将参数从shell脚本传递给hive脚本

kno*_*one 3 bash hadoop hive

我有一个问题,可以分为两种方式:我的要求是将参数从shell脚本传递给hive脚本.或者在一个shell脚本中我应该在hive语句中包含变量的值.

我将用两个例子来解释:

1)将参数从shell脚本传递给hiveQL->

My test Hive QL:
select count(*) from demodb.demo_table limit ${hiveconf:num}
Run Code Online (Sandbox Code Playgroud)

我的测试shell脚本:

cnt=1
sh -c 'hive -hiveconf num=$cnt -f countTable.hql'
Run Code Online (Sandbox Code Playgroud)

所以基本上我想在HQL中包含'cnt'的值,在这种情况下不会发生这种情况.我得到的错误是:

FAILED: ParseException line 2:0 mismatched input '<EOF>' expecting Number near 'limit' in limit clause
Run Code Online (Sandbox Code Playgroud)

我确定错误意味着变量的值没有被传递.

2)直接在shell脚本中传递参数 - >

cnt=1
hive -e 'select count(*) from demodb.demo_table limit $cnt'
Run Code Online (Sandbox Code Playgroud)

在上述两种情况下,我都无法传递参数值.有任何想法吗??

PS:我知道查询似乎很荒谬,包括计数中的'限制',但我已经改写了我实际拥有的问题.通过论证的要求仍然完整无缺.

任何想法,任何人?

提前致谢.

sra*_*ras 8

以这种方式设置变量:

#!/bin/bash
cnt=3
echo "Executing the hive query - starts"
hive -hiveconf num=$cnt -e ' set num; select * from demodb.demo_table limit ${hiveconf:num}'
echo "Executing the hive query - ends"
Run Code Online (Sandbox Code Playgroud)