How to use variables in HIVE Query

While working on HIVE, you may want to use variables in the query to get results. A good coding practice is not to hardcode values in the query itself so we should know how to use variables in the HIVE query. Hive variables can be referred using “hivevar” keyword.
We can set value of HIVE variable using below command:

SET hivevar:VARIABLE_NAME='VARIABLE_VALUE';

We can use this value by using ${hivevar:VARIABLE_NAME} in the query.
Example:

set hivevar:desc='Legislators';
select * from sample_07 where description=${hivevar:desc};
Use_Variables_Parameters_Arguments_In_Hive
Use_Variables_Parameters_Arguments_In_Hive

Leave a Reply