Skip to content

Commit

Permalink
Close result set in case of KyuubiStatement#getMoreResults(CLOSE_CURR…
Browse files Browse the repository at this point in the history
…ENT_RESULT)
  • Loading branch information
tigrulya-exe committed Feb 29, 2024
1 parent eeedaf8 commit b674791
Showing 1 changed file with 22 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 @@ -545,19 +542,25 @@ public int getMaxRows() throws SQLException {

@Override
public boolean getMoreResults(int current) throws SQLException {
// getMoreResults() javadoc says, that it should implicitly close
// any current ResultSet object, so here in case of Statement.CLOSE_CURRENT_RESULT
// we can implement the same logic
// see also https://issues.apache.org/jira/browse/HIVE-7680
if (current == Statement.CLOSE_CURRENT_RESULT) {
closeResultSet();
return false;
}
throw new SQLFeatureNotSupportedException("Method not supported");

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 @@ -851,4 +854,11 @@ private void parseMetadata(
columnAttributes.add(KyuubiArrowQueryResultSet.getColumnAttributes(primitiveTypeEntry));
}
}

private void closeResultSet() throws SQLException {
if (resultSet != null) {
resultSet.close();
resultSet = null;
}
}
}

0 comments on commit b674791

Please sign in to comment.