我已经从git构建了hive-jdbc并尝试执行基本的jdbc查询以获取结果集。由于某种原因,查询抛出以下异常。

16/07/01 22:08:12 INFO Utils: Supplied authorities: localhost:10000
16/07/01 22:08:12 INFO Utils: Resolved authority: localhost:10000
16/07/01 22:08:12 DEBUG TSaslTransport: opening transport org.apache.thrift.transport.TSaslClientTransport@55360888
16/07/01 22:08:12 DEBUG TSaslClientTransport: Sending mechanism name PLAIN and initial response of length 16
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: Writing message with status START and payload length 5
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: Writing message with status COMPLETE and payload length 16
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: Start message handled
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: Main negotiation loop complete
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: SASL Client receiving last message
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: Received message with status COMPLETE and payload length 0
16/07/01 22:08:12 DEBUG TSaslTransport: writing data length: 71
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: reading data length: 109
16/07/01 22:08:12 DEBUG TSaslTransport: writing data length: 183
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: reading data length: 109
16/07/01 22:08:12 DEBUG TSaslTransport: writing data length: 100
16/07/01 22:08:12 DEBUG TSaslTransport: CLIENT: reading data length: 53
Exception in thread "main" java.sql.SQLException: The query did not generate a result set!
   at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:459)
   at com.kris.mond.sample.HiveQuery.main(HiveQuery.java:20)

以下是我正在使用的代码段,
     try {
         Class.forName("org.apache.hive.jdbc.HiveDriver");
        } catch (ClassNotFoundException e) {
            System.err.println("Could not load the driver");
            System.exit(1);
        }
     Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hduser", "*******");
     Statement stmt = con.createStatement();
     ResultSet rs = stmt.executeQuery("select account_id,account_parent,account_description from account");

如另一篇文章中所建议,我正在将executeQuery用于DML,但仍无法获取结果集。

我希望对此有所帮助。
提前致谢。

最佳答案

在HiveStatement.java中的以下修补程序之后,我设法获得了结果集

public boolean execute(String sql) throws SQLException {
    runAsyncOnServer(sql);
    TGetOperationStatusResp status = waitForOperationToComplete();

    **// The query should be completed by now
 -->   /*if (!status.isHasResultSet()) {
 -->     return false;
 -->   }*/**
    resultSet =  new HiveQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle)
        .setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize)
        .setScrollable(isScrollableResultset)
        .build();
    return true;
  }

由于某种原因,即使结果集可用, status.isHasResultSet()返回false。

关于hadoop - Hive JDBC连接返回 “query did not generate a resultset”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38150462/

10-12 22:54
查看更多