PageRenderTime 37ms CodeModel.GetById 10ms 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
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  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. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied. See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <document>
  19. <properties>
  20. <title>Hadoop Hive- Variable Substitution</title>
  21. <author email="hive-user@hadoop.apache.org">Hadoop Hive Documentation Team</author>
  22. </properties>
  23. <body>
  24. <h3>Hive Variable Substitution</h3>
  25. <section name="Introduction" href="Introduction">
  26. <p>Hive is used for both interactive queries as well as part. The hive variable substitution mechanism was
  27. designed to avoid some of the code that was getting baked into the scripting language ontop of hive. For example:</p>
  28. <source><![CDATA[$ a=b
  29. $ hive -e " describe $a "
  30. ]]></source>
  31. <p>
  32. are becoming common place. This is frustrating as hive becomes closely coupled with scripting languages. The hive
  33. startup time of a couple seconds is non-trivial when doing thousands of manipulations multiple hive -e invocations.</p>
  34. <p>
  35. Hive Variables combine the set capability you know and love with some limited yet powerful (evil laugh) substitution
  36. ability. For example:</p>
  37. <source><![CDATA[$ bin/hive -hiveconf a=b -e 'set a; set hiveconf:a; \
  38. create table if not exists b (col int); describe ${hiveconf:a}'
  39. ]]></source>
  40. <p>Results in:</p>
  41. <source><![CDATA[Hive history file=/tmp/edward/hive_job_log_edward_201011240906_1463048967.txt
  42. a=b
  43. hiveconf:a=b
  44. OK
  45. Time taken: 5.913 seconds
  46. OK
  47. col int
  48. Time taken: 0.754 seconds
  49. ]]></source>
  50. </section>
  51. <section name="Using variables" href="using_variables">
  52. <p>There are three namespaces for variables hiveconf,system, and env. hiveconf variables are set as normal:</p>
  53. <source><![CDATA[set x=myvalue
  54. ]]></source>
  55. <p>However they are retrieved using</p>
  56. <source><![CDATA[${hiveconf:x}
  57. ]]></source>
  58. <p>Annotated examples of usage from the test case ql/src/test/queries/clientpositive/set_processor_namespaces.q</p>
  59. <source><![CDATA[set zzz=5;
  60. -- sets zzz=5
  61. set zzz;
  62. set system:xxx=5;
  63. set system:xxx;
  64. -- sets a system property xxx to 5
  65. set system:yyy=${system:xxx};
  66. set system:yyy;
  67. -- sets yyy with value of xxx
  68. set go=${hiveconf:zzz};
  69. set go;
  70. -- sets go base on value on zzz
  71. set hive.variable.substitute=false;
  72. set raw=${hiveconf:zzz};
  73. set raw;
  74. -- disable substitution set a value to the literal
  75. set hive.variable.substitute=true;
  76. EXPLAIN SELECT * FROM src where key=${hiveconf:zzz};
  77. SELECT * FROM src where key=${hiveconf:zzz};
  78. --use a variable in a query
  79. set a=1;
  80. set b=a;
  81. set c=${hiveconf:${hiveconf:b}};
  82. set c;
  83. --uses nested variables.
  84. set jar=../lib/derby.jar;
  85. add file ${hiveconf:jar};
  86. list file;
  87. delete file ${hiveconf:jar};
  88. list file;
  89. ]]></source>
  90. </section>
  91. <section name="Disabling" href="disable">
  92. <p>Variable substitution is on by default. If this causes an issue with an already existing script disable it.</p>
  93. <source><![CDATA[set hive.variable.substitute=false;
  94. ]]></source>
  95. </section>
  96. </body>
  97. </document>