Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

declare variable in sql (hive)

I had a deep look on the internet, but I'm not able to find any suitable answer.

In hive, is it possible to declare a variable, lets say:

test = 1

And change the value of this variable inside a query?

select
   case
      when field > 1 then test = test+1
      else test = 1
   end as test
from my table
like image 436
woshitom Avatar asked May 19 '16 10:05

woshitom


1 Answers

It is possible. Please find the below code to create a variable in Hive.

hive> SET cust_id = 1234567890;

Once you create variable you can use it in your query like below.

hive> select * from cust_table where customer_id = '${hiveconf:cust_id}';

Hope this will help you. Now you can apply this to your scenario.

like image 98
Manindar Avatar answered Nov 09 '22 07:11

Manindar