Skip to content

Allow COMMENT, CODEC and TTL in any order - #337

Merged
git-hulk merged 1 commit into
AfterShip:masterfrom
sharadgaur:sharad/column-modifier-order
Oct 28, 2026
Merged

git-hulk merged 1 commit into
AfterShip:masterfrom
sharadgaur:sharad/column-modifier-order

Conversation

@sharadgaur

Copy link
Copy Markdown
Contributor

Summary

Allow the existing COMMENT, CODEC and TTL column modifiers in any order in CREATE TABLE, ALTER ADD COLUMN and ALTER MODIFY COLUMN.

The parser currently expects COMMENT before CODEC, but the formatter writes CODEC before COMMENT. A definition with both modifiers can parse successfully and then fail when its formatted output is parsed again.

CREATE TABLE db.example (
    event_time DateTime,
    value String CODEC(ZSTD(1)) COMMENT 'example'
) ENGINE = MergeTree ORDER BY event_time;
  • Reuse the existing modifier parsers in a trailing-modifier loop.
  • Reject duplicate COMMENT, CODEC and TTL clauses.
  • Format in canonical COMMENT, CODEC, TTL order.
  • Keep existing AST types and the preceding default/materialized/alias parsing unchanged.

Verification

  • Full make test passes with Go 1.21.13 and Go 1.25.1, including race and compatibility tests. Go 1.21 used external linking for the local macOS linker requirement.
  • Grouped tests cover all six modifier permutations across CREATE, ADD and MODIFY, mixed keyword casing, source end positions, compact/beautified round trips, duplicates and malformed clauses.
  • Added generic SQL fixtures and regenerated AST/format goldens.
  • make lint passes with golangci-lint 1.64.5. The CI-pinned 1.53.3 binary was not used locally.
  • Full vet reports the existing Formatter.WriteByte signature warning, also reproduced on clean master. Other vet analyzers pass.

ClickHouse 26.8's column parser accepts these trailing modifiers in any order and rejects duplicates. Its formatter uses COMMENT, CODEC, TTL order.

Canonical output was also accepted by the available native ClickHouse 26.2.1.1089 formatter. Noncanonical input ordering was checked against the 26.8 source, not a running 26.8 binary; the older binary rejects that input ordering.

@git-hulk
git-hulk merged commit c5ff094 into AfterShip:master Oct 28, 2026
2 checks passed
git-hulk added a commit to git-hulk/clickhouse-sql-parser that referenced this pull request Oct 28, 2026
ALTER TABLE ... MODIFY COLUMN can reject valid modifier-only changes or
store a modifier as the column type. Modifier keywords are treated as
type names when the declaration omits its data type.

For example, CODEC(LZ4) is stored in Column.Type instead of Column.Codec,
while a leading COMMENT causes parsing to fail. This bug predates AfterShip#337.

Recognize COMMENT, CODEC and TTL as modifiers when the type is omitted,
preserving their AST fields through formatting and reparsing. Preserve
explicit-type parsing and duplicate-modifier rejection, and regenerate
the AST and formatting fixtures for the affected ALTER statements.

Assistant-By GPT-6
git-hulk added a commit that referenced this pull request Oct 28, 2026
ALTER TABLE ... MODIFY COLUMN can reject valid modifier-only changes or
store a modifier as the column type. Modifier keywords are treated as
type names when the declaration omits its data type.

For example, CODEC(LZ4) is stored in Column.Type instead of Column.Codec,
while a leading COMMENT causes parsing to fail. This bug predates #337.

Recognize COMMENT, CODEC and TTL as modifiers when the type is omitted,
preserving their AST fields through formatting and reparsing. Preserve
explicit-type parsing and duplicate-modifier rejection, and regenerate
the AST and formatting fixtures for the affected ALTER statements.

Assistant-By GPT-6
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