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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29472695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:44:17  来源:igfitidea点击:

about how to run impala-shell within a shell script

bashshellimpala

提问by aironman

i have a problem when trying to execute this bash code:

尝试执行此 bash 代码时遇到问题:

function createImpalaPartition() {

period_id=;
database=
node=

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
}

This is how i invoke it:

这是我调用它的方式:

createImpalaPartition $actual $impalaDatabase $impalaNode

where

在哪里

actual=$(date +'%s')
impalaDatabase="dbName"
impalaNode="name_of_the_node"

the execution of the script returns:

脚本的执行返回:

[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]

As you can see, i have to create tables using a shell script.

如您所见,我必须使用 shell 脚本创建表。

UPDATE:

更新:

following this link, i can see that impala-shell can be used that way, but i am not using the correct params.

按照此链接,我可以看到可以以这种方式使用impala-shell,但我没有使用正确的参数。

I have used -f instead of -q, the same error remains. Can anybody help me, please?

我使用了 -f 而不是 -q,同样的错误仍然存​​在。有人可以帮我吗?

采纳答案by chepner

You need to quote the expansion of $templatefor the entire string to be treated as a single argument to impala-shell:

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

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

where -Venables verbose output. For non-verbose (quiet) output replace -Vwith -q.

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

回答by aironman

Finally i discover how to resolve my problem.

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

function createImpalaPartition() {

period_id=;
database=
node=

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'"
}

I can't use a template var with the create command, I have to pass the command this way.

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