hive创建分桶表

1.指定分桶:开启分桶功能

在hive连接中

set hive.enforce.bucketing=true;   --默认是flase
set mapreduce.job.reduces=4;  --默认是-1

hive创建分桶表_第1张图片

2.创建分桶表:分桶表创建的时候,分桶字段必须是表中的字段
create table student_buck(Sno int,Sname string,Sex string,Sage int ,Sdept string)
clustered by(Sno)   --
sorted by(Sno DESC)
into 4 buckets
row format delimited
fields terminated by ',';

3.创建临时表,为导入分桶表数据准备:
create table student(Sno int,Sname string,Sex string,Sage int ,Sdept string)
row format delimited
fields terminated by ',';

导入数据到临时表:

LOAD DATA local INPATH '/opt/data/hivedata/student.txt' INTO TABLE student;

select * from student cluster by(Sno);

hive创建分桶表_第2张图片

4.导入分桶表数据:不能使用load data方式,没有分桶效果
insert overwrite table student_buck
select * from student cluster by(Sno);

hive创建分桶表_第3张图片
hive创建分桶表_第4张图片

你可能感兴趣的:(hive,大数据)