Skip to content

fix(column): parse JSON typed paths that contain a space - #2072

Open
spicysharkco wants to merge 3 commits into
ClickHouse:mainfrom
spicysharkco:fix-json-typed-path-space
Open

spicysharkco wants to merge 3 commits into
ClickHouse:mainfrom
spicysharkco:fix-json-typed-path-space

Conversation

@spicysharkco

@spicysharkco spicysharkco commented Oct 16, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1948.

A JSON typed path with a space in its name, such as JSON(`a b` Int64), made every query on that column fail with unsupported column type. (*JSON).parse split each entry at its first space, so the path became a and the type b` Int64. When the path is backquoted, the entry is now split at the first space after the closing backtick. An escaped backtick inside the path (\`) does not end it, and the path is unescaped the same way Tuple element names are.

Covered by TestJSONParseTypedPaths and a native and HTTP regression test in tests/issues/issue_1948_test.go. Both fail without the change.

Named Tuple elements are handled in #2074.

Checklist

  • Unit and integration tests covering the common scenarios were added

Note

Medium Risk
Changes core JSON type-string parsing used on every query against typed JSON columns; mistakes could mis-bind paths or types, though coverage is broad.

Overview
Fixes #1948: JSON column schemas like JSON(`a b` Int64) no longer break with unsupported column type because parsing no longer splits path and type at the first space inside a backquoted path.

(*JSON).parse now finds the closing backtick via new quotedPathEnd (honoring \` escapes), splits on the first space after that quote, and unescapeColName paths the same way Tuple names are. SKIP entries get the same unescaping. splitWithDelimiters treats backslashes inside quotes and ignores parentheses inside backticks so commas, dots, and nested types in path names parse correctly.

Adds TestJSONParseTypedPaths and a native/HTTP regression in issue_1948_test.go for spaced and escaped-path JSON columns.

Reviewed by Cursor Bugbot for commit 43672cb. Bugbot is set up for automated code reviews on this repo. Configure here.

A backquoted typed path such as `a b` Int64 was split at its first
space, giving path "a" and type "b` Int64". When the path is
backquoted, split at the first space after the closing backtick.

Fixes ClickHouse#1948
@CLAassistant

CLAassistant commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

The server writes a backtick inside a backquoted path as \`. The
closing-quote search stopped at that escaped backtick, so a path such as
`c\`d e` was split inside its name, and splitWithDelimiters toggled on
it too, so the entries after such a path were split wrongly. The path
also kept the backslash, so a lookup by the real key c`d missed it.

Skip escaped characters when looking for the closing backtick and when
splitting the entries, and unescape the path as Tuple element names are.
Comment thread lib/column/json.go
i++
currentPart.WriteByte(s[i])
}
case '`':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Should fix — parentheses inside a backquoted path still break the split

( and ) are counted into brackets even while inBackticks is true, so a quoted path containing a parenthesis stops every later top-level comma from splitting and the column fails with the same unsupported column type error this PR fixes.

  • Trace: JSON(`a(b` Int64, c String) yields one part, parse then calls Type("Int64, c String").Column(...) and returns an error.
  • The SKIP branch is affected the same way.
 		case '(':
-			brackets++
+			if !inBackticks {
+				brackets++
+			}
 			currentPart.WriteByte(s[i])
 		case ')':
-			brackets--
+			if !inBackticks {
+				brackets--
+			}

Please add {"JSON(`a(b` Int64, c String)", []string{"a(b", "c"}} to TestJSONParseTypedPaths.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 43672cb: splitWithDelimiters now counts parentheses only outside backticks, which also covers the SKIP entries. TestJSONParseTypedPaths has your row JSON(`a(b` Int64, c String) and a second one with ) in a later path. Both failed before the change.

Comment thread lib/column/json.go Outdated

typedPath := strings.Trim(typedPathParts[0], "`")
typeName := strings.TrimSpace(typedPathParts[1])
typedPath := strings.Trim(typePart[:pathEnd+sep], "`")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Nit — nit: typedPath is computed twice for quoted paths

The strings.Trim result is discarded whenever pathEnd > 0, so the quoted and unquoted cases read as one assignment that is then overwritten.

-		typedPath := strings.Trim(typePart[:pathEnd+sep], "`")
-		if pathEnd > 0 {
-			typedPath = unescapeColName(typePart[:pathEnd+sep])
-		}
+		var typedPath string
+		if pathEnd > 0 {
+			typedPath = unescapeColName(typePart[:pathEnd+sep])
+		} else {
+			typedPath = strings.Trim(typePart[:sep], "`")
+		}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 43672cb: typedPath is now set in one branch.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Claude review

Fixes (*JSON).parse so a backquoted typed path such as JSON(`a b` Int64) is split after the closing backtick instead of at the first space, and teaches splitWithDelimiters to honour backslash escapes inside backticks. The core change is correct: I traced every case in TestJSONParseTypedPaths plus the unclosed-backtick fallback by hand and they all produce the expected path and type. The regression test covers native and HTTP against a live server, which also validates the server's backslash-escaping of the type name.

Key concerns (sibling paths of the same root cause):

  • A ( or ) inside a backquoted path still corrupts the bracket depth in splitWithDelimiters, so JSON(`a(b` Int64, c String) fails with the same unsupported column type symptom this PR fixes (see inline on lib/column/json.go).
  • The SKIP branch still strips backticks with strings.Trim and never unescapes, so SKIP `c\`d` is stored as c\`d and hasSkipPath misses it on append (see general finding).

Blind spots: the sandbox denied checking out or patching the branch, so I could not execute the new unit or integration tests; all findings rest on hand traces of the diff against the current json.go and tuple.go.

Verdict: ⚠️ Request changes

General findings

  • ⚠️ Should fix — SKIP paths are not unescaped like typed paths
    The SKIP branch at lib/column/json.go:127-131 still does strings.Trim(path, " "), so a skipped path with an escaped backtick such as ``SKIP c`d `` is stored as ``c\dwhile the typed-path branch now storesc`d``.

    • hasSkipPath("cd")then returns false inappendObject` (line 749), so the value is appended as a dynamic path and sent to the server instead of being skipped.
    • Same root cause as this PR; a one-line change keeps the two branches consistent:
    -			path = strings.Trim(path, " `")
    +			path = unescapeColName(strings.TrimSpace(path))

    unescapeColName already strips the surrounding backticks and leaves unquoted paths such as fake.field untouched, so existing tests keep passing. Add a SKIP case with a space and an escaped backtick to TestJSONParseTypedPaths (asserting col.skipPaths).

Inline comments are attached to the relevant lines. This summary updates in place on re-review.

A parenthesis inside a backquoted path was counted as bracket depth in
splitWithDelimiters, so no later comma split the entries and the type
failed to parse, as in JSON(`a(b` Int64, c String). Count brackets
only outside backticks.

The SKIP branch trimmed backticks without unescaping, so SKIP `c\`d`
was stored as c\`d and hasSkipPath missed the real path c`d. Unescape
it as typed paths are.

Build typedPath in one branch instead of overwriting it. Test rows
added for each case.
@spicysharkco
spicysharkco requested review from a team and polyglotAI-bot as code owners November 20, 2026 01:41
@spicysharkco

Copy link
Copy Markdown
Author

Fixed in 43672cb: the SKIP branch now uses unescapeColName(strings.TrimSpace(path)), and splitWithDelimiters ignores parentheses inside backticks. TestJSONParseTypedPaths now asserts skipPaths, with rows for a plain, a spaced, an escaped-backtick and a parenthesis path. The escaped-backtick and parenthesis rows failed before the change.

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.

JSON typed path containing a space is unparseable: unsupported column type "b` Int64"

3 participants