Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: update based on comments, clean up wording

...

Introduction

Hive is used for both batch and interactive queries. Variable Substitution allows for tasks such as separating environment-specific configuration variables from code.

as well as part. The Hive variable substitution mechanism was designed to avoid some of the code that was getting baked into the scripting language on top of Hive.

Examples such as the following shell commands may (inefficiently) be used to set variables within a script:

Code Block
$ a=b
$ hive -e " describe $a "

are becoming commonplace. This is frustrating as Hive becomes closely coupled with scripting languages. The Hive startup time of a couple seconds is non-trivial when doing thousands of manipulations such as multiple hive -e invocations.

Hive Variables combine the set capability you know and love with some limited yet powerful (evil laugh) substitution ability. For

The following example:

Code Block
$ bin/hive --hiveconf a=b -e 'set a; set hiveconf:a; \
create table if not exists b (col int); describe ${hiveconf:a}'

...

Hive substitutes the value for a variable when a query is constructed with the variable.

  • If you run two different Hive sessions, variable values will not be mixed across sessions.

...

  • If you set variables with the same name in the same Hive session, a query uses the last set value.

Disabling Variable Substitution

Variable substitution is on by default (hive.variable.substitute=true). If this causes an issue with an already existing script, disable it .using the following command:

Code Block
set hive.variable.substitute=false;