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;

相关推荐
DashingGuy16 小时前
数仓建模理论
数据仓库
像豆芽一样优秀20 小时前
Hive和Flink数据倾斜问题
大数据·数据仓库·hive·hadoop·flink
howard20051 天前
VMWare上搭建Hive集群
hive·hadoop
aristo_boyunv1 天前
拦截器和过滤器(理论+实操)
java·数据仓库·hadoop·servlet
元媛媛2 天前
数据仓库概要
数据仓库
cg.family2 天前
Doris 数据仓库例子
数据仓库·doris
TDengine (老段)2 天前
从 ETL 到 Agentic AI:工业数据管理变革与 TDengine IDMP 的治理之道
数据库·数据仓库·人工智能·物联网·时序数据库·etl·tdengine
镜舟科技3 天前
告别 Hadoop,拥抱 StarRocks!政采云数据平台升级之路
大数据·starrocks·数据仓库·hadoop·存算分离
程序猿 董班长3 天前
springboot配置多数据源(mysql、hive)
hive·spring boot·mysql
XueminXu3 天前
Hive使用Tez引擎出现OOM的解决方法
hive·oom·tez·datagrip·container·outofmemory