蜗牛之窝 2019-12-14
使用动态分区表必须配置的参数
动态分区相关调优参数
create table dpartition(id int ,name string ) partitioned by(ct string );
hive> set hive.exec.dynamic.partition=true; #开启动态分区,默认是false set hive.exec.dynamic.partition.mode=nonstrict; #开启允许所有分区都是动态的,否则必须要有静态分区才能使用。 -- 开始抽取 insert overwrite table dpartition partition(ct) select id ,name,city from mytest_tmp2_p;
hive>--查看可知,hive已经完成了以city字段为分区字段,实现了动态分区。 hive (fdm_sor)> show partitions dpartition; partition ct=beijing ct=beijing1
1.创建一个只有一个字段,两个分区字段的分区表 hive (fdm_sor)> create table ds_parttion(id int ) > partitioned by (state string ,ct string ); 2.往该分区表半动态分区插入数据 hive> set hive.exec.dynamic.partition=true; set hive.exec.dynamic.partition.mode=nonstrict; insert overwrite table ds_parttion partition(state=‘china‘,ct) #state分区为静态,ct为动态分区,以查询的city字段为分区名 select id ,city from mytest_tmp2_p; 3.查询结果显示: hive (fdm_sor)> select * from ds_parttion where state=‘china‘ > ; ds_parttion.id ds_parttion.state ds_parttion.ct 4 china beijing 3 china beijing 2 china beijing 1 china beijing 4 china beijing1 3 china beijing1 2 china beijing1 1 china beijing1 hive (fdm_sor)> select * from ds_parttion where state=‘china‘ and ct=‘beijing‘; ds_parttion.id ds_parttion.state ds_parttion.ct 4 china beijing 3 china beijing 2 china beijing 1 china beijing hive (fdm_sor)> select * from ds_parttion where state=‘china‘ and ct=‘beijing1‘; ds_parttion.id ds_parttion.state ds_parttion.ct 4 china beijing1 3 china beijing1 2 china beijing1 1 china beijing1 Time taken: 0.072 seconds, Fetched: 4 row(s)
set hive.exec.dynamic.partition=true; set hive.exec.dynamic.partition.mode=nonstrict; insert overwrite table ds_parttion partition(state,ct) select id ,country,city from mytest_tmp2_p; 注意:字段的个数和顺序不能弄错。