hive动态分区

hive动态分区概念:允许插入数据到分区表时,根据插入的数据内容自动创建相应的分区

1.启用动态分区功能

hive.exec.dynamic.partition=true;

2.分区字段设置

在insert语句中, 动态分区的字段必须放在select语句的末尾,hive会根据这个字段的值来创建分区目录

示例:

sql 复制代码
--创建分区表:
create table test (
id string
,name string
)
partitioned by (dt string)
row format delimited
fields terminated by '|'
lines terminated by '\n'
;

--动态插入数据:
set hive.exec.dynamic.partition=true;
insert into test
select '1' as id, 'one' as name, '20200921' as dt
union all
select '2' as id, 'two' as name, '20200922' as dt
union all
select '3' as id, 'three' as name, '20200923' as dt

--查看最终效果:
select * from test;
+----------+------------+-----------+
| test.id  | test.name  |  test.dt  |
+----------+------------+-----------+
| 1        | one        | 20200921  |
| 2        | two        | 20200922  |
| 3        | three      | 20200923  |
+----------+------------+-----------+
3 rows selected (0.618 seconds)

show partitions test;
+--------------+
|  partition   |
+--------------+
| dt=20200921  |
| dt=20200922  |
| dt=20200923  |
+--------------+
3 rows selected (0.436 seconds)
相关推荐
二十六画生的博客17 小时前
每个subtask都提交一份快照到hdfs,会把10个小的快照合并成一个大的吗?谁来合并?
大数据·hadoop·hdfs·flink
juniperhan17 小时前
Flink 系列第24篇:Flink SQL 集成维度表指南:存储选型、参数调优与实战避坑
大数据·数据仓库·sql·flink
隐于花海,等待花开17 小时前
41.ABS / POW / SQRT 函数深度解析
大数据·hive
千月落19 小时前
HDFS数据迁移
大数据·hadoop·hdfs
RestCloud1 天前
ETL数据质量保障:如何通过优化提升数据准确性?
数据仓库·etl·数据处理·数据传输·数据同步·数据集成平台
隐于花海,等待花开2 天前
40.RAND 函数深度解析
hive·hadoop
2501_927283582 天前
荣联汇智助力天津艺虹打造“软硬一体”智慧工厂,全流程自动化引领印刷包装行业数智变革
大数据·运维·数据仓库·人工智能·低代码·自动化
孤雪心殇3 天前
快速上手数仓基础知识
数据仓库·hive·spark
渣渣盟3 天前
数据仓库 vs 数据湖 vs 湖仓一体:架构演进与选型
数据仓库·架构
隐于花海,等待花开3 天前
39.ROUND / FLOOR / CEIL 函数深度解析
hive·hadoop