You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by sa...@apache.org on 2019/03/13 04:44:45 UTC
[hive] branch master updated: HIVE-21421: HiveStatement.getQueryId
throws NPE when query is not running (Sankar Hariappan,
reviewed by Mahesh Kumar Behera)
This is an automated email from the ASF dual-hosted git repository.
sankarh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 13938db HIVE-21421: HiveStatement.getQueryId throws NPE when query is not running (Sankar Hariappan, reviewed by Mahesh Kumar Behera)
13938db is described below
commit 13938db46ff89fc4a425854b4795df604ced8ba9
Author: Sankar Hariappan <sa...@apache.org>
AuthorDate: Wed Mar 13 10:13:36 2019 +0530
HIVE-21421: HiveStatement.getQueryId throws NPE when query is not running (Sankar Hariappan, reviewed by Mahesh Kumar Behera)
Signed-off-by: Sankar Hariappan <sa...@apache.org>
---
.../java/org/apache/hive/jdbc/TestJdbcDriver2.java | 7 ++++++-
jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java | 19 ++++++++++++++++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
index 45aac5f..14187cc 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
@@ -3044,8 +3044,13 @@ public class TestJdbcDriver2 {
public void testGetQueryId() throws Exception {
HiveStatement stmt = (HiveStatement) con.createStatement();
HiveStatement stmt1 = (HiveStatement) con.createStatement();
- stmt.executeAsync("create database query_id_test with dbproperties ('repl.source.for' = '1, 2, 3')");
+
+ // Returns null if no query is running.
String queryId = stmt.getQueryId();
+ assertTrue(queryId == null);
+
+ stmt.executeAsync("create database query_id_test with dbproperties ('repl.source.for' = '1, 2, 3')");
+ queryId = stmt.getQueryId();
assertFalse(queryId.isEmpty());
stmt.getUpdateCount();
diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
index a9a312c..d9b6254 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
@@ -18,8 +18,8 @@
package org.apache.hive.jdbc;
-import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.codec.binary.Base64;
+import org.apache.hadoop.hive.common.classification.InterfaceAudience.LimitedPrivate;
import org.apache.hive.jdbc.logs.InPlaceUpdateStream;
import org.apache.hive.service.cli.RowSet;
import org.apache.hive.service.cli.RowSetFactory;
@@ -37,7 +37,6 @@ import org.apache.hive.service.rpc.thrift.TGetOperationStatusReq;
import org.apache.hive.service.rpc.thrift.TGetOperationStatusResp;
import org.apache.hive.service.rpc.thrift.TGetQueryIdReq;
import org.apache.hive.service.rpc.thrift.TOperationHandle;
-import org.apache.hive.service.rpc.thrift.TOperationState;
import org.apache.hive.service.rpc.thrift.TSessionHandle;
import org.apache.thrift.TException;
import org.slf4j.Logger;
@@ -1007,12 +1006,26 @@ public class HiveStatement implements java.sql.Statement {
this.inPlaceUpdateStream = stream;
}
- @VisibleForTesting
+ /**
+ * Returns the Query ID if it is running.
+ * This method is a public API for usage outside of Hive, although it is not part of the
+ * interface java.sql.Statement.
+ * @return Valid query ID if it is running else returns NULL.
+ * @throws SQLException If any internal failures.
+ */
+ @LimitedPrivate(value={"Hive and closely related projects."})
public String getQueryId() throws SQLException {
+ if (stmtHandle == null) {
+ // If query is not running or already closed.
+ return null;
+ }
try {
return client.GetQueryId(new TGetQueryIdReq(stmtHandle)).getQueryId();
} catch (TException e) {
throw new SQLException(e);
+ } catch (Exception e) {
+ // If concurrently the query is closed before we fetch queryID.
+ return null;
}
}
}