hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1520604 - /hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
Date Fri, 06 Sep 2013 15:29:40 GMT
Author: brock
Date: Fri Sep  6 15:29:40 2013
New Revision: 1520604

URL: http://svn.apache.org/r1520604
Log:
HIVE-5060: JDBC driver assumes executeStatement is synchronous (Henry Robinson via Brock Noland)

Modified:
    hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java

Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java?rev=1520604&r1=1520603&r2=1520604&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java Fri Sep  6 15:29:40 2013
@@ -32,6 +32,8 @@ import org.apache.hive.service.cli.thrif
 import org.apache.hive.service.cli.thrift.TCloseOperationResp;
 import org.apache.hive.service.cli.thrift.TExecuteStatementReq;
 import org.apache.hive.service.cli.thrift.TExecuteStatementResp;
+import org.apache.hive.service.cli.thrift.TGetOperationStatusReq;
+import org.apache.hive.service.cli.thrift.TGetOperationStatusResp;
 import org.apache.hive.service.cli.thrift.TOperationHandle;
 import org.apache.hive.service.cli.thrift.TSessionHandle;
 
@@ -193,6 +195,44 @@ public class HiveStatement implements ja
     }
 
     if (!stmtHandle.isHasResultSet()) {
+      // Poll until the query has completed one way or another. DML queries will not return
a result
+      // set, but we should not return from this method until the query has completed to
avoid
+      // racing with possible subsequent session shutdown, or queries that depend on the
results
+      // materialised here.
+      TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle);
+      boolean requestComplete = false;
+      while (!requestComplete) {
+        try {
+          TGetOperationStatusResp statusResp = client.GetOperationStatus(statusReq);
+          Utils.verifySuccessWithInfo(statusResp.getStatus());
+          if (statusResp.isSetOperationState()) {
+            switch (statusResp.getOperationState()) {
+            case CLOSED_STATE:
+            case FINISHED_STATE:
+              return false;
+            case CANCELED_STATE:
+              // 01000 -> warning
+              throw new SQLException("Query was cancelled", "01000");
+            case ERROR_STATE:
+              // HY000 -> general error
+              throw new SQLException("Query failed", "HY000");
+            case UKNOWN_STATE:
+              throw new SQLException("Unknown query", "HY000");
+            case INITIALIZED_STATE:
+            case RUNNING_STATE:
+              break;
+            }
+          }
+        } catch (Exception ex) {
+          throw new SQLException(ex.toString(), "08S01", ex);
+        }
+
+        try {
+          Thread.sleep(100);
+        } catch (InterruptedException ex) {
+          // Ignore
+        }
+      }
       return false;
     }
     resultSet =  new HiveQueryResultSet.Builder().setClient(client).setSessionHandle(sessHandle)



Mime
View raw message