You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proactive server-side statement close when results consumed (#1444)
## Summary
Proactively closes the server-side operation when all results have been
consumed or the ResultSet is explicitly closed, while keeping the
client-side Statement open for reuse. This reduces server resource usage
and warehouse cost for slow consumers who don't explicitly close
statements.
### When server operation is closed:
1. `next()` returns false — all rows consumed
2. `ResultSet.close()` called explicitly
### What stays open:
- Client-side Statement — fully reusable for re-execution
- `Statement.close()` becomes a no-op for the server RPC (operation
already closed), just cleans up client state
### New flag: `serverOperationClosed`
- Set after proactive `closeStatement` RPC
- Prevents duplicate RPCs when `Statement.close()` is called later
- Reset on re-execution (`resetForNewExecution()`)
- Skipped when `directResultsReceived` is already true (server already
closed)
- Best-effort: server errors during proactive close are swallowed
(logged at DEBUG)
## Test plan
- [x] `testCloseServerOperation_closesServerAndSkipsRpcOnStatementClose`
— proactive close sends RPC, Statement.close() skips it
- [x] `testCloseServerOperation_idempotent` — double call sends only one
RPC
- [x] `testCloseServerOperation_skippedForDirectResults` — no-op when
server already closed
- [x] `testCloseServerOperation_skippedWhenNoStatementId` — no-op when
no statement ID
- [x] `testCloseServerOperation_resetsAfterFlagClear` — flag prevents
all subsequent RPCs
- [x] `testCloseServerOperation_errorSwallowed` — server errors don't
propagate
- [x] Full suite: 193 tests pass (DatabricksStatementTest +
DatabricksResultSetTest + DatabricksConnectionTest)
This pull request was AI-assisted by Isaac.
---------
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
Copy file name to clipboardExpand all lines: NEXT_CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ upgrading. These changes do not affect metadata on All-Purpose Clusters.
43
43
-`EnableGeoSpatialSupport` no longer requires `EnableComplexDatatypeSupport=1`. Geospatial types (GEOMETRY, GEOGRAPHY) can now be enabled independently of complex type support (ARRAY, MAP, STRUCT).
44
44
- Arrow schema deserialization failures (Thrift metadata path) now surface a dedicated driver error code `ARROW_SCHEMA_PARSING_ERROR` (vendor code `22000`) and a proper SQLSTATE `22000` (Data Exception) on the thrown `SQLException`, instead of the generic `RESULT_SET_ERROR` (1004) and the enum name as SQLSTATE. The exception message is unchanged.
45
45
- When a Statement is re-executed, the previous server-side operation is now explicitly closed before starting the new execution, preventing orphaned server-side operations when Statements are reused.
46
+
- Server-side operations are now closed proactively when `ResultSet.close()` is called, improving resource utilization. The client-side Statement remains open and reusable for re-execution. As a result, `getExecutionResult()` after result consumption returns the cached ResultSet instead of making a server RPC.
46
47
47
48
### Fixed
48
49
- Fixed `DatabaseMetaData.getTables()` in Thrift mode returning rows when called with an empty `types` array. Per JDBC spec, empty types means "no types selected" and now correctly returns zero rows (matching SEA mode).
0 commit comments