我正在使用hpd-2.4.2,并尝试使用oozie协调器作业向外部配置单元表添加分区。我创建了一个协调器,每天执行以下工作流程:
<workflow-app name="addPartition" xmlns="uri:oozie:workflow:0.4">
<start to="hive"/>
<action name="hive">
<hive2 xmlns="uri:oozie:hive2-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<jdbc-url>jdbc:hive2://${jdbcPath}</jdbc-url>
<password>yarn</password>
<script>${appPath}/addPartition.q</script>
<param>nameNode=${nameNode}</param>
<param>dt=${dt}</param>
<param>path=${path}</param>
</hive2>
<ok to="end" />
<error to="fail" />
</action>
<kill name="fail">
<message>
Workflow failed, error message[${wf:errorMessage(wf:lastErrorNode())}]
</message>
</kill>
<end name="end" />
</workflow-app>
执行的脚本包含
CREATE EXTERNAL TABLE IF NOT EXISTS visits (sid BIGINT, os STRING, browser STRING, visit_time TIMESTAMP)
PARTITIONED BY (dt STRING)
STORED AS PARQUET;
ALTER TABLE visits ADD PARTITION(dt = '${dt}') LOCATION '${nameNode}/data/parquet/visitors/${path}';
如果我运行该作业,则会创建表,但不会添加分区。我发现:
Beeline command arguments :
-u
jdbc:hive2://localhost:10000/default
-n
yarn
-p
yarn
-d
org.apache.hive.jdbc.HiveDriver
--hivevar
nameNode=hdfs://bigdata01.local:8020
--hivevar
dt=2016-01-05
--hivevar
path=2016/01/05
-f
addPartition.q
-a
delegationToken
--hiveconf
mapreduce.job.tags=oozie-1b3b2ee664df7ac9ee436379d784955a
Fetching child yarn jobs
tag id : oozie-1b3b2ee664df7ac9ee436379d784955a
Child yarn jobs are found -
=================================================================
>>> Invoking Beeline command line now >>>
[...]
0: jdbc:hive2://localhost:10000/default> ALTER TABLE visits ADD PARTITION(dt = '${dt}') LOCATION '${nameNode}/data/parquet/visitors/${path}';
似乎alter表中的参数没有被替换,为了检查这一点,我尝试直接从cli调用beeline:
beeline -u jdbc:hive2://localhost:10000/default -n yarn -p yarn -d org.apache.hive.jdbc.HiveDriver --hivevar nameNode=hdfs://bigdata01.local:8020 --hivevar dt="2016-01-03" --hivevar path="2016/01/03" -e "ALTER TABLE visits ADD PARTITION(dt='${dt}') LOCATION '${nameNode}/data/parquet/visitors/${path}';"
从而导致错误:
Connecting to jdbc:hive2://localhost:10000/default
Connected to: Apache Hive (version 1.2.1000.2.4.2.0-258)
Driver: Hive JDBC (version 1.2.1000.2.4.2.0-258)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. partition spec is invalid; field dt does not exist or is empty (state=08S01,code=1)
如果我不带参数运行alter语句
beeline -u jdbc:hive2://localhost:10000/default -n yarn -p yarn -d org.apache.hive.jdbc.HiveDriver -e "ALTER TABLE visits ADD PARTITION(dt='2016-01-03') LOCATION 'hdfs://bigdata01.local:8020/data/parquet/visitors/2016/01/03';"
或者打开一个定义了hivevars的beeline控制台并执行alter语句
beeline -u jdbc:hive2://localhost:10000/default -n yarn -p yarn -d org.apache.hive.jdbc.HiveDriver --hivevar nameNode=hdfs://bigdata01.local:8020 --hivevar dt="2016-01-03" --hivevar path="2016/01/03"
0: jdbc:hive2://localhost:10000/default> ALTER TABLE visits ADD PARTITION(dt = '${dt}') LOCATION '${nameNode}/data/parquet/visitors/${path}';
分区已创建。
我错在哪里?
更新:
hive2操作中参数的值在oozie.properties文件和coordinator.xml中定义
<property>
<name>nameNode</name>
<value>${nameNode}</value>
</property>
<property>
<name>dt</name>
<value>${coord:formatTime(coord:dateOffset(coord:nominalTime(), -1,'DAY'),'yyyy-MM-dd')}</value>
</property>
<property>
<name>path</name>
<value>${coord:formatTime(coord:dateOffset(coord:nominalTime(), -1,'DAY'),'yyyy/MM/dd')}</value>
</property>
在你找到的
Parameters:
------------------------
nameNode=hdfs://bigdata01.local:8020
dt=2016-01-05
path=2016/01/05
在hive2操作的直线调用中将它们设置为hivevars之前。
2条答案
按热度按时间yh2wf1be1#
谢谢你的帮助,但我放弃了。我将使用ssh操作来执行带有静态alter语句的beeline,而不是hive2操作。
jfgube3f2#
终于发现了问题。必须使用双引号而不是单引号;-)