0
点赞
收藏
分享

微信扫一扫

hive-分桶-索引(初篇)

米小格儿 2天前 阅读 0

hvie - 分桶

  • 创建分桶表之前要先设置hive允许进行强制分桶配置

set hive.enforce.bucketing=true
  • 创建分桶表

create table tmp_bucket(id int,
                        name String) 
                        clustered by (id) into 4 buckets    
  • 建表

  • 其中x表示分几个桶进行抽样,y表示间隔几个桶进行一次分桶

select columns 
from  table tablesample(bucket x out of y on column);
  • 进行抽样

select id,name from tmp_bucket tablesample(bucket 1 out of 2 on id);
  • 像分桶表加载数据

insert overwrite table tmp_bucket 
select id,name from source_data;
# 其中的source_data 表中的数据一定是提前分好桶的
​
  • 查询分桶表 - > 高效抽样 , 通过桶号进行抽样

select * from tmp_bucket where name in (select name from tmp_bucket distribute by rand() into 3 butkets);   

hive-索引

  • 刚创建完hive的索引表是数据的, 需要生成索引数据

alter index 索引名称 on table_name rebuild;
  • 查看索引

show  formatted index on table_name

这篇文件未完成待续哦 ......

举报

相关推荐

Hive分桶

Hive-

Hive分桶表

hive 分桶分区

hive分桶表排序

0 条评论