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)
相关推荐
杂家12 小时前
Hadoop完全分布式部署(超详细)
大数据·hadoop·分布式
BD_Marathon12 小时前
【Hadoop】hadoop3.3.1完全分布式配置
大数据·hadoop·分布式
Q264336502316 小时前
【有源码】基于Hadoop+Spark的起点小说网大数据可视化分析系统-基于Python大数据生态的网络文学数据挖掘与可视化系统
大数据·hadoop·python·信息可视化·数据分析·spark·毕业设计
yumgpkpm1 天前
CMP(类Cloudera CDP 7.3 404版华为泰山Kunpeng)和Apache Doris的对比
大数据·hive·hadoop·spark·apache·hbase·cloudera
呆呆小金人1 天前
SQL字段对齐:性能优化与数据准确的关键
大数据·数据仓库·sql·数据库开发·etl·etl工程师
口_天_光健2 天前
制造企业的数据目录编写
大数据·数据库·数据仓库·数据分析
梦里不知身是客112 天前
spark读取table中的数据【hive】
大数据·hive·spark
DashVector2 天前
向量检索服务 DashVector产品计费
数据库·数据仓库·人工智能·算法·向量检索
yumgpkpm3 天前
Doris在CMP7(类Cloudera CDP 7 404版华为Kunpeng)启用 Kerberos部署Doris
大数据·hive·hadoop·python·oracle·flink·cloudera
Mr_Art893 天前
金融行业湖仓实践:Apache Paimon 小文件治理之道
数据仓库·金融·apache