Skip to content

Keep a compound function name parsable when one of its parts contains a dot - #129405

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-compound-function-name-dotted-part
Nov 5, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-compound-function-name-dotted-part

Conversation

@groeneai

@groeneai groeneai commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #128992

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Description

#128992 made ASTFunction write a compound name (db.pv(...)) part by part, splitting the joined name on every dot. A back-quoted part can contain dots, so .. or a part that starts or ends with a dot yields an empty part, written as an empty quoted identifier, which does not parse: SELECT `a..b`.f(1) is formatted as SELECT a.``.b.f(1). The AST fuzzer hits this through {N..M} globs in quoted identifiers, a debug-build Inconsistent AST formatting LOGICAL_ERROR: 1, 2, 3, 4.

The AST keeps only the joined name, so the original boundaries are lost. A dot now separates two parts only when the part before it is non-empty and text follows it. Every parsed name still gets at least two parts with the same joined name, so it parses back as a compound name, which Context::executeTableFunction and the EXPLAIN SYNTAX view inlining rely on. A name without an empty part is written exactly as before.

Not for changelog: #128992 is only in master.

Validation: the new test fails on master and passes with the fix (50/50 randomized runs). The four CI queries abort a master debug build and give ordinary analysis errors with the fix. 810 names built from parts such as ., .., a., .a, a..b and select round-trip and run without the abort; 1176 queries over names without an empty part format byte-identically on both builds.


Workflow [PR]
Sync PR [sync-upstream/pr/129405]

Version info

  • Merged into: 26.11.1.1425-master (included in 26.11 and later)

… a dot

The parser joins the parts of a compound function name with a dot and keeps
only the joined string plus the compound flag. A back-quoted part may itself
contain dots. Since ClickHouse#128992 the formatter writes a compound name part by part
and split the joined name on every dot, so `..` inside a part, or a part that
starts or ends with a dot, produced an empty part, written as an empty quoted
identifier that ParserIdentifier rejects:

    SELECT `a..b`.f(1)  ->  SELECT a.``.b.f(1)

The debug-build round trip in executeQuery then throws LOGICAL_ERROR
"Inconsistent AST formatting". The AST fuzzer reaches it through `{N..M}`
globs turned into quoted identifiers (STID 1941-26fa, 1941-1bfa).

The original part boundaries are not recoverable from the joined name, so
choose them leftmost-greedy: a dot separates two parts only when the part
before it is non-empty and text follows it. Every name the parser produces
(at least two non-empty parts) still gets at least two parts with the same
joined name, so it parses back as a compound name; Context::executeTableFunction
and the EXPLAIN SYNTAX view inlining take a different path for a non-compound
name, so writing such a name as one quoted token would change their decision
after a round trip. Names without an empty part are written exactly as before.
A name with no compound spelling (`v.`, only from AST JSON or the analyzer)
is written as one quoted token, as before ClickHouse#128992.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 PR description: the unfixed output was in a code span that closed early AGREE, fixed description only, no code change
2 💡 The test checks text idempotence, not the compound flag directly DISAGREE every expected output keeps an unquoted dot, which only the compound path prints, and the output depends only on the joined name and the flag

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261104-230500

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT `a..b`.f(1) on a master debug build aborts every time with Inconsistent AST formatting: the query: SELECT a.``.b.f(1) cannot parse query back, the CI message. The new test fails with SYNTAX_ERROR in any build.
b Root cause explained? The AST keeps only the joined name of a compound function; since #128992 the formatter splits it on every dot, so a quoted part with .. or a leading/trailing dot yields an empty part, written as an empty quoted identifier that does not parse.
c Fix matches root cause? Yes. The formatter, the only place that chooses part boundaries, no longer emits an empty part: a dot splits only between non-empty parts. Nothing is guarded at the throw site.
d Test intent preserved / new tests added? New 05507_compound_function_name_with_dotted_part.sql (five formatter round trips plus the executed query). No existing test changed.
e Both directions demonstrated? Master: test FAIL (code 62), direct query aborts (134), all four CI queries abort. Fix: test OK (50/50 randomized runs), UNKNOWN_FUNCTION (46), CI queries give ordinary analysis errors.
f Fix is general across code paths? Both writeFunctionName call sites share the loop. Every parser-produced name keeps a compound spelling; a name with none (AST JSON, analyzer TableFunctionNode for a view named v.) is written as one quoted token, as before #128992.
g Fix generalizes across inputs (params/datatypes/wrappers)? 810 names from parts ., .., a., .a, a.b, a..b, select, x y round-trip and run without the abort; 1176 queries over names without an empty part format byte-identically on master and the fix.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; only text that does not parse today changes. #128992 is in no release branch.
i Invariants and contracts preserved? The written name parses back to a function with the same joined name and, for every parsed name, the same compound flag, which Context::executeTableFunction and EXPLAIN SYNTAX view inlining depend on.

Session id: cron:clickhouse-impl-slot-41:20261104-222900

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim @george-larionov, could you review this and add the can be tested label so CI runs? The compound-name formatter from #128992 split the joined name on every dot, so a quoted part containing .. (the fuzzer's {N..M} globs) was written as an empty quoted identifier that does not parse; a dot now separates two parts only when both are non-empty.

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b47bcd7]

Summary: ✅


AI Review

Summary

PR #129405 fixes ASTFunction formatting when a compound name contains leading, trailing, or repeated dots within quoted parts. The formatter avoids empty identifiers while preserving the joined name and compound flag for parser-produced names. No actionable findings at head b47bcd75e98007f478a8984a4e3ce4004244e436. The new regression test, 05507_compound_function_name_with_dotted_part, passed in Fast test CI.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog can be tested Allows running workflows for external contributors labels Nov 4, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b47bcd75e with master b2889017a (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline.

Job report

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 5, 2026
Merged via the queue into ClickHouse:master with commit b5f8086 Nov 5, 2026
547 of 549 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 5, 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 comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants