hive-分桶-索引(初篇)

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

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

相关推荐
hINs IONN20 小时前
深入解析HDFS:定义、架构、原理、应用场景及常用命令
hadoop·hdfs·架构
隐于花海,等待花开20 小时前
Hive 常用函数详细总结
数据仓库·hive·hadoop
孟意昶1 天前
Doris专题28-聚合多维分析
大数据·数据库·数据仓库·sql·doris
docsz2 天前
据数据基座搭建
大数据·hadoop
RestCloud2 天前
流式优先数据架构:从批量ETL到事件驱动架构的演进之路
数据仓库·etl·cdc·数据处理·数据集成·数据传输·数据同步
coderlin_2 天前
LangGraph项目二 同步数据仓库信息到元数据库并且建立向量索引
数据库·数据仓库
隐于花海,等待花开3 天前
COLLECT_LIST函数详解
hive
隐于花海,等待花开3 天前
数据开发常问的技术性问题及解答
大数据·hive
曹宇飞丶3 天前
ambari server及元数据库(postgreSQL)迁移
hadoop·ambari
隐于花海,等待花开3 天前
窗口函数之排序函数详细解读及示例
大数据·数据库·hive