5.分桶
分桶意义
–1.提高查询效率。使用链接查询的两个字段进行过分桶。
–2.提高抽样效率
–分桶关键字:bucket
5.1建表语句
怎么知道对那个字段分桶??分几个桶??
create table if not exists tablename(
id int,name string,sex string)
#对性别分两个桶
clustered by (sex) into 2 buckets
row format delimited fields terminated by ' ';
5.2属性
默认属性为true,可以使用分桶,如果不行可更改
set hive.enforce.bucketing=true;
5.3添加数据
表导入
insert into table table1 select * from table2;
#覆盖
insert overwrite table table1 select * from table2;
文件导入
load data local inpath '文件路径' into table tablename;
5.4查询
tablesample (bucket x out of y on gender)
#从y个桶里抽取第x个桶