Hive分区表与分桶

分区表

在Hive Select查询中,一般会扫描整个表内容,会消耗很多时间做没必要的工作。
分区表指的是在创建表时,指定partition的分区空间。

分区语法

create table tablename
name string
)
partitioned by(key type,…)

create table if not exists employees(
name string,
salary string,
subordinates array<string>,
deductions map<string,float>,
address struct<street:string,city:string,state:string,zip:int>
)
partitioned by (dt string,type string)
row format delimited fields terminated by '\t' 
collection items terminated by ','
map keys terminated by ':'
lines terminated by '\n' 
stored as textfile
;

分区表操作
增加分区

Alter table employees add if not exists partition(country='xxx'[,state='yyyy'])
Alter table employees add if not exists partition(dt='20140715',type='test');

删除分区

Alter table employees drop if exists partition(country='xxx'[,state='yyyy’)

Hive分桶

对于每一个表(table)或者分区,Hive可以进一步组织成桶,也就是说捅是更为细粒度的数据范困划分。

Hive是针对某一列进行分捅。

Hive采用对列值哈希,然后除以捅的个数求余的方式决定该条记录存放在哪个桶当中。

好处
获得更高的查询处理效率。
使取样(sampling)更高效

分桶语法

create table bucketed_user(
id string ,
name string
)
clustered by (id) sorted by (name) into 4 buckets
row format delimited fields terminated by '\t' 
stored as textfile;

设置

set hive.enforce.bucketing = true;

插入数据

insert overwrite table bucketed_user select addr ,name from testtable;

Hive分区与分桶比较

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃果冻不吐果冻皮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值