1.动态分区参数介绍
2.实际例子
几个参数:
set hive.exec.dynamic.partition=true//使用动态分区
set hive.exec.dynamic.partition.mode=nonstrick;//无限制模式
如果模式是strick,则必须有一个静态分区,且放在最前面,就是第一个分区先给他指定好
set hive.exec.max.dynamic.partitions.pernode=10000;//每个节点生成动态分区的最大数
set hive.exec.max.dynamic.partitions=100000;//生成动态分区的最大个数
set hive.exec.max.created.files=150000;//一个任务调度最多可以创建的文件数目
set dfs.datanode.max.xcievers=8888;//限定一次对多打开的文件数
实际例子:
创建分区表:
hive> create table if not exists dynamic_partition1(month string,detail string) partitioned by(dt string) row format delimited fields terminated by '\t' stored as textfile;
插入数据实现动态分区,使用month作为分区字段:
hive> insert overwrite table dynamic_partition1 partition (dt) select month,detail,month as dt from dynamic_partition;//注意这里分区字段要放到字段的后面
查看打印信息:
Loading data to table default.dynamic_partition1 partition (dt=null)
Time taken for load dynamic partitions : 728
Loading partition {dt=201501}
Loading partition {dt=201504}
Loading partition {dt=201503}
Loading partition {dt=201502}
验证是否生产分区目录:
hive> dfs -ls /user/hive/warehouse/dynamic_partition1;
drwxr-xr-x - root supergroup 0 2015-11-21 07:57 /user/hive/warehouse/dynamic_partition1/dt=201501
drwxr-xr-x - root supergroup 0 2015-11-21 07:57 /user/hive/warehouse/dynamic_partition1/dt=201502
drwxr-xr-x - root supergroup 0 2015-11-21 07:57 /user/hive/warehouse/dynamic_partition1/dt=201503
drwxr-xr-x - root supergroup 0 2015-11-21 07:57 /user/hive/warehouse/dynamic_partition1/dt=201504