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 e09581387c1..23f0a1f43d7 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 void close() throws SQLException { } closeClientOperation(); client = null; - if (resultSet != null) { - resultSet.close(); - resultSet = null; - } + closeResultSet(); isClosed = true; } @@ -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(); } } @@ -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(); } } @@ -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 @@ -851,4 +854,11 @@ private void parseMetadata( columnAttributes.add(KyuubiArrowQueryResultSet.getColumnAttributes(primitiveTypeEntry)); } } + + private void closeResultSet() throws SQLException { + if (resultSet != null) { + resultSet.close(); + resultSet = null; + } + } }