本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>