Workflow-Hive Action

本workflow位於oozie目錄下新創建的一個oozie-apps文件夾下的hive-select文件夾中。

hive-select

1、job.properties

2、lib文件夾(其中包含了一個mysql的驅動包)

3、workflow.xml

4、hive-site.xml

5、select-user.sql

將整個oozie-apps文件夾上傳到hdfs的對應用戶目錄下

然後運行程序

bin/oozie job -config oozie-apps/hive-select/job.properties -run


job.properties

nameNode=hdfs://BPF:9000
jobTracker=BPF:8032
queueName=default
oozieappsRoot=user/bpf/oozie-apps
DataRoot=user/bpf/oozie/datas

oozie.use.system.libpath=true

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

hive-site.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>

<property>
  <name>hive.cli.print.header</name>
  <value>true</value>
  <description>Whether to print the names of the columns in query output.</description>
</property>

<property>
  <name>hive.cli.print.current.db</name>
  <value>true</value>
  <description>Whether to include the current database in the Hive prompt.</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://BPF:3306/metastore?createDatabaseIfNotExist=true</value>
  <description>JDBC connect string for a JDBC metastore</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
  <description>Driver class name for a JDBC metastore</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>root</value>
  <description>username to use against metastore database</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>1234</value>
  <description>password to use against metastore database</description>
</property>

<property>
<name>hive.log4j.file</name>
<value>/opt/cdh-5.5.0/hive-1.1.0-cdh5.5.0/conf/hive-log4j.properties</value>
</property>

</configuration>

select-user.sql

insert overwrite directory '${OUTPUT}' 
select count(1) cnt from default.user;

workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.5" name="hive-select-wf">
    <start to="hive-node"/>

    <action name="hive-node">
        <hive xmlns="uri:oozie:hive-action:0.5">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <prepare>
                <delete path="${nameNode}/${DataRoot}/${outputDir}"/>
                <mkdir path="${nameNode}/${DataRoot}/${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>select-user.sql</script>
            <param>OUTPUT=${nameNode}/${DataRoot}/${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>



發佈了65 篇原創文章 · 獲贊 14 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章