我是靠谱客的博主 虚幻铃铛,这篇文章主要介绍Hive on 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

复制代码
1
hadoop fs -put /etc/hive/conf/hive-site.xml /yj/

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

附上workflow.xml

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<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:

复制代码
1
2
3
# !/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>值:

复制代码
1
2
3
<argument> ${wf:actionData('shell-d412').hive_test_count} </argument>

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

复制代码
1
2
# !/bin/bash echo "aaaaa $1"

通过$数字来获取!

hue配置
这里写图片描述

附上workflow.xml

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<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里添加:

复制代码
1
2
3
<param> COUNT=${wf:actionData('shell-d412').hive_test_count} </param>

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

复制代码
1
select ${COUNT}

hue配置
这里写图片描述

附上workflow.xml

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<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>

最后

以上就是虚幻铃铛最近收集整理的关于Hive on oozie以及action间参数传递的全部内容,更多相关Hive内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部