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)
相关推荐
juniperhan10 小时前
Flink 系列第17篇:Flink Table&SQL 核心概念、原理与实战详解
大数据·数据仓库·分布式·sql·flink
菜鸟小码13 小时前
Hadoop大数据时代的底座和基石
大数据·hadoop·分布式
隐于花海,等待花开13 小时前
18.TRUNC / LAST_DAY / NEXT_DAY 函数深度解析
大数据·hive
隐于花海,等待花开13 小时前
17.DATE_FORMAT 函数深度解析
大数据·hive
隐于花海,等待花开14 小时前
15.TO_DATE 函数深度解析
大数据·hive
QEasyCloud202216 小时前
企业数据仓库建设实践与价值分析
数据仓库
地球资源数据云1 天前
1951-2025年中国逐年1千米逐月总降水量区域统计数据集_年表_县
大数据·数据结构·数据库·数据仓库·人工智能
YJlio2 天前
1 4.1 微软商店的使用(Microsoft Store:下载/安装/管理应用与游戏)
运维·hive·hadoop·windows·游戏·microsoft·计算机外设
看海的四叔2 天前
【SQL】SQL的日期与时间函数
数据库·hive·sql·数据分析·时间函数·日期函数
看海的四叔2 天前
【SQL】SQL-常见窗口函数有哪些-上篇
数据库·hive·sql·mysql·数据分析·窗口函数