Skip to content

feat(java/driver/flight-sql): implement Flight SQL session management#4444

Open
unikdahal wants to merge 2 commits into
apache:mainfrom
unikdahal:main
Open

feat(java/driver/flight-sql): implement Flight SQL session management#4444
unikdahal wants to merge 2 commits into
apache:mainfrom
unikdahal:main

Conversation

@unikdahal

@unikdahal unikdahal commented Jun 26, 2026

Copy link
Copy Markdown

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 for
session option key prefixes:

  • adbc.flight.sql.session.option. (string/long/double)
  • adbc.flight.sql.session.optionbool. (boolean)
  • adbc.flight.sql.session.optionstringlist. (String[]; JSON string
    also 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 — adds setSessionOptions,
getSessionOptions, and closeSession delegation methods following the
existing combine(callOptions) pattern.

FlightSqlConnection — overrides getOption/setOption for all
session prefixes with typed dispatch via TypedKey<T>:

  • null value rejected early with INVALID_ARGUMENT
  • Empty option name caught before the RPC with INVALID_ARGUMENT
  • Long/Double parse errors wrapped in AdbcException instead of
    leaking NumberFormatException
  • close() sends CloseSession best-effort; catches only
    FlightRuntimeException so InterruptedException is never swallowed

FlightSqlSessionUtil (new class) — package-private utility
holding all JSON helpers and typed SessionOptionValue visitors,
extracted from FlightSqlConnection to keep the connection class
focused on the ADBC surface:

  • escapeJson covers the full U+0000–U+001F control-character range
  • parseJsonArray handles \uXXXX, \b, \f, and all JSON
    whitespace (not just ASCII space)
  • JSON_VALUE_VISITOR emits "null" for NaN/Infinity doubles to
    produce valid RFC 8259 output

FlightSqlSessionTest (new tests) — 8 unit tests using an
in-process FlightSqlProducer with real in-memory session state,
covering: string/bool/string-list set+get, erase, the full
SESSION_OPTIONS JSON blob, CloseSession called on close(),
read-only blob rejection, and graceful close when server returns
produce valid RFC 8259 output

FlightSqlSessionTest (new tests) — 8 unit tests using an
in-process FlightSqlProducer with real in-memory session state,
covering: string/bool/string-list set+get, erase, the full
SESSION_OPTIONS JSON blob, CloseSession called on close(),
read-only blob rejection, and graceful close when server returns
UNIMPLEMENTED.

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>
@unikdahal unikdahal requested a review from lidavidm as a code owner June 26, 2026 21:53
@unikdahal unikdahal changed the title feat(java/driver/flight-sql): implement Flight SQL session management (#4443) feat(java/driver/flight-sql): implement Flight SQL session management Jun 26, 2026
@lidavidm lidavidm requested a review from Copilot June 28, 2026 22:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/setOption handling for session option prefixes (including erase and read-only blob).
  • Add setSessionOptions / getSessionOptions / closeSession delegations to FlightSqlClientWithCallOptions and invoke CloseSession on connection close.
  • Introduce FlightSqlSessionUtil plus a new FlightSqlSessionTest covering 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather we use a real JSON library.

@unikdahal unikdahal Jun 29, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrow-java itself uses Jackson, so I think it'd be best to align with that.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lidavidm i have updated the MR with jackson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java] Does ADBC ​​FlightSqlConnection support Arrow Flight session management?

3 participants