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)
相关推荐
weixin_307779133 小时前
Databricks里用PySpark统计指定表和字段中各字段的空值、空字符串或零值比例
运维·数据仓库·python·spark·云计算
邀星月为媒4 小时前
从零打造一个属于自己的 AI Agent:Core Hive Agent 开源项目解析
人工智能·hive·开源
BI专家之路5 小时前
安装linux/hadoop/jdk/hive
linux·hive·hadoop
2601_962073972 天前
大数据-258 离线数仓 - Griffin架构 配置安装 Livy 架构设计 解压配置 Hadoop Hive
大数据·hadoop·架构
fastjson_2 天前
Hive 基础函数
数据仓库·hive·hadoop
kuroomi2 天前
hadoop高可用架构
hadoop
APItesterCris3 天前
告别人工盯品:借助 OpenClaw 搭建商品自动监控与数据分析系统(完整实操)
大数据·数据库·数据仓库·自动化
千里码aicood3 天前
基于Hadoop的汽车销量分析与可视化
大数据·hadoop·分布式
AbnerWright4 天前
读书笔记-数据密集型应用系统设计
数据仓库
wxchyy5 天前
手把手教你入门云计算(二):这些技术改变了世界,你也能轻松掌握
hadoop·阿里云·docker·云原生·华为云·云计算·运维开发