Skip to content

Align DDL traversal and validation with active AST definitions - #2778

Open
minleejae wants to merge 3 commits into
JSQLParser:masterfrom
minleejae:refactor/ddl-active-traversal-20261011
Open

minleejae wants to merge 3 commits into
JSQLParser:masterfrom
minleejae:refactor/ddl-active-traversal-20261011

Conversation

@minleejae

@minleejae minleejae commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Make table discovery and metadata validation follow the DDL body actually rendered after AST mutation. For example, adding a column to an ALTER action that still stores an earlier foreign key renders ADD added INT, but currently table discovery and validation still use the inactive foreign table and key columns.

Current design (As-is)

Rendering selects one body, while traversal and metadata validation independently visit stored definitions, defaults and column options. This leaks inactive state into consumers. A CHECK option changed to FOREIGN_OPTIONS can also retain its old constraint node and incorrectly traverse that expression.

Target design (To-be)

  • Share active-definition selection through getActiveTableDefinition() and the body-selection hooks introduced in Fix ALTER deparser dispatch for inactive column metadata #2770.
  • Traverse active defaults, columns, constraints and indexes, while preserving the expression/table children of specialized ALTER bodies.
  • Validate only the selected structured definitions and key columns. Keep stored metadata accessible through existing getters.
  • Respect the active ColumnOption.Kind, partial legacy constraint headers, identity actions and dedicated primary-key/partition/relation bodies.
  • Document the stored-versus-active distinction and dispatch hooks for custom subclasses.

This refactoring changes consumer behavior after AST mutation; it adds no SQL syntax or database validity rules.

Dependency

Depends on #2770 and includes its commits until that PR is merged. The additional changes can be reviewed in the stack-only comparison. The base remains upstream master so this PR is available for upstream review.

Validation

  • Regression tests compare rendered SQL, custom traversal callbacks, table-name discovery and metadata validation after mutations. Active foreign keys and specialized bodies retain their required children; inactive definitions stay accessible without being visited.
  • Java 17 offline Gradle spotlessApply check: 10,077 tests, 10,052 passed, 25 skipped, zero failures/errors. Grammar, Checkstyle, PMD, SpotBugs and coverage checks pass.
  • Default PMD comparison: existing findings decrease from 13 to 8, with no new findings or suppression/threshold changes.

Integration validation

Applied #2770, #2771 and all four follow-ups (#2775–#2778) together on master (066f581e), resolving overlapping validator edits while preserving their respective behavior. The integrated build passes Java 17 offline Gradle spotlessApply check: 10,141 tests, 10,116 passed, 25 skipped, zero failures/errors. The combined ALTER validator has zero findings under the default PMD complexity and field-placement rules.

Replayed 882 previously DB-validated MySQL/PostgreSQL DDL fixtures: 875 pass and the same seven existing parse gaps remain. SQL output, reparsing and AST node-type sets match the preceding integration baseline, with no new differences. This replay did not rerun the databases.

The published head passes grammar checks, Gradle and Maven on Ubuntu/Windows/macOS, and Codacy. Deployment-only jobs are skipped as expected for a PR.

Signed-off-by: minleejae <mmj9808@gmail.com>
Signed-off-by: minleejae <mmj9808@gmail.com>
Signed-off-by: minleejae <mmj9808@gmail.com>

This branch has not been deployed

No deployments
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.

1 participant