理论基础
1、概念:
对于表或分区,进一步细分成桶。
分桶方式:
对列进行hash再对桶个数取模,确定记录入桶。
2、操作
普通表:
create table nor_tab(id int,name String,age int) row format delimited
fields terminated by '\t'
lines terminated by '\n';
加载数据:
load data local inpath '/root/b.txt' overwrite into table nor_tab;
桶表:
create table buc_tab(id int,name String,age int) clustered by (age) into 3 buckets
row format delimited
fields terminated by '\t'
lines terminated by '\n';
#####这儿和分区表不一样,分区表的分区字段不在建表字段中,而分桶字段在建表字段中。
往桶表插入数据:
insert into buc_tab select id,name,age from nor_tab;
查看hdfs目录:
[root@Linux005 ~]# hdfs dfs -ls /user/hive_remote/warehouse/buc_tab
Found 3 items
-rwxr-xr-x 1 root supergroup 10 2019-04-24 19:36 /user/hive_remote/warehouse/buc_tab/000000_0
-rwxr-xr-x 1 root supergroup 11 2019-04