Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view the calculated value of a hive variable

Tags:

sql

hql

hadoop

hive

I'm trying to see the value of a calculated value in hive. For example, I'm trying to get the year from this tablename:

set TABLE_NAME = orders2014;
set TABLE_YEAR = substr(${hiveconf:TABLE_NAME},6,4);
set TABLE_YEAR;

The result I get is the uncalculated string;

substr(${hiveconf:TABLE_NAME},6,4)

What I would like to get is the calculated value, "2014". How would I see this value?

Thanks

like image 444
Peter Avatar asked Dec 30 '25 13:12

Peter


1 Answers

Hive "variables" are actually nothing more than 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
like image 141
David דודו Markovitz Avatar answered Jan 01 '26 02:01

David דודו Markovitz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!