Use case: the following is valid in mysql:
set @max_date: = select max (date) from some_table;
select * from some_other_table, where date> @max_date;
This is very useful for scripts that must repeatedly call this variable, since you only need to query the maximum date once, and not every time the variable is called.
HIVE support is currently not supported. (please correct me if I'm wrong! I tried to figure out how to do this all day)
My workaround is to keep the required variable in a table that is small enough to map the connection to the query in which it is used. Since a connection is a card and not a broadcast connection, this should not significantly degrade performance. For instance:
drop table if var_table exists;
create var_table as table
select max (date) as max_date from some_table;
select some_other_table. *
from some_other_table
left join var_table
where some_other_table.date> var_table.max_date;
The proposed solution @visakh is not optimal, because it stores the string "select count (1) from table_name;" not a return value and therefore will not be useful in cases where you need to call var repeatedly during a script.
source share