Search code examples
hadoopparametershivehue

how to pass variables in hive using hue


I will pass variables, I try this

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

but I have one error

Then I will try

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

but I have error:

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

Any ideas?

Thanks


Solution

  • I think this is the proper notation for what you are trying to achieve:

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

    Note that there is no need to surround ${hiveconf:x} with quotes, and also that the comparison operator is =, not ==. From the Hive documentation on relational operators, we have these two excerpts:

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

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

    So, given the following silly test table:

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

    Your query may look something like the following:

    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)