Hive - 如何组合具有相同附录的许多表?

问题描述 投票:0回答:1

我想结合根据年份选择的许多表格。对于今年(2019),我有tab_h_2016tab_h_2017tab_h_2018。当我们将在2020年,我们将添加tab_h_2019。如何将所有具有相同附录的表加入(使用union),如果将新表添加到数据库中,表将自动组合?

hive hortonworks-data-platform
1个回答
0
投票

计算shell中的表名并对脚本进行参数化。

贝壳:

table1=$(date +"tab_h_%Y" --date " -3 year");
table2=$(date +"tab_h_%Y" --date " -2 year");
table3=$(date +"tab_h_%Y" --date " -1 year");

hive --hiveconf table1="$table1"  --hiveconf table2="$table2"  --hiveconf table3="$table3" -f your_script.hql

脚本your_script.hql

select * from ${hiveconf:table1} inner join ${hiveconf:table2} ...
© www.soinside.com 2019 - 2024. All rights reserved.