Hive - Variable Substitution

> Database > Apache - Hive (HS|Hive Server)

1 - About

Language - Variable substitution in Hive.

substitution can be used in Hive commands or queries.

Advertising

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)
Advertising

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

db/hive/substitution.txt · Last modified: 2019/06/04 15:30 by gerardnico