注意:1 并不是都要建辅助表,因为是用load的方式加载数据,所以才要建
2 select 的时候,分区字段要写在最后面
使用动态分区表必须配置的参数 :
//设置为true允许使用dynamic partition
hive.exec.dynamic.partition(缺省false)
//设置dynamic partition模式(nostrict允许所有partition列都为dynamic partition,strict不允许)
hive.exec.dynamic.partition.mode(缺省strick)
使用动态分区相关的调优参数:
//每一个mapreduce job允许创建的分区的最大数量,如果超过了这个数量就会报错
hive.exec.max.dynamic.partitions.pernode (缺省100):
//一个dml语句允许创建的所有分区的最大数量
hive.exec.max.dynamic.partitions (缺省1000):
//所有的mapreduce job允许创建的文件的最大数量
hive.exec.max.created.files (缺省100000):
use test03;
drop table d_fz
只有1个分区字段的分区表,操作示例
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.dynamic.partition=true;
//一级分区的动态分区表
create table d_patition1(
id bigint,
name string,
interest array<string>)
partitioned by (country varchar(50))
row format delimited fields terminated by '\t'
collection items terminated by ',';
//建立一个辅助表存储数据(和动态分区表列相同)
create table d_fz(
id bigint,
name string,
interest array<string>,
country string)
row format delimited fields terminated by '\t'
collection items terminated by ','
//由本地文件插入到临时表
load data local inpath '/data/log/fenqu5.txt' into table d_fz
//将临时表的数据 插入到分区表中,需 指定分区字段 (完全动态分区)
insert overwrite table d_patition1 partition(country)
select * from d_fz
//也可以像静态分区一样,分区字段直接写死
load data local inpath '/data/log/fenqu5.txt' into table d_patition1 partition(country='woman')
多个分区字段的分区表,操作示例
//二级分区的动态分区表
create table d_partition3(
id bigint,
name string,
interest array<string>)
partitioned by (country varchar(50),age int)
row format delimited fields terminated by '\t'
collection items terminated by ',';
//建立一个辅助表存储数据(和动态分区表列相同)
create table d_fz2(
id bigint,
name string,
interest array<string>,
country string,
age int)
row format delimited fields terminated by '\t'
collection items terminated by ',';
//导入数据到临时表
load data local inpath '/data/log/fenqu6.txt' into table d_fz2
//将临时表的数据 插入到分区表中,需 指定分区字段 (完全动态分区)
insert overwrite table d_partition3 partition(country,age)
select id,name,interest,country,age from d_fz2;
//将临时表的数据 插入到分区表中,(分区字段静态和动态混用,注意select的部分少了静态分区列)
insert overwrite table d_partition3 partition(country='abc',age)
select id,name,interest,age from d_fz2;
也可以像静态分区一样,分区字段直接写死
load data local inpath '/data/log/fenqu6.txt' into table d_partition3 partition(country='woman',age=11)
1574

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



