向配置单元查询传递参数

oxcyiej7  于 2021-06-27  发布在  Hive
关注(0)|答案(2)|浏览(283)

我像这样将参数传递给配置单元脚本,使用--hiveconf参数将一个值传递给配置单元查询。有没有其他方法可以将参数传递给配置单元脚本?

beeline -u "${dbconection}" --hiveconf load_id=${loadid} -f /etc/sql/hive_script.sql

hive_script.sql正在从表-a中选择记录并插入到表-b中。

INSERT into TABLE table-b
SELECT column1,
Column2,
Column3,
${hiveconf:loadid} as load_id,
Column5
From table-a;

我收到以下错误消息

Error: Failed to open new session: org.apache.hive.service.cli.HiveSQLException: java.lang.IllegalArgumentException: Cannot modify load_id at runtime. It is not in list of params that are allowed to be modified at runtime

下面是配置单元变量在我的环境中的替代设置。

set hive.variable.substitute;
+--------------------------------+--+
|              set               |
+--------------------------------+--+
| hive.variable.substitute=true  |
+--------------------------------+--+
eqoofvh9

eqoofvh91#

如果您使用的是直线,则需要使用 --hivevar ```
beeline -u "${dbconection}" --hivevar load_id=${loadid} -f /etc/sql/hive_script.sql

.sql或.hql扩展将不会产生任何影响。
配置单元查询将按以下方式使用变量:

INSERT into TABLE table-b
SELECT column1,
Column2,
Column3,
${loadid} as load_id,
Column5
From table-a;

tpgth1q7

tpgth1q72#

这是我使用的,它对我有效,而不是“--hiveconf”use“--hivevar”这将适用于hive版本v0.8.x及更高版本。

loaded='201810251040'
beeline -u "${dbconection}" --hivevar load_id=${loadid} -f /etc/sql/hive_script.sql

更新hive\u script.sql如下

INSERT into TABLE table-b
SELECT column1,
Column2,
Column3,
${hivevar:load_id} as load_id,
Column5
From table-a;

这是伪代码。。。。

相关问题