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)
相关推荐
smchaopiao6 小时前
Hive中的排序与分桶技术详解
数据仓库·hive·hadoop
tsyjjOvO3 天前
SpringMVC 从入门到精通
数据仓库·hive·hadoop
Francek Chen3 天前
【大数据存储与管理】分布式数据库HBase:05 HBase运行机制
大数据·数据库·hadoop·分布式·hdfs·hbase
zzzzzwbetter3 天前
Hadoop完全分布式部署-Master的NameNode以及Slaver2的DataNode未启动
大数据·hadoop·分布式
weixin_449310843 天前
ETL转换和数据写入小满OKKICRM的技术细节
数据仓库·php·etl
IvanCodes3 天前
Hive IDE连接及UDF实战
ide·hive·hadoop
yumgpkpm3 天前
华为昇腾910B 开源软件GPUStack的介绍(Cloudera CDH、CDP)
人工智能·hadoop·elasticsearch·flink·kafka·企业微信·big data
lifewange4 天前
Hive数据库
数据库·hive·hadoop
五月天的尾巴5 天前
hive数据库模糊查询表名
hive·查询表名
蓝魔Y5 天前
hive—1.1、执行优化
hive