这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos
本文是《hive学习笔记》的第五篇,前文学习了分区表,很容易发现分区表的问题:
set hive.enforce.bucketing = true;
接下来先准备外部表t13,往里面添加一些数据,将t13作为后面分桶表的数据源:
create external table t13 (name string, age int, province string, city string)
row format delimited
fields terminated by ','
location '/data/external_t13';
tom,11,guangdong,guangzhou
jerry,12,guangdong,shenzhen
tony,13,shanxi,xian
john,14,shanxi,hanzhong
load data
local inpath '/home/hadoop/temp/202010/25/013.txt'
into table t13;
create table t14 (name string, age int, province string, city string)
clustered by (province, city) into 16 buckets
row format delimited
fields terminated by ',';
from t13
insert overwrite table t14
select name, age, province, city;
执行以下语句,取样查看t14的数据:
hive> select * from t14 tablesample(bucket 1 out of 2 on province, city);
OK
tom 11 guangdong guangzhou
john 14 shanxi hanzhong
Time taken: 0.114 seconds, Fetched: 2 row(s)