如何使用色调在配置单元中传递变量

how to pass variables in hive using hue

我会传递变量, 我试试这个

SET x = 'user';
SELECT * FROM foo WHERE user == @user

但是我有一个错误

那我试试

set x='user';
select * from foo where user == '${hiveconf:x}'

但我有错误:

 error while compiling statement: failed: parseexception line   
 1:38 missing eof at 'user' near ''''

有什么想法吗?

谢谢

我认为这是您要实现的目标的正确表示法:

SELECT * FROM foo WHERE user = ${hiveconf:x};

注意${hiveconf:x}不需要用引号括起来,而且比较运算符是=,而不是==。从关于关系运算符的 Hive documentation 中,我们有以下两个摘录:

A = B TRUE if expression A is equal to expression B otherwise FALSE.

A == B Fails because of invalid syntax. SQL uses =, not ==.

所以,给定以下愚蠢的测试table:

hive> SELECT user, fullname FROM foo;
OK
other_user  Bar Bazfoo
user        Foo Barbaz
Time taken: 0.228 seconds, Fetched: 2 row(s)

您的查询可能如下所示:

hive> SET x='user';
hive> SELECT * FROM foo WHERE user = ${hiveconf:x};
OK
user        Foo Barbaz
Time taken: 0.229 seconds, Fetched: 1 row(s)