动态分区流程:
①建一个动态分区表
②建一个临时表(分区字段作为临时表的表内字段)
③将数据导入临时表中
④根据临时表中的数据含有的动态分区字段的值进行数据加载并
动态分区
-- 设置属性
set hive.exec.dynamic.partition.mode=nonstrict; <----非严格模式下可以都是动态分区,而严格模式下必须至少有一个静态分区
set hive.exec.dynamic.partition=true; 开启动态分区
-- 创建动态分区表student
drop table if exists student;
create table if not exists student
(
id int,
name string
)
partitioned by (age int)
row format delimited fields terminated by ','
;
-- 创建临时表
drop table if exists temp;
create table if not exists temp
(
id int,
name string,
age int
)
row format delimited fields terminated by ','
;
-- 准备一个文件,含有临时表中的所有字段数据,data.txt,该文件在linux文件系统中
1,zhangsan,15
2,lisi,16
3,wangwu,20
4,hanmeimei,50
5,liufang,20
6,wuting,15
7,dafang,30
8,shiba,10
9,chifan,12
10,kuishi,12
-- 将数据导入到临时表中
load data local inpath '/root/data.txt' into table temp;
-- 查看数据是否成功导入临时表中
select * from temp;

本文详细介绍了使用Hive进行动态分区的过程,包括创建动态分区表、临时表,数据导入及分区加载步骤。通过实例演示了如何设置Hive属性,创建表结构,导入数据并实现动态分区,最终查询分区结果。
最低0.47元/天 解锁文章
1872

被折叠的 条评论
为什么被折叠?



