如何正确使用配置单元变量替换

时间:2019-03-20 00:31:24

标签: hiveql beeline hivecli

在蜂巢中使用变量替换时,遇到一些错误,但是需要您的帮助。

我的代码:

set hievar:b='on t1.id=t2.id where t2.id is null';
select * from t_old as t1 full outer join t_new as t2 ${b};

当我在蜂巢壳中运行此代码时,它给我一些关于${b}的错误。

我也尝试这样做:

set hivevar:c='select * from t_old as t1 full outer join t_new as t2 on t1.id=t2.id where t2.id is null';
${c};

它给了我同样的错误。

1 个答案:

答案 0 :(得分:0)

修复hivevar命名空间名称(在您的代码中为hievar)并删除引号,因为引号也按原样在Hive中传递。

示例:

set hivevar:b=where 1=1; --without quotes
select 1 ${hivevar:b}; --you can do without hivevar: as in your example

结果:

OK
1
Time taken: 0.129 seconds, Fetched: 1 row(s)

第二个示例:

hive> set hivevar:c=select 1 where 1=1;
hive> ${c};
OK
1
Time taken: 0.491 seconds, Fetched: 1 row(s)