在hive中,如何在hql中生成动态表名?

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

我想在hql中生成使用beeline运行的动态表名。

在db2中,我可以使用||实现此要求。例如,使用year生成表名'as400.trxfintrx_' || year(current date),但我怎样才能在hive'hql中实现它?

hive hql
1个回答
0
投票

如果我理解它是正确的,你想要参数化表名,

为此你可以使用hive变量,

create table dbName.table1_${hivevar:yearMonthDate}
(
c1 int,
c2 int
)
stored as orc
tblproperties('ZLIB');

$ hive -f test_create_table.hql --hivevar yearMonthDate=20190215
OK
Time taken: 1.149 seconds
$ hive
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> use dbname;
OK
Time taken: 0.726 seconds
hive> desc table1_20190215;
OK
c1                      int
c2                      int
Time taken: 0.302 seconds, Fetched: 2 row(s)

你可以参考https://cwiki.apache.org/confluence/display/Hive/LanguageManual+VariableSubstitution

从beeline终端,您无法定义任何设置参数值的函数,然后在查询中使用它们。

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.