Skip to content

Fix parsing columns that omit the type before DEFAULT, MATERIALIZED or ALIAS - #339

Merged
git-hulk merged 1 commit into
AfterShip:masterfrom
youdie006:column-value-without-type
Nov 2, 2026
Merged

git-hulk merged 1 commit into
AfterShip:masterfrom
youdie006:column-value-without-type

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

#338 stopped COMMENT, CODEC and TTL from being read as a type name when a column's type is omitted. The same guard in parseTableColumnExpr doesn't skip DEFAULT, MATERIALIZED and ALIAS, which are handled a few lines below it, so a column that omits its type before one of them either fails to parse or is misparsed. ClickHouse allows this: "The column type of a default value column can be omitted in which case it is inferred from expr's type", e.g. EventDate DEFAULT toDate(EventTime) (CREATE TABLE, default values).

CREATE TABLE t (ts DateTime, d DEFAULT ts + 1) ENGINE = MergeTree ORDER BY ts
  before: line 1:40 expected ')', but got '<ident>'
  after:  column d: Type="" DefaultExpr="ts + 1"
ALTER TABLE t MODIFY COLUMN m MATERIALIZED toDate(ts)
  before: line 1:44 <EOF> or ';' was expected, but got: "toDate"
  after:  column m: Type="" MaterializedExpr="toDate(ts)"
ALTER TABLE t ADD COLUMN a ALIAS ts
  before: line 1:34 <EOF> or ';' was expected, but got: "ts"
  after:  column a: Type="" AliasExpr="ts"
ALTER TABLE t MODIFY COLUMN d DEFAULT (1)
  before: column d: Type="DEFAULT(1)" DefaultExpr=""
  after:  column d: Type="" DefaultExpr="(1)"

This adds the three keywords to that guard. All three statements (CREATE, ADD COLUMN, MODIFY COLUMN) go through parseTableColumnExpr. TestParser_ColumnValueExprWithoutType covers each keyword in each statement, including Date DEFAULT today() and Nullable(String) ALIAS 'x', where the type must still be parsed. It also checks that DEFAULT, MATERIALIZED or ALIAS without an expression is an error; those used to parse as a type name, and the docs say a type is required when the expression is left out. New fixture parser/testdata/ddl/column_value_without_type.sql, with goldens regenerated by -update; no other golden changed.

clickhouse-local was not available here, so the syntax is checked against the docs above rather than the engine. go test -v ./... -covermode=atomic -race -compatible (as make test) passes and gofmt is clean; I couldn't run make lint, since golangci-lint v1.53.3 isn't installed.

Written with AI assistance (Claude); I have reviewed the change.

@git-hulk

git-hulk commented Nov 2, 2026

Copy link
Copy Markdown
Member

@youdie006 Thanks for your improvement.

@git-hulk
git-hulk merged commit 5de9b3c into AfterShip:master Nov 2, 2026
1 of 2 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