Skip to content

Reject data type names starting with a digit - #109511

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-datatype-numeric-name-roundtrip-109501
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-datatype-numeric-name-roundtrip-109501

Conversation

@groeneai

@groeneai groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix an Inconsistent AST formatting logical error (server abort in debug/sanitizer builds) when a back-quoted data type name starts with a digit, e.g. Nullable(`255`). Such a name is now rejected at parse time.

Description

Closes: #109501

Found by the AST fuzzer (STID 1941-1bfa). A back-quoted type name whose first character is a digit (e.g. Nullable(`255`)) is printed unquoted by the formatter (Nullable(255)). The unquoted name then re-lexes as a number literal (ASTLiteral) instead of a type name (ASTDataType), so the format-parse-format AST round-trip check in executeQuery diverges and aborts debug/sanitizer builds with an Inconsistent AST formatting logical error.

Minimal reproducer:

CREATE TABLE t (`x` Nullable(`255`)) ENGINE = Memory;

Root cause: ParserDataType accepted any word-char string as a type name, including all-digit names. ASTDataType::formatImpl prints the name unquoted, so a digit-leading name does not survive the round trip. Real data type names never start with a digit, so this rejects them at parse time (returning a normal SYNTAX_ERROR), alongside the existing rejection of non-word-char names (`x.y`, `Null`).

Regression test added to 03210_inconsistent_formatting_of_data_types (the canonical test for this STID family).

CI report of the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109288&sha=749cbb09b5f36bf574dce5707ca1e496db0840bd&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29

@groeneai

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE t (\x` Nullable(`255`)) ENGINE = Memoryaborts a debug build 100% of the time with theInconsistent AST formatting` LOGICAL_ERROR (verified on server, buildId 366A6BB9...).
b Root cause explained? ParserDataType accepts any word-char string as a type name, including all-digit ones, building ASTDataType("255"). ASTDataType::formatImpl prints the name unquoted → 255. Re-lexing 255 yields a Number token, so the reparsed AST holds ASTLiteral(UInt64, 255) instead of ASTDataType("255"). The tree hashes differ → executeQuery's round-trip check throws LOGICAL_ERROR.
c Fix matches root cause? Yes. Reject a type name whose first char is a digit at parse time — exactly the names that cannot survive the unquoted round trip. Sits beside the existing rejections of non-word-char names (\x.y`, `Null``).
d Test intent preserved / new tests added? Yes. Added two cases (minimal Nullable(\255`)and the fullmultiIf(...)shape) to03210_inconsistent_formatting_of_data_types` — the canonical regression test for this STID family. No existing assertions weakened.
e Both directions demonstrated? Yes. Pre-fix binary: LOGICAL_ERROR / server abort. Post-fix binary (buildId 0019120F...): clean SYNTAX_ERROR (Expected type name); valid types (UInt64, Nullable(String), Array, Tuple, Decimal, FixedString) unaffected; 03210 passes.
f Fix is general across code paths? Yes. The guard is in the single ParserDataType::parseImpl type-name gate, which every data type (nested or top-level) flows through. No sibling parser duplicates this logic.
g Fix generalizes across inputs? Yes. The reject is on the type NAME, independent of wrapper (Nullable, Array, Tuple, LowCardinality, ...) and of what the digit-leading name contains. Covers bare \255`and expression-embeddedmultiIf(equals(`255`, ...))`. Empty name also rejected.
h Backward compatible? Yes. No valid data type name starts with a digit, so no real DDL is rejected. Previously such input aborted debug/sanitizer builds and errored in release too (round-trip is debug-only, but the type never resolved). No setting/format/metadata change.
i Invariants and contracts preserved? Yes. Upholds the parser/formatter round-trip contract (format→parse→format is stable) that executeQuery asserts. The guard runs before any AST node is built; no data-structure or concurrency invariant is touched.

Session id: cron:clickhouse-worker-slot-7:20260706-145700

@groeneai

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @evillique — small parser fix: reject data type names starting with a digit, which the formatter prints unquoted and re-lexes as a number literal (breaks the AST round-trip, STID 1941-1bfa). Closes #109501.

A back-quoted type name whose first character is a digit (e.g. Nullable(`255`))
is printed unquoted by the formatter (Nullable(255)). The unquoted name then
re-lexes as a number literal (ASTLiteral) instead of a type name (ASTDataType),
so the format-parse-format AST round-trip check in executeQuery diverges and
aborts debug/sanitizer builds with an Inconsistent AST formatting LOGICAL_ERROR
(STID 1941-1bfa). Real data type names never start with a digit, so reject them
at parse time, alongside the existing rejection of non-word-char names.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the fix-datatype-numeric-name-roundtrip-109501 branch from e0d553a to 35e322a Compare July 7, 2026 11:28
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [35e322aa]

Summary: ✅


AI Review

Summary

This PR rejects digit-leading quoted data type names in ParserDataType so the formatter cannot emit an unquoted token that reparses as a number, and it adds focused regression coverage for both the minimal Nullable(\255`)` reproducer and the larger fuzzer-shaped case. I did not find any unresolved correctness, compatibility, or evidence gaps in the current patch.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.70% 85.70% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 77.90% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 35e322a

CI fully finished (Finish Workflow: success, Mergeable Check: success). No test failures.

Check / test Reason Owner / fixing PR
CH Inc sync private staging sync CH Inc sync (private, not actionable by us)

All checks green apart from the private CH Inc sync. No PR-caused failures, no flaky/infra failures.

Session id: cron:our-pr-ci-monitor:20260707-153000

@cv4g cv4g self-assigned this Jul 9, 2026
@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #109720 (merged to master 2026-07-08), which applies the identical parse-time guard rejecting type names whose first character is a digit, for the same root cause (STID 1941-1bfa). Master also carries regression coverage in 04507_data_type_name_numeric_roundtrip. Closing this as redundant.

@groeneai groeneai closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: 'Inconsistent AST formatting: the original AST: (STID: 1941-1bfa)

3 participants