Skip to content

Render JSON children through the configured expression deparser - #2767

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:refactor/json-expression-rendering-20261011
Oct 11, 2026
Merged

manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:refactor/json-expression-rendering-20261011

Conversation

@minleejae

@minleejae minleejae commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Allow a custom ExpressionDeParser to rewrite structured expressions inside scalar JSON functions and JSON_TABLE. For example, rewriting a referenced column should also work inside a generated column's JSON_VALUE input and inside JSON_TABLE paths, PASSING values and DEFAULT expressions.

Current design (As-is)

The JSON deparser visits append the node's string representation, while the JSON renderers append child expressions directly. This bypasses the caller's expression visitor and makes JSON output behave differently from expressions rendered through that visitor.

Target design (To-be)

  • Share rendering through appendTo(StringBuilder, Consumer<Expression>), with consumer overloads for scalar JSON function variants. Default string output and visitor output use the same clause ordering and formatting.
  • Route structured inputs, paths, PASSING values, defaults, JSON object expression keys/values and expression-valued plan terms through the supplied printer. Recurse into nested JSON_TABLE columns and plans while preserving identifier-valued plan terms and opaque values.
  • Keep column type/PATH options and function input/PASSING clauses in focused rendering helpers.
  • Pass the incoming visitor context through the JSON callback. Keep raw query-path strings opaque, and preserve existing null rendering for incomplete builders and mutable lists.
  • Document direct printer usage, connected select deparsers for subqueries and the subclass migration. Custom subclasses should override the consumer overloads or appendTo; legacy type-specific one-argument append* overrides and concrete JSON_TABLE column toString() overrides no longer control the shared rendering path.

This covers JsonFunction and JsonTableFunction; JSON aggregate and XML table renderers are unchanged. No SQL grammar changes or AST mutation are required for a custom deparser rewrite.

Validation

  • Java 17, offline Gradle spotlessApply check: 9,967 tests, 9,942 passed, 25 skipped, zero failures/errors. Grammar, formatting, Checkstyle, PMD, SpotBugs and coverage checks pass.
  • The Codacy NPathComplexity rule (threshold 200) reports zero violations after extracting clause helpers; the previous revision reproduced both reported violations locally. No analyzer thresholds or suppressions were added.
  • Fifteen new regression cases cover scalar JSON variants, MySQL generated columns, JSON_TABLE defaults/passing/nested paths, plan terms, connected scalar subqueries, opaque values, null builders, custom subclass hooks and rendering/reparsing without AST mutation.
  • Built independently on current master (cdbaf1ad). No fresh live database execution was performed for this rendering refactor.
  • Integration check with the other independent refactors (Use one foreign-key state in ALTER TABLE #2764–Expose editable ALTER column identity actions #2768), using this branch at 1e02ab36 before the internal helper extraction: all five patches apply without conflicts; full Java 17 Gradle check passes with 10,030 tests (10,005 passed, 25 skipped). Replaying 882 previously DB-validated fixtures preserves the AST and both SQL outputs for 875 supported cases, with the same seven existing parse gaps and no semantic regression. No fresh database execution.
  • Remote Codacy reanalysis of c2b441d6 passes with zero issues; the grammar check and Gradle/Maven checks on Ubuntu, Windows and macOS also pass (all eight checks successful).

Share callback-based rendering for JSON functions and JSON_TABLE so custom deparsers can rewrite structured inputs, paths, defaults, passing values, and plan expressions. Preserve opaque and incomplete-builder output, and document the rendering hooks for subclasses.

Signed-off-by: minleejae <mmj9808@gmail.com>
Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit 6be0452 into JSQLParser:master Oct 11, 2026
10 checks passed
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