How to use variables in Hive while run the queries?

hivevar option in Hive

The hivevar option is used to create the custom variables and pass the values to the variable while run the queries in Hive.

Syntax of hivevar option:

The value will be substituted to the variable that used in the hive query.

Example:

We have created the custom variable as ${database} in the above hive query. The query is saved in the file create.hql in the following directory /x/home/revisit_user1. The value for the variable ${database} will be passed using the hivevar option.

Hive command to pass the value to the variable and execute the queries

Here we are passing the value “Banking_Db” to the variable database using the –hivevar option and -f is used the execute the hive queries that are present inside the file.

Once we hit the enter after this command, the value will substituted and queries will be executed in the Hive.

Output:

Variable substituted using –hivevar option

Recommended Articles