I am trying to set hivevar using the query below. But its not able to detect the date when I use it in a query later.
set hivevar:curr_date = select date_sub(max(partition_date), 1) from mytable;
select * from mytable where partition_date = '${curr_date}' limit 10;
No Results
However, it works when I hardcode the hivevar
set hivevar:curr_date = '2017-03-11';
select * from mytable where partition_date = '${curr_date}' limit 10;
Results:
partition_date cookie userid value
2017-03-11 015ABF9C4C6601016574F15E684C8F14 b1a19464f74d6 Melrose
Hive variables are nothing but a text replacement mechanism.
The replacement is done before parsing and execution.
Passing a query result as an argument to another query can be done from the shell, e.g. -