Storing result of query in hive variable

2019-03-05 10:42发布

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?

标签: hive
1条回答
不美不萌又怎样
2楼-- · 2019-03-05 11:00

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'
查看更多
登录 后发表回答