【问题标题】:Run Hive Script with variable - problem with passing variable使用变量运行 Hive 脚本 - 传递变量的问题
【发布时间】:2021-08-04 15:50:50
【问题描述】:

我正在使用 DBVisualiser 运行以下脚本(期望在查询中传递变量并根据 where 条件检索数据)

set Id='1';

select * from MyTable where account_id = '${hivevar:Id}' limit 5

不幸的是,当我运行这个脚本时,我看到执行的查询如下:

set Id='1';

select * from mytable where account_id = '${hivevar:Id}' limit 5

但是当我使用硬编码值运行查询时

select * from mytable where account_id = '1' limit 5

然后我得到预期的数据集。 如果有人可以帮助我了解我做错了什么,我会很高兴。

提前致谢。

【问题讨论】:

标签: variables hive parameter-passing hiveql dbvisualizer


【解决方案1】:

在没有命名空间的情况下设置的变量是 hiveconf 变量,而不是 hivevar。虽然您可以明确指定命名空间。

试试这个:

set Id=1; --No need to quote here if it is quoted in the select
-- use hiveconf
select * from MyTable where account_id = '${hiveconf:Id}' limit 5;

或者这个:

--specify the namespace
set hivevar:Id=1;
select * from MyTable where account_id = '${hivevar:Id}' limit 5;

另见similar question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    相关资源
    最近更新 更多