【问题标题】:Passing parameters to HIVE query将参数传递给 HIVE 查询
【发布时间】:2018-10-25 22:46:08
【问题描述】:

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

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

hive_script.sql 正在从 table-a 中选择记录并插入 table-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  |
+--------------------------------+--+

【问题讨论】:

    标签: hive hiveql


    【解决方案1】:

    如果你使用beeline,你需要使用--hivevar

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

    .sql 或 .hql 扩展名不会产生影响。

    而 hive 查询将通过以下方式使用变量:

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

    【讨论】:

    • 酷,如果它对你有用,请随时点赞并接受答案。
    【解决方案2】:

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

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

    如下更新 hive_script.sql

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

    这是伪代码......

    【讨论】:

      猜你喜欢
      • 2019-11-19
      • 1970-01-01
      • 2017-09-27
      • 2014-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-26
      • 2016-08-27
      相关资源
      最近更新 更多