1

In Hive,how to store the results of a query in a variable? I've tried the below command: SET hivevar:a=(Query);

But instead of the result,query itself is getting stored. Is there any way for storing the results?

Parameshwar
  • 21
  • 1
  • 5

1 Answers1

2

Hive variables are nothing but a text replacement mechanism.
The replacement is done before parsing and execution.

hive> set hivevar:v1=se;
hive> set hivevar:v2=l;
hive> set hivevar:v3=ec;
hive> set hivevar:v4=t 1+;
hive> set hivevar:v5=2;
hive> ${hivevar:v1}${hivevar:v2}${hivevar:v3}${hivevar:v4}${hivevar:v5};
OK
3

Passing a query result as an argument to another query can be done from the shell, e.g. -

hive --hivevar x=$(hive -e 'select 1+2') -e 'select ${hivevar:x}*100'
David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88
  • I have a table which I have to validate.. After validation,if the number of valid records are more than a threshold value, table will be used for analysis. else table will be rejected. So I thought of counting the records of original table, and that of the valid table. Then the difference is compared to the threshold value. How do I do that in hive?? – Parameshwar Mar 19 '17 at 16:05