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)
相关推荐
修先生9 小时前
Hive Udf函数AES加密
hive·aes·udf
SeaTunnel14 小时前
Apache SeaTunnel 4 月有何新动作?连接器增强与 Zeta 稳定性提升等亮点速览
大数据·数据仓库·spark·apache·seatunnel
Volunteer Technology14 小时前
HDFS源码(二)
大数据·hadoop·hdfs
承渊政道15 小时前
Oracle迁移避坑:一个(+)写错,LEFT JOIN可能变INNER JOIN
运维·服务器·数据库·数据仓库·学习·安全·oracle
WL_Aurora15 小时前
MapReduce框架原理深度解析 | Shuffle机制、切片分区、Join全攻略
大数据·hadoop·mapreduce
赵渝强老师15 小时前
【赵渝强老师】Hadoop的伪分布部署模式
大数据·hadoop·分布式
Volunteer Technology15 小时前
HDFS源码(一)
大数据·hadoop·hdfs
AllData公司负责人1 天前
通过Postgresql同步到Doris,全视角演示AllData数据中台核心功能效果,涵盖:数据入湖仓,数据同步,数据处理,数据服务,BI可视化驾驶舱
java·大数据·数据库·数据仓库·人工智能·python·postgresql
WL_Aurora1 天前
HDFS底层原理深度解析 | 读写流程、NameNode工作机制、DataNode心跳与数据完整性
大数据·hadoop·hdfs
Pushkin.2 天前
新数仓建设方法论与实践指南-分层解耦驱动的数据仓库
大数据·数据仓库