簡體   English   中英

連接Hive動態分區表中的所有分區

[英]Concatenate all partitions in Hive dynamically partitioned table

我的配置單元表按2年內的日期進行分區,每個分區中有200個2mb文件。

我可以連接以下命令“ ALTER TABLE table_name分區(partition_column_name ='2017-12-31')並置”

手動需要花費更多時間來運行每個查詢,所以有沒有簡單的方法來執行此操作?

選項1: Select and overwrite same hive table:

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>;

您還可以使用“ 排序依據”,“分發依據”這些其他參數來控制表中創建的文件數。

選項2Using Shell script:

bash$ cat cnct.hql
alter table default.partitn1 partition(${hiveconf:var1} = '${hiveconf:var2}') concatenate

使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM