Hive分桶表

时间:2024-03-17 17:00:27

分桶表

一、准备数据

1,wsq1
2,wsq2
3,wsq3
4,wsq4
5,wsq5

二、开启分桶表的支持

set hive.enforce.bucketing=true;
set mapreduce.job.reduces=4;
set mapreduce.reduce.task=4;

三、创建分桶表

hive>create table bucketed_users(id int,name string) clustered by (id) sorted by (id) into 4 buckets row format delimited fields terminated by ',';

四、创建存放数据的表并将原数据加载入

hive> create table users(id int,name string) row format delimited fields terminated by ',';
hive> load data local inpath '/home/ec2-user/total/wsq' into table users;

五、数据装载到分桶表

hive> insert into bucketed_users select * from users;