Hive 在配置单元中,如何在hql中生成动态表名?

Hive 在配置单元中,如何在hql中生成动态表名?,hive,hql,Hive,Hql,我想在hql中生成使用直线运行的动态表名 在db2中,我可以使用| |实现这个需求。 例如,使用year生成表名as400.trxfintrx|year(当前日期),但是我如何在hive'hql中实现它呢?如果我理解正确,您希望表名被参数化 为此,您可以使用配置单元变量 create table dbName.table1_${hivevar:yearMonthDate} ( c1 int, c2 int ) stored as orc tblproperties('ZLIB'); $ hiv

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

在db2中,我可以使用
| |
实现这个需求。
例如,使用year生成表名as400.trxfintrx|year(当前日期),但是我如何在hive'hql中实现它呢?

如果我理解正确,您希望表名被参数化

为此,您可以使用配置单元变量

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)
你可以参考

从直线终端,您不能定义任何函数来设置参数值,然后在查询中使用它们


希望这有助于创建表dbName.table1${hivevar:yearMonthDate}(c1 int,c2 int)存储为orc TBLProperty('ZLIB')这适用于beeline cli?是的,它会,但您应该在使用它之前定义变量…配置单元>设置配置单元变量:monthDate=2018;配置单元>选择1,其中${hivevar:monthDate}=2018;确定1所用时间:1.868秒,获取:1行