PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/docs/xdocs/language_manual/var_substitution.xml

#
XML | 130 lines | 81 code | 31 blank | 18 comment | 0 complexity | ec3d091e49dcc11e5a58435f050c39e0 MD5 | raw file
  1<?xml version="1.0" encoding="UTF-8"?>
  2<!--
  3 Licensed to the Apache Software Foundation (ASF) under one
  4 or more contributor license agreements.  See the NOTICE file
  5 distributed with this work for additional information
  6 regarding copyright ownership.  The ASF licenses this file
  7 to you under the Apache License, Version 2.0 (the
  8 "License"); you may not use this file except in compliance
  9 with the License.  You may obtain a copy of the License at
 10
 11   http://www.apache.org/licenses/LICENSE-2.0
 12
 13 Unless required by applicable law or agreed to in writing,
 14 software distributed under the License is distributed on an
 15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 16 KIND, either express or implied.  See the License for the
 17 specific language governing permissions and limitations
 18 under the License.
 19-->
 20
 21<document>
 22
 23  <properties>
 24    <title>Hadoop Hive- Variable Substitution</title>
 25    <author email="hive-user@hadoop.apache.org">Hadoop Hive Documentation Team</author>
 26  </properties>
 27
 28  <body>
 29<h3>Hive Variable Substitution</h3>
 30<section name="Introduction" href="Introduction">
 31
 32<p>Hive is used for both interactive queries as well as part. The hive variable substitution mechanism was 
 33designed to avoid some of the code that was getting baked into the scripting language ontop of hive. For example:</p>
 34
 35<source><![CDATA[$ a=b
 36$ hive -e " describe $a "
 37]]></source>
 38
 39<p>
 40are becoming common place. This is frustrating as hive becomes closely coupled with scripting languages. The hive
 41startup time of a couple seconds is non-trivial when doing thousands of manipulations multiple hive -e invocations.</p>
 42
 43<p>
 44Hive Variables combine the set capability you know and love with some limited yet powerful (evil laugh) substitution 
 45ability. For example:</p>
 46
 47<source><![CDATA[$ bin/hive -hiveconf a=b -e 'set a; set hiveconf:a; \
 48create table if not exists b (col int); describe ${hiveconf:a}'
 49]]></source>
 50
 51<p>Results in:</p>
 52<source><![CDATA[Hive history file=/tmp/edward/hive_job_log_edward_201011240906_1463048967.txt
 53a=b
 54hiveconf:a=b
 55OK
 56Time taken: 5.913 seconds
 57OK
 58col	int	
 59Time taken: 0.754 seconds
 60]]></source>
 61
 62</section>
 63
 64<section name="Using variables" href="using_variables">
 65
 66<p>There are three namespaces for variables hiveconf,system, and env. hiveconf variables are set as normal:</p>
 67
 68<source><![CDATA[set x=myvalue
 69]]></source>
 70
 71<p>However they are retrieved using</p>
 72
 73<source><![CDATA[${hiveconf:x}
 74]]></source>
 75 
 76<p>Annotated examples of usage from the test case ql/src/test/queries/clientpositive/set_processor_namespaces.q</p>
 77
 78<source><![CDATA[set zzz=5;
 79--  sets zzz=5
 80set zzz;
 81
 82set system:xxx=5;
 83set system:xxx;
 84-- sets a system property xxx to 5
 85
 86set system:yyy=${system:xxx};
 87set system:yyy;
 88-- sets yyy with value of xxx
 89
 90set go=${hiveconf:zzz};
 91set go;
 92-- sets go base on value on zzz
 93
 94set hive.variable.substitute=false;
 95set raw=${hiveconf:zzz};
 96set raw;
 97-- disable substitution set a value to the literal
 98
 99set hive.variable.substitute=true;
100
101EXPLAIN SELECT * FROM src where key=${hiveconf:zzz};
102SELECT * FROM src where key=${hiveconf:zzz};
103--use a variable in a query
104
105set a=1;
106set b=a;
107set c=${hiveconf:${hiveconf:b}};
108set c;
109--uses nested variables. 
110
111
112set jar=../lib/derby.jar;
113
114add file ${hiveconf:jar};
115list file;
116delete file ${hiveconf:jar};
117list file;
118]]></source>
119</section>
120
121<section name="Disabling" href="disable">
122  <p>Variable substitution is on by default. If this causes an issue with an already existing script disable it.</p>
123
124<source><![CDATA[set hive.variable.substitute=false;
125]]></source>
126
127</section>
128
129</body>
130</document>