Support Questions
Find answers, ask questions, and share your expertise

Setting variables for hive??

Highlighted

Setting variables for hive??

New Contributor

Hello everybody

i just downloaded the sandbox and i use hive through ambari for querying data. I m trying to understand how to define and use variables. I wrote this but it doesn't work:

set hivevar:mavar1='Ford';

set hivevar:mavar2=12058;

select * from tempo where model=${hiveconf:mavar1}

and ${hiveconf:marvar2};

Could you help me please?

1 REPLY 1

Re: Setting variables for hive??

Explorer

@hadoop user

Could you try issuing your select statement something like this -

"select * from tempo where model=${mavar1} and ${marvar2};"

I tried a similar thing on Hive CLI and it worked.

hive> create table test(i int,s string);

hive> insert into test values (1,'aa'),(2,'bb');

hive> set hivevar:testvar=1;

hive> select * from test where i=${testvar};

OK

1aa

Time taken: 0.261 seconds, Fetched: 1 row(s)