繁体   English   中英

如何在Oozie Java动作中运行Hive命令?

[英]How to run a Hive command from within Oozie Java action?

我有一个运行Java动作的oozie工作流程。 在java动作中,我需要描述一个Hive表以获得表的模式。 我通过使用流程生成器并执行包含describe table query的shell脚本来完成此describe table query

我的describeTable.sh:

hive -e 'describe <tableName>`

Java代码生成此脚本后,我将其复制到本地FS上的/tmp ,然后使用流程生成器执行脚本,如下所示:

fs.copyToLocalFile(bashScriptPath, new Path("/tmp/describeTable.sh"));
ProcessBuilder builder = new ProcessBuilder("bash", "/tmp/describeTable.sh");

脚本执行,但无法将hive识别为命令

/tmp/describeTable.sh: line 1: hive: command not found

我也尝试过/usr/bin/hive -e 'describe <tableName>' ,但是效果不佳。

当我在本地FS上将其作为jar文件执行时,java程序运行良好,但是作为oozie工作流程的一部分运行时,它会失败。

我不确定如何使它正常工作,我真的很感谢一些想法。

编辑

添加流程构建器的完整代码:

fs.copyToLocalFile(bashScriptPath, new Path("/tmp/describeTable.sh"));
    ProcessBuilder builder = new ProcessBuilder("bash", "/tmp/describeTable.sh");
    builder.directory(new File(currentLocalDir));
    ArrayList<String> columnList = new ArrayList<String>();
    System.err.println("trying to run script");
    try {
        final Process process = builder.start();
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        BufferedReader error1 = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        String errorLine=null;
        System.err.println("error stream: ");
        while((errorLine=error1.readLine())!=null){
            System.err.println(errorLine);
        }
        String line;
        System.err.println("input stream");
        while((line=br.readLine())!=null) {
            System.err.println("line from running script: " + line);
            String[] output = line.split("\t");
            columnList.add(output[0]);

        }
        is.close();
        isr.close();
        br.close();
        System.err.println("column list:" + columnList);
        return columnList;

Oozie将大多数(如果不是全部)动作作为Map Reduce作业运行,因此,您看到的错误消息可能是因为Java动作是在您的一个计算节点上执行的,而不是在您提交oozie作业的机器或该机器上执行的Oozie服务器正在运行的位置。

您可以确保将hive安装在群集中的所有计算节点上,或者使用Java Action中的Hive Java API并将hive库(以及所有依赖项)添加到HDFS中Oozie作业的共享库路径中。

暂无
暂无

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

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