Skip to content

feat: structure column attributes and generated expressions - #2641

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/structured-column-attributes
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/structured-column-attributes

Conversation

@minleejae

@minleejae minleejae commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Column definitions currently retain many attributes as raw strings. For example, ON UPDATE CURRENT_TIMESTAMP(6) is split into tokens and a generated column's expression cannot be visited or rewritten. Extend the existing ColumnOption model to preserve these attributes in CREATE and ALTER column definitions.

This adds structured nullability, collation, comment literals, ON UPDATE expressions, AUTO_INCREMENT, visibility and inline PRIMARY KEY. GeneratedColumnDefinition preserves the expression, optional GENERATED ALWAYS prefix and explicit STORED/VIRTUAL choice; existing identity declarations keep their own model. Shared table-definition traversal and rendering now expose the new expressions to visitors, validators and custom deparsers.

Charset remains on ColDataType, while column COLLATE is a ColumnOption; consumers can read both directly. Unknown extensions retain their raw fallback and source order. The legacy getColumnSpecs() supplies a snapshot for structured options, with canonical keyword capitalization and expression fragments rendered as one token. setColumnSpecs() still explicitly replaces structured options; addColumnSpecs() preserves them. Existing tests that asserted the old raw-only representation were updated, with raw-setter coverage retained.

Validation

  • Merged locally with fix: preserve PostgreSQL quoted names, numeric scales and comment literals #2638, feat: support additional PostgreSQL COMMENT targets #2639 and feat: preserve DROP INDEX owner tables in the AST #2640 without conflicts: 7,126 Gradle tests, zero failures/errors, 25 skipped; the grammar ambiguity check passed. All 193 new audit cases produced identical parser/rendering results in the combined build.

  • Full Gradle check, including the JavaCC ambiguity gate, formatting, Checkstyle, PMD and SpotBugs: 6,946 tests, zero failures/errors, 25 skipped. Spotless ratchet pinned to base 6312f9e5.

  • EXPORT_TEST_TO_FILE=False mvn -B clean verify: 6,928 tests, zero failures/errors, 25 skipped.

  • Database differential audit: 132 valid MySQL 8.4.11 cases and 20 valid PostgreSQL 18.6 cases produced identical column metadata from original and regenerated SQL; five malformed definitions were rejected. Checks cover CREATE/ADD/MODIFY/CHANGE, charset/collation, stored comments, ON UPDATE and generated-column expressions/storage.

  • Regression tests check AST payloads after both rendering paths, expression visitors, validation, mutations, identity/reference/default boundaries and legacy token behavior.

No server defaults or expression-validity rules are inferred. SQL Server's unparenthesized computed-column forms, complete column-constraint modeling and semantic literal decoding remain outside this change. This enriches the existing AST independently of the querying API discussed in #2620.

Syntax references: MySQL column definitions, MySQL generated columns, MySQL automatic timestamp updating, PostgreSQL column definitions.

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