Skip to content

Commit

Permalink
[KYUUBI #6114] Properly handle KyuubiStatement#getMoreResults(CLOSE_C…
Browse files Browse the repository at this point in the history
…URRENT_RESULT)

# 🔍 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 should also return false instead of failing with an exception. This fix also allows Kyuubi JDBC driver to be used in the JDBC engine.

## Types of changes 🔖

- [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 ⚰️

#### Behavior With This Pull Request 🎉

#### 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

b674791 [Tigran Manasyan] Close result set in case of KyuubiStatement#getMoreResults(CLOSE_CURRENT_RESULT)
eeedaf8 [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]>
(cherry picked from commit abb782c)
Signed-off-by: Cheng Pan <[email protected]>
  • Loading branch information
tigrulya-exe authored and pan3793 committed Feb 29, 2024
1 parent cae5fbb commit 0501d7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ public void close() throws SQLException {
}
closeClientOperation();
client = null;
if (resultSet != null) {
resultSet.close();
resultSet = null;
}
closeResultSet();
isClosed = true;
}

Expand Down Expand Up @@ -486,7 +483,7 @@ public ResultSet executePython(String code) throws SQLException {
public void executeSetCurrentCatalog(String sql, String catalog) throws SQLException {
if (executeWithConfOverlay(
sql, Collections.singletonMap("kyuubi.operation.set.current.catalog", catalog))) {
resultSet.close();
closeResultSet();
}
}

Expand All @@ -501,7 +498,7 @@ public ResultSet executeGetCurrentCatalog(String sql) throws SQLException {
public void executeSetCurrentDatabase(String sql, String database) throws SQLException {
if (executeWithConfOverlay(
sql, Collections.singletonMap("kyuubi.operation.set.current.database", database))) {
resultSet.close();
closeResultSet();
}
}

Expand Down Expand Up @@ -543,9 +540,27 @@ public int getMaxRows() throws SQLException {
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
Expand Down Expand Up @@ -839,4 +854,11 @@ private void parseMetadata(
columnAttributes.add(KyuubiArrowQueryResultSet.getColumnAttributes(primitiveTypeEntry));
}
}

private void closeResultSet() throws SQLException {
if (resultSet != null) {
resultSet.close();
resultSet = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ default int[] executeBatch() throws SQLException {
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");
Expand Down

0 comments on commit 0501d7f

Please sign in to comment.