kishore goud
kishore goud

Reputation: 11

Hive JDBC Connection returning "query did not generate a resultset"

I have built hive-jdbc from git and trying to execute a basic jdbc query to fetch a resultset. For some reason the query is throwing the following exception.

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)

The following is the snippet of the code I am using,

     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");

As suggested in another post, I am using executeQuery for DML but still unable to fetch the resultset.

I would appreciate some help on this. Thanks in Advance.

Upvotes: 0

Views: 2729

Answers (1)

kishore goud
kishore goud

Reputation: 11

I have managed to get the resultset after the following patch in 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;
  }

For some reason status.isHasResultSet() is returning false even though a resultset is available.

Upvotes: 1

Related Questions