LanguageManual VariableSubstitution
Skip to end of metadata
Go to start of metadata


Hive is used for both interactive queries 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:

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 example:

results in:

For general information about Hive command line options, see Hive CLI.

Version information


The hiveconf option was added in version 0.7.0 (JIRA HIVE-1096). Version 0.8.0 added the options define and hivevar (JIRA HIVE-2020), which are equivalent and are not described here. They create custom variables in a namespace that is separate from the hiveconf, system, and env namespaces.

Using Variables

There are three namespaces for variables – hiveconf, system, and env. The hiveconf variables are set as normal:

However they are retrieved using:

Annotated examples of usage from the test case ql/src/test/queries/clientpositive/set_processor_namespaces.q:

Disabling Variable Substitution

Variable substitution is on by default. If this causes an issue with an already existing script, disable it.

  • No labels
  1. This doc comes from the Hive xdocs, with minor edits. It is included here because the xdocs are currently unavailable (Feb. 2013).

    In the first sentence "as well as part" should probably be changed to "as well as batch mode" or some such, but "part" is so far off that I'm wondering if it meant something else.