关于如何在shell脚本中运行impala-shell

问题描述 投票:2回答:2

我在尝试执行此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,仍然存在相同的错误。请问有人帮帮我吗?

bash shell impala
2个回答
2
投票

您需要引用$template的扩展,将整个字符串视为impala-shell的单个参数:

impala-shell -V -i $node "$template"

其中-V启用详细输出。对于非详细(安静)输出,用-V替换-q


0
投票

最后,我发现如何解决我的问题。

function createImpalaPartition() {

period_id=$1;
database=$2
node=$3

actual_full=$(date -d@"$period_id" +%Y/%m/%d/%H/%M/)
#UC=$(impala-shell -r -q "select count(1) from table where condition=1" -d $DB -i $HOST -B)
# attention, i have to use this way impala-shell
impala-shell -V -i $node -d $database -q "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'"
}

我不能在create命令中使用模板var,我必须以这种方式传递命令。

© www.soinside.com 2019 - 2024. All rights reserved.