This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new abb782cea [KYUUBI #6114] Properly handle 
KyuubiStatement#getMoreResults(CLOSE_CURRENT_RESULT)
abb782cea is described below

commit abb782ceaf4e19c62c5e771d5f96188411bf4342
Author: Tigran Manasyan <[email protected]>
AuthorDate: Thu Feb 29 18:06:13 2024 +0800

    [KYUUBI #6114] Properly handle 
KyuubiStatement#getMoreResults(CLOSE_CURRENT_RESULT)
    
    # :mag: Description
    ## Issue References ๐Ÿ”—
    
    This pull request fixes #6114
    
    ## Describe Your Solution ๐Ÿ”ง
    
    After fixing [HIVE-7680](https://issues.apache.org/jira/browse/HIVE-7680) 
issue the method getMoreResults() of HiveStatement and respectively 
KyuubiStatementclasses returns false instead of throwing exception. The javadoc 
of the Statement#getMoreResults()method says, that it should implicitly close 
any current ResultSet object, i.e. is similar to calling the 
KyuubiStatement#getMoreResults(int) method with Statement.CLOSE_CURRENT_RESULT 
argument. Therefore, in the latter case, we shoul [...]
    
    ## Types of changes :bookmark:
    
    - [x] Bugfix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
    
    ## Test Plan ๐Ÿงช
    
    #### Behavior Without This Pull Request :coffin:
    
    #### Behavior With This Pull Request :tada:
    
    #### Related Unit Tests
    
    ---
    
    # Checklist ๐Ÿ“
    
    - [x] This patch was not authored or co-authored using [Generative 
Tooling](https://www.apache.org/legal/generative-tooling.html)
    
    **Be nice. Be informative.**
    
    Closes #6115 from tigrulya-exe/bugfix/jdbc-driver-get-more-results.
    
    Closes #6114
    
    b67479166 [Tigran Manasyan] Close result set in case of 
KyuubiStatement#getMoreResults(CLOSE_CURRENT_RESULT)
    eeedaf898 [Tigran Manasyan] Do not throw exception in 
KyuubiStatement#getMoreResults(int) in case of closing current result set
    
    Authored-by: Tigran Manasyan <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../apache/kyuubi/jdbc/hive/KyuubiStatement.java   | 36 +++++++++++++++++-----
 .../kyuubi/jdbc/hive/adapter/SQLStatement.java     |  5 ---
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java
 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java
index 346c8a964..23f0a1f43 100644
--- 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java
+++ 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java
@@ -182,10 +182,7 @@ public class KyuubiStatement implements SQLStatement, 
KyuubiLoggable {
     }
     closeClientOperation();
     client = null;
-    if (resultSet != null) {
-      resultSet.close();
-      resultSet = null;
-    }
+    closeResultSet();
     isClosed = true;
   }
 
@@ -486,7 +483,7 @@ public class KyuubiStatement implements SQLStatement, 
KyuubiLoggable {
   public void executeSetCurrentCatalog(String sql, String catalog) throws 
SQLException {
     if (executeWithConfOverlay(
         sql, Collections.singletonMap("kyuubi.operation.set.current.catalog", 
catalog))) {
-      resultSet.close();
+      closeResultSet();
     }
   }
 
@@ -501,7 +498,7 @@ public class KyuubiStatement implements SQLStatement, 
KyuubiLoggable {
   public void executeSetCurrentDatabase(String sql, String database) throws 
SQLException {
     if (executeWithConfOverlay(
         sql, Collections.singletonMap("kyuubi.operation.set.current.database", 
database))) {
-      resultSet.close();
+      closeResultSet();
     }
   }
 
@@ -543,9 +540,27 @@ public class KyuubiStatement implements SQLStatement, 
KyuubiLoggable {
     return maxRows;
   }
 
+  @Override
+  public boolean getMoreResults(int current) throws SQLException {
+    if (current == Statement.CLOSE_CURRENT_RESULT) {
+      closeResultSet();
+      return false;
+    }
+
+    if (current != KEEP_CURRENT_RESULT && current != CLOSE_ALL_RESULTS) {
+      throw new SQLException("Invalid argument: " + current);
+    }
+
+    throw new SQLFeatureNotSupportedException("Multiple open results not 
supported");
+  }
+
   @Override
   public boolean getMoreResults() throws SQLException {
-    return false;
+    // The javadoc of this method says, that it should implicitly close any 
current
+    // ResultSet object, i.e. is similar to calling the getMoreResults(int)
+    // method with Statement.CLOSE_CURRENT_RESULT argument.
+    // this is an additional enhancement on top of HIVE-7680
+    return getMoreResults(Statement.CLOSE_CURRENT_RESULT);
   }
 
   @Override
@@ -839,4 +854,11 @@ public class KyuubiStatement implements SQLStatement, 
KyuubiLoggable {
       
columnAttributes.add(KyuubiArrowQueryResultSet.getColumnAttributes(primitiveTypeEntry));
     }
   }
+
+  private void closeResultSet() throws SQLException {
+    if (resultSet != null) {
+      resultSet.close();
+      resultSet = null;
+    }
+  }
 }
diff --git 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLStatement.java
 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLStatement.java
index 8ae78bb0b..b9793b038 100644
--- 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLStatement.java
+++ 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLStatement.java
@@ -64,11 +64,6 @@ public interface SQLStatement extends Statement {
     throw new SQLFeatureNotSupportedException("Method not supported");
   }
 
-  @Override
-  default boolean getMoreResults(int current) throws SQLException {
-    throw new SQLFeatureNotSupportedException("Method not supported");
-  }
-
   @Override
   default ResultSet getGeneratedKeys() throws SQLException {
     throw new SQLFeatureNotSupportedException("Method not supported");

Reply via email to