feat(java/driver/flight-sql): implement Flight SQL session management#4444
feat(java/driver/flight-sql): implement Flight SQL session management#4444unikdahal wants to merge 2 commits into
Conversation
Wires Flight SQL session options and CloseSession into the Java ADBC driver, bringing it to parity with the Go/Python drivers. What changed: FlightSqlConnectionProperties — five new string constants for session option key prefixes (adbc.flight.sql.session.option., adbc.flight.sql.session.optionbool., adbc.flight.sql.session.optionstringlist., adbc.flight.sql.session.optionerase., and the read-only adbc.flight.sql.session.options JSON blob key). FlightSqlClientWithCallOptions — three new delegation methods: setSessionOptions, getSessionOptions, closeSession, all forwarding connectionOptions via the existing combine() pattern. FlightSqlConnection — overrides getOption/setOption on AdbcConnection for all session key prefixes; each typed prefix (string, bool, stringlist, long, double) dispatches to the appropriate SessionOptionValue via a visitor. setOption null value is rejected early with INVALID_ARGUMENT. The erase prefix calls makeEmptySessionOptionValue. close() now sends CloseSession best-effort, catching only FlightRuntimeException so InterruptedException is not swallowed. FlightSqlSessionUtil — new package-private class holding all JSON helpers (sessionOptionsToJson, toJsonArray, parseJsonArray, escapeJson) and the six typed SessionOptionValue visitors. Extracted from FlightSqlConnection to keep that class focused on the ADBC surface. escapeJson handles the full U+0000-U+001F control-character range. parseJsonArray handles \uXXXX, \b, \f and all JSON whitespace. JSON_VALUE_VISITOR emits "null" for NaN/Infinity doubles to produce valid RFC 8259 output. FlightSqlSessionTest — new unit tests covering set/get for string, bool, and string-list option types, erase, the full SESSION_OPTIONS JSON blob, CloseSession being called on close(), read-only blob rejection, and close() not throwing when the server returns UNIMPLEMENTED. Relates to apache#745. Closes apache#4443. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Implements Flight SQL session management in the Java ADBC Flight SQL driver by wiring Arrow Flight SQL session APIs into FlightSqlConnection, adding a small utility for (de)serialization/type conversions, and introducing unit tests to validate session option behavior.
Changes:
- Add session option key constants and implement
getOption/setOptionhandling for session option prefixes (including erase and read-only blob). - Add
setSessionOptions/getSessionOptions/closeSessiondelegations toFlightSqlClientWithCallOptionsand invokeCloseSessionon connection close. - Introduce
FlightSqlSessionUtilplus a newFlightSqlSessionTestcovering basic set/get/erase and close-session behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| java/driver/flight-sql/src/test/java/org/apache/arrow/adbc/driver/flightsql/FlightSqlSessionTest.java | Adds in-process unit tests for session option set/get/erase and CloseSession-on-close. |
| java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/FlightSqlSessionUtil.java | New package-private helpers for JSON serialization/parsing and SessionOptionValue conversions. |
| java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/FlightSqlConnectionProperties.java | Introduces constants for session option prefixes and the session options JSON blob key. |
| java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/FlightSqlConnection.java | Implements session option handling via TypedKey<T> and best-effort CloseSession invocation. |
| java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/FlightSqlClientWithCallOptions.java | Exposes session APIs while preserving the existing call-option combining pattern. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
I think I'd rather we use a real JSON library.
There was a problem hiding this comment.
This was the point i was confused with whether to add a new json library dependency or not as we don't have an existing dependency. Do we have any preferred library for JSON will add it and refactor. @lidavidm
There was a problem hiding this comment.
arrow-java itself uses Jackson, so I think it'd be best to align with that.
Summary
Implements Flight SQL session management in the Java ADBC driver,
bringing parity with the Go/Python drivers. Relates to #745. Closes
#4443. Closes #2821.
Changes
FlightSqlConnectionProperties— adds five string constants forsession option key prefixes:
adbc.flight.sql.session.option.(string/long/double)adbc.flight.sql.session.optionbool.(boolean)adbc.flight.sql.session.optionstringlist.(String[]; JSON stringalso accepted for cross-language compat)
adbc.flight.sql.session.optionerase.(erase an option)adbc.flight.sql.session.options(read-only JSON blob of all options)FlightSqlClientWithCallOptions— addssetSessionOptions,getSessionOptions, andcloseSessiondelegation methods following theexisting
combine(callOptions)pattern.FlightSqlConnection— overridesgetOption/setOptionfor allsession prefixes with typed dispatch via
TypedKey<T>:nullvalue rejected early withINVALID_ARGUMENTINVALID_ARGUMENTLong/Doubleparse errors wrapped inAdbcExceptioninstead ofleaking
NumberFormatExceptionclose()sendsCloseSessionbest-effort; catches onlyFlightRuntimeExceptionsoInterruptedExceptionis never swallowedFlightSqlSessionUtil(new class) — package-private utilityholding all JSON helpers and typed
SessionOptionValuevisitors,extracted from
FlightSqlConnectionto keep the connection classfocused on the ADBC surface:
escapeJsoncovers the full U+0000–U+001F control-character rangeparseJsonArrayhandles\uXXXX,\b,\f, and all JSONwhitespace (not just ASCII space)
JSON_VALUE_VISITORemits"null"forNaN/Infinitydoubles toproduce valid RFC 8259 output
FlightSqlSessionTest(new tests) — 8 unit tests using anin-process
FlightSqlProducerwith real in-memory session state,covering: string/bool/string-list set+get, erase, the full
SESSION_OPTIONSJSON blob,CloseSessioncalled onclose(),read-only blob rejection, and graceful close when server returns
produce valid RFC 8259 output
FlightSqlSessionTest(new tests) — 8 unit tests using anin-process
FlightSqlProducerwith real in-memory session state,covering: string/bool/string-list set+get, erase, the full
SESSION_OPTIONSJSON blob,CloseSessioncalled onclose(),read-only blob rejection, and graceful close when server returns
UNIMPLEMENTED.