欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

hive创建分桶表

程序员文章站 2022-03-08 14:27:03
...
1.指定分桶:开启分桶功能

在hive连接中

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

hive创建分桶表

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创建分桶表

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

hive创建分桶表
hive创建分桶表

相关标签: 大数据 hive