bash - 将参数从 shell 脚本传递到 hive 脚本

标签 bash hadoop hive

我有一个问题可以分为两种方式: 我的要求是将参数从 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/

相关文章:

java - Hadoop Eclipse 插件构建错误

Hadoop Streaming Job 与 Hadoop 管道作业

sql-server - 配置单元加载 CSV : load part of columns (or column mapping)

mysql - Hive Metastore 服务器 (CDH) 启动失败

linux - 如何从命令行获取 Linux 中的 CPU/内核数?

linux - sed 替换字符串中的数字

hadoop - hive 中的maxCombinedSplitSize属性?

hadoop - 用于日志的 Snappy 或 LZO,然后由 hadoop 使用

bash - 为什么我不能在 bash 的 echo 中使用感叹号,即使它被转义了?

bash - 程序化保管箱共享