关于如何在 shell 脚本中 运行 impala-shell
about how to run impala-shell within a shell script
我在尝试执行此 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
}
我是这样调用它的:
createImpalaPartition $actual $impalaDatabase $impalaNode
其中
actual=$(date +'%s')
impalaDatabase="dbName"
impalaNode="name_of_the_node"
执行脚本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]
如您所见,我必须使用 shell 脚本创建表格。
更新:
在这个 之后,我可以看到 impala-shell 可以那样使用,但我没有使用正确的参数。
我用-f代替了-q,还是一样的错误。有人可以帮帮我吗?
您需要引用 $template
的扩展,以便将整个字符串视为 impala-shell
的单个参数:
impala-shell -V -i $node "$template"
其中 -V
启用详细输出。对于非详细(安静)输出,将 -V
替换为 -q
。
终于我发现了如何解决我的问题。
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'"
}
我不能在创建命令中使用模板变量,我必须以这种方式传递命令。
我在尝试执行此 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
}
我是这样调用它的:
createImpalaPartition $actual $impalaDatabase $impalaNode
其中
actual=$(date +'%s')
impalaDatabase="dbName"
impalaNode="name_of_the_node"
执行脚本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]
如您所见,我必须使用 shell 脚本创建表格。
更新:
在这个
我用-f代替了-q,还是一样的错误。有人可以帮帮我吗?
您需要引用 $template
的扩展,以便将整个字符串视为 impala-shell
的单个参数:
impala-shell -V -i $node "$template"
其中 -V
启用详细输出。对于非详细(安静)输出,将 -V
替换为 -q
。
终于我发现了如何解决我的问题。
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'"
}
我不能在创建命令中使用模板变量,我必须以这种方式传递命令。