简体   繁体   English

如何通过 oozie 工作流从 shell 脚本中的 Hive 中获取值?

[英]How to fetch value from Hive in shell script via an oozie workflow?

I have a shell script example.sh我有一个 shell 脚本example.sh

hive -e "select max(id) from dummy.table;" > data.txt
hdfs dfs -put -f data.txt /user/username/data.txt

This script fetches data from hive and stores the result in hdfs.此脚本从 hive 获取数据并将结果存储在 hdfs 中。 This is working as expected in terminal.这在终端中按预期工作。 But when I create an oozie workflow, the file created is empty.但是当我创建一个 oozie 工作流时,创建的文件是空的。 I tried printing some hardcoded value then the workflow runs fine.我尝试打印一些硬编码值,然后工作流程运行良好。 The problem is that when hive query is involved the data is absent though the job is successful.问题是,当涉及 hive 查询时,尽管作业成功,但数据不存在。 I tried running the same thing with hql and it was working successfully.我尝试用 hql 运行同样的东西,它运行成功。

insert overwrite directory '/user/username/hiveData' select max(id) from dummy.table;

But my requirement is such that I have to get hive data in my shell script.但我的要求是我必须在我的 shell 脚本中获取 hive 数据。

Since you do not have a check on $?既然你没有对$? you may not know that it is failing.你可能不知道它失败了。 So first step is to add that in your shell script.所以第一步是在你的 shell 脚本中添加它。 Or else you wont know whether the shell script failed (because of hive failure) and Oozie will get a successful run status of the shell script.否则你不会知道 shell 脚本是否失败(因为 hive 失败)并且 Oozie 将获得 shell 脚本的成功运行状态。

So without knowing what the real reason for failure of the hive code, I am making a guess.因此,在不知道 hive 代码失败的真正原因的情况下,我正在猜测。

If you have kerberos authentication, used by Hive, the hive query may be failing inside the shell script called by Oozie.如果您有由 Hive 使用的 kerberos 身份验证,则 hive 查询可能在 Oozie 调用的 shell 脚本中失败。 To resolve the kerberos issue, you may need to do something like this:要解决 kerberos 问题,您可能需要执行以下操作:

if [ -z ${HADOOP_TOKEN_FILE_LOCATION} ]
then
    hive -e "select max(id) from dummy.table;" > data.txt
else
    hive -e "SET mapreduce.job.credentials.binary=$HADOOP_TOKEN_FILE_LOCATION; select max(id) from dummy.table;" > data.txt
fi

You can read more about this here您可以在此处阅读有关此内容的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM