Repository navigation
fix(column): parse Tuple element names that contain a space - #2074
spicysharkco wants to merge 4 commits into
Conversation
A backquoted element name such as `a b` Int64 was split at its first space, giving name "`a" and type "b` Int64". When the name is backquoted, split at the first space after the closing backtick. Fixes ClickHouse#2073
…mmas The guard that tells a name from an unnamed type such as Decimal(10, 2) looked for a parenthesis before the first space, so `price (usd)` Float64 was read as a type. The element split also counted brackets and commas inside a backquoted name. Apply the guard only to unquoted names, and do not split inside a backquoted name that opens an element.
🤖 Claude reviewFixes What I checked:
Minor points (inline, nits only):
Blind spots:
Verdict: ✅ Approve Inline comments are attached to the relevant lines. This summary updates in place on re-review. |
The Tuple parser carried its own copy of the bracket and quote-aware comma split. indexTopLevelComma in map.go already handles backquoted names, quoted strings and backslash escapes, so use it and drop the name and escape state kept here. The existing Tuple rows pass as before. Because indexTopLevelComma also skips single-quoted strings, a parenthesis inside a quoted Enum value no longer ends the element; a test row covers it.
chernser
left a comment
There was a problem hiding this comment.
Thank you @spicysharkco !
However please do:
- simplify name extraction. Task really in getting everything between back quouts and double quotes (back quotes case is missing, btw)
- extend tests with different case like double escape sequence, double quotes, etc.
Here is also what LLM found:
Redundant + buggy split after nameEnd: Once the loop finds the closing quote at i, the name is already cType[:i+1] and the type is strings.TrimSpace(cType[i+1:]). Searching cType[nameEnd:] for " " afterward fails whenever the separator is \n or \t (such as HTTP pretty-printed types, tested in lib/column/tuple_test.go:42-46) or omitted:
Trace Tuple(a b\nDecimal(10, 2)): nameEnd = 5, strings.Index(cType[5:], " ") skips \nDecimal(10, and matches the space inside Decimal(10, 2). Because nameEnd > 0 bypasses !strings.Contains(cType[:sep], "("), it sets name = "a b\nDecimal(10," and cType = "2)", failing to parse.
Trace Tuple(a b\tInt64) or Tuple(a\tInt64): strings.Index(..., " ") returns -1, leaving the name attached to the type.
Thanks!
splitTupleElement takes a name in backticks or double quotes as the text between the quotes, unescaped, and the rest of the element as the type. The second search for a space is gone, so a newline, a tab or no separator after the closing quote works, and an unquoted name ends at any whitespace. Inside the quotes a backslash escapes the next character, and \t, \n, \r, \b, \f and \0 decode to the control characters the server writes that way.
Summary
Fixes #2073.
A named
Tupleelement with a space in its name, such asTuple(`a b` Int64), made every query on that column fail withunsupported column type "bInt64".(*Tuple).parsesplit each element at its first space, so the name became ``aand the typebInt64``. The backquote handling from #2046 ran after that split. When the name is backquoted, the element is now split at the first space after the closing backtick, skipping an escaped backtick inside the name. Parentheses and commas inside a backquoted name, as in ``Tuple(price (usd)` Float64)``, no longer end it or mark it as a type.Covered by a new row in
TestTupleParseElementNamesand a native and HTTP regression test intests/issues/issue_2073_test.go. Both fail without the change.Checklist
Note
Medium Risk
Touches core Tuple type parsing used on every query involving named tuples; behavior change is targeted and heavily tested but affects a frequently used column code path.
Overview
Fixes Tuple type parsing so named elements with spaces, parentheses, or commas in backquoted or double-quoted names no longer break column decoding (e.g.
Tuple(`a b` Int64)).(*Tuple).parsenow splits elements at top-level commas via existingindexTopLevelComma, then uses newsplitTupleElementto separate name and type. Quoted names are read as a whole (withtupleNameUnescapefor server escapes); unquoted names still split on whitespace unless the first token contains((typed parameters likeDecimal(9, 2)).Unit coverage in
TestTupleParseElementNamesis expanded;tests/issues/issue_2073_test.goadds native/HTTP round-trip for tuple maps with spaced names.Reviewed by Cursor Bugbot for commit aa99677. Bugbot is set up for automated code reviews on this repo. Configure here.