Skip to content

fix: serialize AST join, sample and interleave helpers - #2753

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
fudianchn:fix/ast-helper-serialization
Oct 2, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
fudianchn:fix/ast-helper-serialization

Conversation

@fudianchn

Copy link
Copy Markdown
Contributor

AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.

What

Make JoinHint, SampleClause and SpannerInterleaveIn serializable so ASTs containing these helpers can be copied with Java object streams.

Why

Serializing a parsed SELECT with a join hint or sampling clause, or a CREATE TABLE with Spanner interleaving, currently throws NotSerializableException. Ordinary SELECT and CREATE TABLE ASTs serialize successfully.

How

  1. Add Serializable to the three helper classes, following the existing helper-model convention.
  2. Extend SerializationTest with parsed-SQL object-stream round trips and assertions for helper fields, adjacent AST fields and copy independence.

Root cause

Join and sampling owners inherit serializability through ASTNodeAccessImpl; CreateTable implements Statement, whose Model parent is serializable. Their non-transient helper fields refer to three classes that do not implement Serializable, breaking those object graphs.

Testing

  • SerializationTest has 25 cases: on base bb55bb9d, 22 fail with the scoped NotSerializableException and three normal controls pass; the fix passes all 25. Tests cover SQL Server/Doris hint positions, sampling enum/value/flag fields, Table/ParenthesedSelect/ParenthesedFromItem/MatchRecognize sampling owners, Spanner delete actions and deep-copy independence after AST mutation.
  • Deleting the JoinHint or SpannerInterleaveIn marker rejects seven or three cases in the original 24-case matrix. Deleting the SampleClause marker rejects 13 cases in the final 25-case matrix. All normal controls pass in every mutation run.
  • JDK 17: the serialization and adjacent hint/sampling test classes pass, 53 cases total. Full Gradle check passes with 9,426 cases, zero failures/errors and 25 skipped; Maven clean verify spotless:check passes with 9,408 cases, zero failures/errors and 25 skipped. Formatting, Checkstyle, PMD, SpotBugs, grammar ambiguity, applicable coverage and strict changed-file license checks pass.
  • Project JMH parseSQLStatements, unchanged 54-statement corpus, version=latest: interleaved states, three forks per state, two one-second warmups and five one-second measurements per fork; 15 samples per state. Baseline 28.608 ms/op, 99.9% CI [21.591,35.624]; fixed 29.062 ms/op, CI [22.203,35.920]. The intervals overlap; no measurable regression in this benchmark. The generated parser bytecode is identical to the baseline; this parsing benchmark does not measure Java serialization throughput. No Windows/macOS local matrix or historical serialized-byte compatibility test was run.

Behavior notes

  • Helper fields, constructors, getters, rendering and grammar are unchanged. Serialization retains all helper fields; no fields are made transient.
  • Follow the existing AST-helper convention of a default computed serialization UID. This does not establish compatibility with older serialized data or user-defined serializable subclasses.
  • This change covers the three named helpers. Exception token graphs and other helper models are outside its scope.

Verification of the original issue

No existing issue is linked. The failures were reproduced on upstream master bb55bb9de8377de9880b14e4fe3b3cc94bf63498; the fixed commit is 3e220711767d6b71574a87bd7786225b6f925da9. This follows the model-serialization contract discussed in #2144, which fixed WithItem and invited additional model fixes.

SELECT a.id FROM a INNER LOOP JOIN b ON a.id = b.id;
SELECT id FROM events TABLESAMPLE SYSTEM (10.5 PERCENT) REPEATABLE (7) WHERE id > 0;
CREATE TABLE child (id INT) PRIMARY KEY (id), INTERLEAVE IN PARENT parent ON DELETE CASCADE;

Each parsed AST fails serialization on the base commit and completes an ObjectOutputStream/ObjectInputStream round trip with the fix. The tests also assert helper values and neighboring AST fields.

Signed-off-by: 付典 <fudianchn@gmail.com>
@fudianchn
fudianchn marked this pull request as ready for review October 2, 2026 07:26
@manticore-projects
manticore-projects merged commit 26d3e02 into JSQLParser:master Oct 2, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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.

2 participants