我有一个问题可以分为两种方式: 我的要求是将参数从 shell 脚本传递到 hive 脚本。 要么 在一个 shell 脚本中,我应该在配置单元语句中包含变量的值。
我将用一个例子来解释这两者:
1) 从 shell 脚本传递参数到 hiveQL->
My test Hive QL:
select count(*) from demodb.demo_table limit ${hiveconf:num}
我的测试 shell 脚本:
cnt=1
sh -c 'hive -hiveconf num=$cnt -f countTable.hql'
所以基本上我想在 HQL 中包含“cnt”的值,在这种情况下不会发生这种情况。我得到的错误是:
FAILED: ParseException line 2:0 mismatched input '<EOF>' expecting Number near 'limit' in limit clause
我确定这个错误意味着变量的值没有被传递。
2) 直接在 shell 脚本中传递参数->
cnt=1
hive -e 'select count(*) from demodb.demo_table limit $cnt'
在上述两种情况下,我都无法传递参数值。有什么想法吗??
PS:我知道查询在计数中包含“限制”似乎很荒谬,但我已经改述了我实际遇到的问题。传递参数的要求保持不变。
任何想法,任何人?
提前致谢。
最佳答案
这样设置变量:
#!/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"
关于bash - 将参数从 shell 脚本传递到 hive 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30592007/