[英]Concatenate all partitions in Hive dynamically partitioned table
My hive table is partitioned by date in period of 2 years , and each partition has 200 2mb files in it. 我的配置单元表按2年内的日期进行分区,每个分区中有200个2mb文件。
i am able to concatenate running following command "ALTER TABLE table_name partition (partition_column_name ='2017-12-31') concatenate" 我可以连接以下命令“ ALTER TABLE table_name分区(partition_column_name ='2017-12-31')并置”
Manually it takes more time to run each query, so is there any easy way to do this? 手动需要花费更多时间来运行每个查询,所以有没有简单的方法来执行此操作?
Option-1: Select and overwrite same hive table:
选项1:
Select and overwrite same hive table:
Hive supports insert overwrite same table , if you are sure the data inserted in hive table using insert statements only
(not loading files through hdfs ) then use this option. Hive支持插入覆盖同一表 ,如果您确定
insert statements only
使用insert statements only
将数据插入到Hive 表中 (不通过hdfs加载文件 ),则使用此选项。
hive> SET hive.exec.dynamic.partition = true;
hive> SET hive.exec.dynamic.partition.mode = nonstrict;
hive> Insert overwrite table <partition_table_name> partition(<partition_col>)
select * from <db>.<partition_table_name>;
You can also use sort by,distribute by and these additional params to control the number of files created in the table. 您还可以使用“ 排序依据”,“分发依据”和这些其他参数来控制表中创建的文件数。
Option-2 : Using Shell script:
选项2 :
Using Shell script:
bash$ cat cnct.hql
alter table default.partitn1 partition(${hiveconf:var1} = '${hiveconf:var2}') concatenate
Trigger the above .hql
script using shell script(for loop) 使用shell脚本触发上述
.hql
脚本(for循环)
bash$ cat trigg.sh
#!/bin/bash
id=`hive -e "show partitions default.partitn"`
echo "partitions: " $id
for f in $id; do
echo "select query for: " $f
#split the partitions on = then assigning to two variables
IFS="=" read var1 var2 <<< $f
#pass the variables and execute the cnct.hql script
hive --hiveconf var1=$var1 --hiveconf var2=$var2 -f cnct.hql
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.