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?
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.
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';
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`;
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With