Hive - Variable Substitution

1 - About

Language - Variable substitution in Hive.

substitution can be used in Hive commands or queries.

3 - Type

Type Substitution
Configuration variable ${hiveconf:var}
Hive - Variable (hivevar) ${var}
System ${system:var}
Env ${env:var}

4 - Configuration

conf Hive - Configuration (Variable)


--default
set hive.variable.substitute=true; 
-- or
set hive.variable.substitute=false;

5 - Example

5.1 - Conf Variable

Example


set hive.exec.scratchdir;


+-------------------------------------------------+--+
|                       set                       |
+-------------------------------------------------+--+
| hive.exec.scratchdir=hdfs://mycluster/tmp/hive  |
+-------------------------------------------------+--+

  • Within a query and with substitution

select '${hiveconf:hive.exec.scratchdir}';


+------+
| hdfs://mycluster/tmp/hive |
+------+
| hdfs://mycluster/tmp/hive |
+------+
1 row selected (0.517 seconds)

5.2 - hivevar

Example with SQL - SQLLine (SQL at the command line) and a URL


sqlline -u "jdbc:hive2://HiveServer/db;#foo=bar" 

  • Select with substituion

select '${foo}';


+-----+
| bar |
+-----+
| bar |
+-----+
1 row selected (0.368 seconds)

6 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap