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)
相关推荐
Zhu7581 天前
在k8s集群环境部署高可用的Apache Hadoop3.1.1定制版集群
hadoop·kubernetes
Y3815326621 天前
3 种 SERP 数据 ETL 方案对比:实时 / 定时 / 流式
数据仓库·etl
还有你Y2 天前
软件工程架构
hadoop·架构·软件工程
向夏威夷 梦断明暄2 天前
基于Tez引擎的 Hive SQL 性能优化
hive·sql·性能优化
这个DBA有点耶2 天前
交易型数据库是什么?OLTP核心能力与2026选型指南
数据库·数据仓库·sql·database·数据库架构·olap·dba
RestCloud3 天前
Informatica迁移国产ETL完整实施指南:ETLCloud自动化平滑替换方案
数据仓库·etl·etlcloud·数据传输·数据集成工具·informatica·国产化替代
德昂信息dataondemand4 天前
全量还是增量?聊聊数仓ETL中的数据同步策略
数据仓库·etl
观远数据5 天前
数据集成平台选型战卡:DataFlow对比传统ETL的5个维度与红线排除项
数据仓库·etl
Database_Cool_5 天前
云数据仓库开通指南:阿里云 AnalyticDB MySQL 10 分钟从 0 到分析实战教程
数据仓库·mysql·阿里云