Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate expression in HIVE set statements

In my hive queries I set some variables.

However I realized that hive remember the expression rather than the value, for example:

set a=1 ;
set b=2 ;
set c= ${hiveconf:a} + ${hiveconf:b} ;
set c ;
-- the command above returns
-- c=1 + 2

Why Hive doesn't evaluate the value? Is there any way to set hive so that set c ; would return c= 3 in my previous example?

like image 695
lucacerone Avatar asked Oct 14 '14 07:10

lucacerone


People also ask

WHAT IS SET command in hive?

We can use the hive SET command to either override an existing hive property(can not override environmental variables) or display the configuration property of the hive containing system and environmental variables. The separated property can also be checked with the SET command in the hive.

How do you set variables in hive?

Here is how you set the variables. It is good practice to properly specify the namespace on where you are setting these variables. We are using hivevar namespace here and the variable name is date-ymd. hive> set hivevar:date-ymd = '2019-11-15';

How do you store hive query results in a variable?

Bookmark this question. Show activity on this post. ./hive -e "use telecom;insert overwrite local directory '/tmp/result' select avg(a) from abc;" ./hive --hiveconf MY_VAR =`cat /tmp/result/000000_0`;

How do I display a variable value in hive?

You may have to write additional lines in your hive script to view the values/redirect them to a separate file. As far as I know there is no such config property. You may have to write additional lines in your hive script to view the values/redirect them to a separate file.


1 Answers

Generally at point you are only defining variables in CLI. Evaluation will take place during map reduce run, ex.

SELECT ${hiveconf:c} FROM yourTable LIMIT 1;

will give you calculated value of c.

like image 144
www Avatar answered Sep 25 '22 19:09

www