设为首页 加入收藏

TOP

Hive on oozie以及action间参数传递
2018-11-13 14:56:29 】 浏览:118
Tags:Hive oozie 以及 action 参数 传递

背景:
简单介绍下 hive action的使用,以及action间是如何进行参数传递的,这也是进行多job调度必备的操作~

集群环境:CDH 5.13.0 ,其中oozie版本:4.1.0,hive版本:1.1.0


一、Hue配置 Hive action

hue上创建hive任务必须添加两个配置项:scripthive xml
这里写图片描述
其中:
script 指的是hive sql 脚本,
hive xml 指的是hive-site.xml(该文件在CDH集群中每台机器的/etc/hive/conf目录下)

我们将 hive-site.xml 文件上传到 hdfs

hadoop fs -put /etc/hive/conf/hive-site.xml /yj/

配置完直接运行即可,hive action一般没啥坑~

附上workflow.xml

<workflow-app name="hiveshell-test2" xmlns="uri:oozie:workflow:0.5">
    <start to="hive-a0d5"/>
    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <action name="hive-a0d5" cred="hcat">
        <hive xmlns="uri:oozie:hive-action:0.2">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <job-xml>/yj/hive-site.xml</job-xml>
            <script>/yj/hive_script3.hql</script>
        </hive>
        <ok to="End"/>
        <error to="Kill"/>
    </action>
    <end name="End"/>
</workflow-app>

二、action间参数传递

我们在根据业务需求配置workflow.xml时,经常需要将上一个action得出的结果作为参数传递给下一个action,这种需求如何实现呢?

我们首先要明确的是:
hive action之间不支持传递参数,我们可以通过在shell 脚本中hive -e执行hql获取结果,再由shell传递给下一个hive action

目前我测试成功的有shell action中输出,然后在下一个hive actionshell action 接受上一个shell action 的输出结果;关于spark等其他action以后有时间在研究吧!


参数发送方(shell action):

先创建shell脚本 hive_script1:

# !/bin/bash
hive_test_count=`hive -e "select count(1) from house.h_apply"`
echo "hive_test_count=${hive_test_count}"

将其shell脚本配置到 shell action 作为结果参数发送方,然后在workflow.xml中添加<capture-output/>属性;

注:添加<capture-output/>元素可以捕获shell脚本的标准输出,然后在另一个action中里通过el表达式获取:${wf:actionData('shell action1').hive_test_count}${wf:actionData('shell action1')['hive_test_count']}

hue界面只需要勾选就行了!默认都是勾选好的!
这里写图片描述


1.参数接收方(shell action):

在shell-f704中添加<argument>值:

<argument>
    ${wf:actionData('shell-d412').hive_test_count}
</argument>

然后在该shell脚本hive_script2中获取:

# !/bin/bash
echo "aaaaa $1"

通过$数字来获取!

hue配置
这里写图片描述

附上workflow.xml

<workflow-app name="hiveshell-test1" xmlns="uri:oozie:workflow:0.5">
    <start to="shell-d412"/>
    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <action name="shell-d412">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>/yj/hive_script1</exec>
            <file>/yj/hive_script1#hive_script1</file>
              <capture-output/>
        </shell>
        <ok to="shell-f704"/>
        <error to="Kill"/>
    </action>
    <action name="shell-f704">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>/yj/hive_script2</exec>
              <argument>${wf:actionData('shell-d412').hive_test_count}</argument>
            <file>/yj/hive_script2#hive_script2</file>
              <capture-output/>
        </shell>
        <ok to="End"/>
        <error to="Kill"/>
    </action>
    <end name="End"/>
</workflow-app>

2.参数接收方(hive action):

在hive-a0d5中的workflow.xml里添加:

<param>
    COUNT=${wf:actionData('shell-d412').hive_test_count}
</param>

然后在hql脚本 hive_script3.hql中添加:

select ${COUNT}

hue配置
这里写图片描述

附上workflow.xml

<workflow-app name="hiveshell-test2" xmlns="uri:oozie:workflow:0.5">
    <start to="shell-928d"/>
    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <action name="shell-928d">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>/yj/hive_script1</exec>
            <file>/yj/hive_script1#hive_script1</file>
              <capture-output/>
        </shell>
        <ok to="hive-a0d5"/>
        <error to="Kill"/>
    </action>
    <action name="hive-a0d5" cred="hcat">
        <hive xmlns="uri:oozie:hive-action:0.2">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <job-xml>/yj/hive-site.xml</job-xml>
            <script>/yj/hive_script3.hql</script>
            <param>COUNT=${wf:actionData('shell-928d').hive_test_count}</param>
        </hive>
        <ok to="End"/>
        <error to="Kill"/>
    </action>
    <end name="End"/>
</workflow-app>
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇DBeaver安装使用手册 下一篇Hive之 hive的三种使用方式(CLI..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目