Hive变量替换不能从hive -e命令工作

时间:2013-03-06 06:16:15

标签: unix hadoop hive

我正在尝试使用Hive变量。

如果我登录Hive并使用:

hive > set a=test_table;
hive > describe ${hiveconf:a};

但是如果从Shell尝试使用相同的命令,它会给出:解析错误1:1无法识别附近的输入...

$> hive -e "set a=test_table; describe ${hiveconf:a};"
Parse Error 1:1 cannot recognize input near <EOF>

3 个答案:

答案 0 :(得分:0)

Parameter Expansion
   The `$' character introduces parameter expansion, command substitution, or arithmetic expansion.  The parameter name  or
   symbol  to  be  expanded  may be enclosed in braces, which are optional but serve to protect the variable to be expanded
   from characters immediately following it which could be interpreted as part of the name.

   When braces are used, the matching ending brace is the first `}' not escaped by a backslash or within a  quoted  string,
   and not within an embedded arithmetic expansion, command substitution, or parameter expansion.

   ${parameter}
          The  value  of  parameter  is substituted.  The braces are required when parameter is a positional parameter with
          more than one digit, or when parameter is followed by a character which is not to be interpreted as part  of  its
          name.

所以hive -e 'set a=test_table; desc ${hiveconf:a};'

答案 1 :(得分:0)

尝试一下:

hive --hiveconf a =“ test_table” -e“描述数据库。$ {hiveconf:a}”

答案 2 :(得分:-1)

你必须像下面这样编码。

   >a=test_table
   >hive -e "describe $a"

Check language manual