Repository navigation
Fix Inconsistent AST formatting for a Tuple with mixed named/unnamed elements - #108915
Conversation
…elements
A Tuple data type that mixes named and unnamed elements (for example
Tuple(a UInt8, UInt16), as produced by the AST fuzzer) was parsed into an
ASTTupleDataType whose element_names holds an empty string placeholder for
each unnamed element. ASTTupleDataType::formatImpl emitted that empty name
through backQuoteIfNeed(""), which produces an empty backquoted identifier ``.
The resulting SQL (Tuple(a UInt8, `` UInt16)) cannot be parsed back, so the
parse-format-parse round-trip check in executeQueryImpl raised the
LOGICAL_ERROR "Inconsistent AST formatting" and aborted the server in debug
and sanitizer builds (STID 1941-26fa).
Skip the name and its trailing space when the placeholder is empty, in both
the single-line and the pretty (multiline) formatting branches. The type now
formats as Tuple(a UInt8, UInt16), which round-trips and still produces the
normal BAD_ARGUMENTS exception ("Names are specified not for all elements of
Tuple type") at type resolution.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260630-095200 |
|
cc @evillique @george-larionov — could you review this? It fixes the |
| /// Print element name if present. | ||
| /// An empty name is the placeholder for an unnamed element in a | ||
| /// mixed named/unnamed tuple; formatting it as `` (an empty | ||
| /// backquoted identifier) is not parseable back, so skip it. |
There was a problem hiding this comment.
@groeneai Please consider to remove the sentence:
formatting it as `` (an empty
/// backquoted identifier) is not parseable back, so skip it.
It may be confusing to unfamiliar readers of the code. it's totally expected that unnamed elements do not have a name serialized. Explaining that an empty string in backticks is not parseable confuses the point in my opinion.
| @@ -97,8 +100,8 @@ void ASTTupleDataType::formatImpl(WriteBuffer & ostr, const FormatSettings & set | |||
| if (i > 0) | |||
| ostr << ", "; | |||
|
|
|||
| /// Print element name if present | |||
| if (i < element_names.size()) | |||
| /// See the multiline branch above: skip an empty placeholder name. | |||
There was a problem hiding this comment.
@groeneai Please mention the term unnamed element in this comment. If you want to you can add that unnamed elements are represented by empty strings which in turn serve as placeholder. Although I would go one step further and suggest to not introduce the term placeholder here. It's an unnecessary indirection to what is actually meant.
|
Workflow [PR], commit [88cb888] Summary: ❌
AI ReviewSummaryThis PR fixes formatting for parsed Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
@groeneai Can you please add a test for the multi line branch? |
Add four cases to 03210_inconsistent_formatting_of_data_types that format the mixed named/unnamed tuples without --oneline, so the first pass takes the pretty (multi-line) branch of ASTTupleDataType::formatImpl, then re-format with --oneline to assert the multi-line output reparses to a stable result. Reword the two element-name comments to talk about unnamed elements (empty names) directly, instead of explaining that an empty backquoted identifier is unparseable. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation gate (click to expand) — covers 88cb888
Session id: cron:clickhouse-worker-slot-3:20260630-150500 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
CI finish ledger — 88cb888CI fully finished (Finish Workflow: success @ 19:11 UTC). This PR fixes
The diff is confined to the AST formatter for Session id: cron:our-pr-ci-monitor:20260630-193000 |
CI finish ledger — 88cb888Every failure below has an owner. Only
No PR-caused failure. This PR fixes the AST formatter for a Tuple with mixed named/unnamed elements; it cannot cause a TSAN ThreadPool-shutdown deadlock. Session id: cron:our-pr-ci-monitor:20260630-200000 |
c124391
…ed-tuple-json Fix Inconsistent AST formatting for a Tuple with mixed named/unnamed elements
Related: #108372
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR("Inconsistent AST formatting") that aborted the server in debug and sanitizer builds when formatting aTupledata type that mixes named and unnamed elements (for exampleTuple(a UInt8, UInt16)).Description
The AST fuzzer hit
Inconsistent AST formatting(STID1941-26fa) on a fuzzer-mangledCREATE TABLEwhose column type was aTuplemixing named and unnamed elements. This is the nested named-tuple /JSONshape tracked by #108372; it is unrelated to the PRs it shows up on and reproduces onmaster. It is a different shape from #107806 (no-argument window function inCODEC).Root cause: a
Tuple(a UInt8, UInt16)is parsed intoASTTupleDataTypewhoseelement_namesholds an empty-string placeholder for each unnamed element.ASTTupleDataType::formatImplemitted that empty name viabackQuoteIfNeed(""), which produces an empty backquoted identifier``. The formatted SQLTuple(a UInt8, `` UInt16)cannot be parsed back, so the parse/format round-trip check inexecuteQueryImpl(#ifndef NDEBUG) raised theLOGICAL_ERROR.Fix: skip the name and its trailing space when the placeholder is empty, in both the single-line and pretty (multiline) branches. The type now formats as
Tuple(a UInt8, UInt16), which round-trips and still raises the normalBAD_ARGUMENTS("Names are specified not for all elements of Tuple type") at type resolution.Verified on a debug build (both directions): the previously-aborting
clickhouse-localCREATE TABLE t (x Tuple(a UInt8, UInt16))now returns a cleanBAD_ARGUMENTSinstead ofSIGABRT, the server survives, and valid named/unnamed tuples are unchanged. Regression coverage added to03210_inconsistent_formatting_of_data_types.CI report (AST fuzzer (amd_debug), STID 1941-26fa, on #91358): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=91358&sha=fec6b590416b97167791253cb52586db7bd50d56&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29
Version info
26.7.1.428(included in26.7and later)