Hive分区和分桶

分区:

根据某一列进行进行划分存储,常用的有时间分区;

查询数据时只需要扫描特定的分区数据,不需要全盘扫描,节省时间,

方便数据归档和清理

创建分区表

create table table_name(

col1 int,

col2 string

)

partition by (dt string,country string);

插入分区

insert into table_name partition (dt='2024-06-19',country='china')

values(1,'data1'),(2,data2);

修改分区

alter table table_name partition ()

删除分区

alter table table_name drop partition(dt='2024-06-18');

分桶:

将表数据按照哈希函数的结果进行划分存储,将数据均匀分不到桶中,提高了查询的并行度和性能。

支持随机抽样

创建分桶

create table bucket_table_name(

col1 int,

col2 string

)

clustered by (col1) into 4 buckets

sorted by (col2);

插入数据

insert overwrite table bucket_table_name

select cols,col2

from table_name;

查询分桶数据

select *

from

bucket_table_name

where col1=1;

相关推荐
想ai抽14 小时前
深入starrocks-多列联合统计一致性探查与策略(YY一下)
java·数据库·数据仓库
starfalling102415 小时前
【hive】一种高效增量表的实现
hive
D明明就是我20 小时前
Hive 拉链表
数据仓库·hive·hadoop
嘉禾望岗5031 天前
hive join优化和数据倾斜处理
数据仓库·hive·hadoop
yumgpkpm1 天前
华为鲲鹏 Aarch64 环境下多 Oracle 数据库汇聚操作指南 CMP(类 Cloudera CDP 7.3)
大数据·hive·hadoop·elasticsearch·zookeeper·big data·cloudera
忧郁火龙果1 天前
六、Hive的基本使用
数据仓库·hive·hadoop
忧郁火龙果1 天前
五、安装配置hive
数据仓库·hive·hadoop
chad__chang2 天前
dolphinscheduler安装过程
hive·hadoop
莫叫石榴姐2 天前
字节数开一面
大数据·数据仓库·职场和发展