我想结合根据年份选择的许多表格。对于今年(2019
),我有tab_h_2016
,tab_h_2017
和tab_h_2018
。当我们将在2020年,我们将添加tab_h_2019
。如何将所有具有相同附录的表加入(使用union),如果将新表添加到数据库中,表将自动组合?
计算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} ...