Oozie workflow之Hive Action

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zzw0221/article/details/81697874

1、将examples中的hive复制到oozie-apps目录下,并重命名

/opt/cdh5.14.2/oozie-4.1.0/oozie-apps/hive-select
[root@master hive-select]# ll
total 20
-rw-r--r-- 1 root root 1000 Aug  4 13:52 job.properties
-rw-r--r-- 1 root root  110 Aug  4 13:52 README
-rw-r--r-- 1 root root  966 Aug  4 13:52 script.q
-rw-r--r-- 1 root root 2003 Aug  4 13:52 workflow.xml
-rw-r--r-- 1 root root 2398 Aug  4 13:52 workflow.xml.security

2、在hive-select目录下创建目录lib,并将mysql-connector-java-5.1.27-bin.jar放到lib目录下

3、将hive中的配置hive-site.xml复制到hive-select目录下

4、job.properties

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
nameNode=hdfs://ns1
jobTracker=master.cdh.com:8032
queueName=default
oozieAppsRoot=user/root/oozie-apps
oozieDataRoot=user/root/oozie/datas

oozie.use.system.libpath=true

oozie.wf.application.path=${nameNode}/${oozieAppsRoot}/hive-select/workflow.xml
outputDir=hive-select/output

5、userinfo-script.sql

insert overwrite directory '${OUTPUT}'
select user_id,user_name from db_bbc.tb_user;

6、workflow.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<workflow-app xmlns="uri:oozie:workflow:0.5" name="hive-select-wf">
    <start to="hive-select-node"/>

    <action name="hive-select-node">
        <hive xmlns="uri:oozie:hive-action:0.5">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <prepare>
                <delete path="${nameNode}/${oozieDataRoot}/${outputDir}"/>
            </prepare>
			<job-xml>${nameNode}/${oozieAppsRoot}/hive-select/hive-site.xml</job-xml>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
            </configuration>
            <script>userinfo-script.sql</script>
            <param>OUTPUT=${nameNode}/${oozieDataRoot}/${outputDir}</param>
        </hive>
        <ok to="end"/>
        <error to="fail"/>
    </action>

    <kill name="fail">
        <message>Hive failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

8、将 hive-select上传到hdfs

bin/hdfs dfs -put /opt/cdh5.14.2/oozie-4.1.0/oozie-apps/hive-select /user/root/oozie-apps

9、启动ozzie任务:

[root@master oozie-4.1.0]# bin/oozie job -oozie http://master.cdh.com:11000/oozie/ -config oozie-apps/hive-select/job.properties -run
job: 0000002-180805230543527-oozie-root-W

 10、任务结束以及结果:

[root@master hadoop-2.6.0]# bin/hdfs dfs -text /user/root/oozie/datas/hive-select/output/0*
18/08/06 05:22:25 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
扫描二维码关注公众号,回复: 4717021 查看本文章

猜你喜欢

转载自blog.csdn.net/zzw0221/article/details/81697874