【问题标题】:How to run a Hive command from within Oozie Java action?如何从 Oozie Java 操作中运行 Hive 命令?
【发布时间】:2015-12-08 13:34:03
【问题描述】:

我有一个运行 Java 操作的 oozie 工作流。在 java 操作中,我需要描述一个 Hive 表来获取表的架构。我通过使用进程构建器并执行包含 describe table query

的 shell 脚本来做到这一点

我的 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 &lt;tableName&gt;' ,但效果不佳。

当我在本地 FS 上将 java 程序作为 jar 文件执行时,它可以正常工作,但是当我将它作为 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;

【问题讨论】:

  • 尝试从你的 describeTable.sh 运行 'which hive' 或 'echo $PATH' 看看为什么它找不到 hive
  • 它说 hive 命令未找到...我猜 hive 没有安装在集群的所有节点上?
  • echo $PATH 打印一个空行 btw..
  • 宾果游戏!您使用 ProcessBuilder 的方式有问题
  • @Oleksii,我添加了流程构建器部分的完整代码。我不确定我做错了什么。

标签: java hadoop hive oozie


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-29
    • 2014-10-20
    • 1970-01-01
    相关资源
    最近更新 更多