我在尝试执行此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,仍然存在相同的错误。请问有人帮帮我吗?
答案 0 :(得分:2)
您需要引用$template
的扩展,将整个字符串视为impala-shell
的单个参数:
impala-shell -V -i $node "$template"
其中-V
启用详细输出。对于非详细(安静)输出,将-V
替换为-q
。
答案 1 :(得分: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,我必须以这种方式传递命令。