我在尝试执行此 bash 代码时遇到问题:
function createImpalaPartition() {
period_id=$1;
database=$2
node=$3
actual_full=$(date -d@"$period_id" +%Y/%m/%d/%H/%M/)
template="use c2d;create EXTERNAL TABLE exptopology_$period_id (child_id bigint,parent_id bigint,level INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' WITH SERDEPROPERTIES ('serialization.format'=',', 'field.delim'=',') STORED AS TEXTFILE LOCATION '/hfc/sip/service/topology/$actual_full'"
echo "template is $template";
#impala-shell -V -i $node -d $database -q $template
impala-shell -V -i $node -q $template
}
这就是我调用它的方式:
createImpalaPartition $actual $impalaDatabase $impalaNode
哪里
actual=$(date +'%s')
impalaDatabase="dbName"
impalaNode="name_of_the_node"
脚本执行返回:
[core@dub-vcd-vms170 ~]$ createImpalaPartition $actual $impalaDatabase $impalaNode
template is use c2d;create EXTERNAL TABLE exptopology_1428326587 (child_id bigint,parent_id bigint,level INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' WITH SERDEPROPERTIES ('serialization.format'=',', 'field.delim'=',') STORED AS TEXTFILE LOCATION '/hfc/sip/service/topology/2015/04/06/14/23/'
Error, could not parse arguments "c2d;create EXTERNAL TABLE exptopology_1428326587 (child_id bigint,parent_id bigint,level INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' WITH SERDEPROPERTIES ('serialization.format'=',', 'field.delim'=',') STORED AS TEXTFILE LOCATION '/hfc/sip/service/topology/2015/04/06/14/23/'"
Usage: impala_shell.py [options]
如您所见,我必须使用 shell 脚本创建表。
更新:
关注此link ,我可以看到 impala-shell 可以这样使用,但我没有使用正确的参数。
我使用了 -f 而不是 -q,仍然存在相同的错误。有人可以帮我吗?
最佳答案
您需要引用 $template
的扩展,以便将整个字符串视为 impala-shell
的单个参数:
impala-shell -V -i $node "$template"
其中-V
启用详细输出。对于非详细(安静)输出,请将 -V
替换为 -q
。
关于bash - 关于如何在 shell 脚本中运行 impala-shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29472695/