在配置单元中,如何在 hql 中生成动态 table 名称?
In hive, how to generate dynamic table name in hql?
我想在使用直线运行的 hql 中生成动态 table 名称。
在 db2 中,我可以使用 ||
实现此要求。
例如,使用年份生成 table 名称 'as400.trxfintrx_' || year(current date)
,但我如何在 hive'hql 中实现它?
如果我理解正确,您希望 table 名称被参数化,
为此,您可以使用配置单元变量,
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
从直线终端,您不能定义任何函数来设置参数值,然后在您的查询中使用它们。
希望对您有所帮助
我想在使用直线运行的 hql 中生成动态 table 名称。
在 db2 中,我可以使用 ||
实现此要求。
例如,使用年份生成 table 名称 'as400.trxfintrx_' || year(current date)
,但我如何在 hive'hql 中实现它?
如果我理解正确,您希望 table 名称被参数化,
为此,您可以使用配置单元变量,
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
从直线终端,您不能定义任何函数来设置参数值,然后在您的查询中使用它们。
希望对您有所帮助