简体   繁体   English

Hive over Tez 通过 Hive JDBC - 错误

[英]Hive over Tez via Hive JDBC - Error

I am using Hortonworks Hadoop HDP-2.3.2.0-2950 Hive over Tez engine我在 Tez 引擎上使用 Hortonworks Hadoop HDP-2.3.2.0-2950 Hive

Below 2 queries are from Java code.以下 2 个查询来自 Java 代码。

  • select * from ascii -- works well select * from ascii -- 效果很好
  • select count(*) from ascii or select count(1) from ascii -- fails with error out select count(*) from ascii or select count(1) from ascii -- 失败并显示错误

My code:我的代码:

package com.hadoop.hive;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * 
 * @author hdpadmin
 *
 */
public class HiveReadJDBCMain {
        private static String driverName = "org.apache.hive.jdbc.HiveDriver";

        /**
         * @param args
         * @throws SQLException
         */
        public static void main(String[] args) throws SQLException {
                Connection con = null;
                PreparedStatement pst = null;
                ResultSet  res = null;

                try {

                        // Load Hive Driver Clazz
                        Class.forName(driverName);
                        // No username and password required.(running in a local machine)
                        con = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs");
                        //Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs", "<Username>", "<Password>");
                        String tableName = "ascii";
                        // select * query
                        String sql = "select * from " + tableName;
                        System.out.println("Select Query Running: " + sql);
                        pst = con.prepareStatement(sql);
                        res = pst.executeQuery();
                        while (res.next()) {
                                System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
                        }
                        pst.close();
                        res.close();

                        // regular hive query
                        sql = "select count(*) from " + tableName;
                        System.out.println("Count Query Running: " + sql);
                        pst = con.prepareStatement(sql);
                        res = pst.executeQuery();
                        while (res.next()) {
                                System.out.println(res.getString(1));
                        }
                } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                        System.exit(1);
                } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(1);
                } finally {
                        res.close();
                        pst.close();
                        con.close();
                }
        }
}

Error
java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.tez.TezTask
        at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:282)
        at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:378)
        at org.apache.hive.jdbc.HivePreparedStatement.executeQuery(HivePreparedStatement.java:109)
        at com.hadoop.hive.HiveReadJDBCMain.main(HiveReadJDBCMain.java:48)

是的,我已经通过使用我的用户名传递以下连接对象进行了修复。谢谢....:)

con = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs", "hdpadmin","");

i also fixed by passing username in connection string .我还通过在连接字符串中传递用户名来修复。 Thanks :)谢谢 :)

The queries like Select * from table; 像Select * from table这样的查询; work well because they don't launch any MR job. 工作得很好,因为他们没有启动任何MR工作。 When an MR job is launched, the user with which the JDBC Connection was made requires having proper access to HDFS directories which the Job will require. 启动MR作业时,与其建立JDBC连接的用户需要正确访问作业所需的HDFS目录。 If you want to see the actual stack trace run the same job by running in MR mode. 如果要查看实际堆栈跟踪,请通过在MR模式下运行来运行相同的作业。 To do so pass the following in the Connection String or as a parameter:- 为此,请在连接字符串中传递以下内容或作为参数: -

connection = DriverManager.getConnection("jdbc:hive2://localhost:10000/labs?hive.execution.engine=mr", "hive","");

This would print the actual error, I guess Tez abstracts away the actual error. 这将打印实际错误,我猜Tez抽象出实际错误。

This answer is in response to Saurab's comment on the answer above. 这个答案是对Saurab对上述答案评论的回应。 Didn't have enough repo to comment :p. 没有足够的回购评论:p。

In case your using the AWS Hive JDBC to talk with a default EMR cluster the following setup in Intellij worked for me如果您使用 AWS Hive JDBC 与默认 EMR 集群通信,Intellij 中的以下设置对我有用在此处输入图片说明

The trick was using user hadoop诀窍是使用用户hadoop

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

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