Skip to content

[client-v2] Parse Enum labels that end with a backslash - #3372

Open
Indian-boult wants to merge 1 commit into
ClickHouse:mainfrom
Indian-boult:fix/enum-label-trailing-backslash
Open

Indian-boult wants to merge 1 commit into
ClickHouse:mainfrom
Indian-boult:fix/enum-label-trailing-backslash

Conversation

@Indian-boult

@Indian-boult Indian-boult commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

ClickHouseUtils.readParameters treated a quote inside a quoted string as escaped when the character before it was a backslash. The server writes the Enum label a\ as 'a\\', so for that label the closing quote was skipped. The rest of the type name was read as part of the label and the parser failed with NumberFormatException. A client-v2 or jdbc-v2 query that returned such a column failed before the first row, and so did a TableSchema built from the type name. Nullable, Array, Map, Tuple and Variant of such an Enum failed the same way.

The loop now skips the character after each backslash in a quoted string, the same way readNameOrQuotedString already does. So \\ is one escaped backslash and the next quote closes the string. A quote after an odd number of backslashes is still escaped, so labels such as \' are read as before. Nothing else changes for strings without a backslash.

This PR does not change how the label is decoded after it is split. That part is #3348, in #3369. The two branches change different methods and merge without conflicts.

Tests. ClickHouseUtilsTest#testReadParameters has a new case with 'a\\', 'b\\\'' and 'c'. ClickHouseColumnTest has a data provider with labels that end with one or two backslashes at the start and the end of the list, a label \' that worked before as a control, and the same Enum inside Nullable, Array, Map, Tuple and Variant. RowBinaryFormatWriterTest#writeEnumWithSchemaFromTypeNameTest has one more row that creates the table with the label, writes it and reads it back from a 26.10 server. Without the change 9 of the new unit cases and the new integration row fail, and with it all pass.

Closes #3371

Checklist


Note

Medium Risk
Changes low-level quoted-string parsing in readParameters, which ClickHouseColumn uses for type names; risk is mitigated by broad new tests but could affect other parameterized type strings with backslashes.

Overview
Fixes client-v2 and jdbc-v2 failures when a ClickHouse type name contains an Enum label that ends with \ (serialized as 'a\\' = 1). ClickHouseUtils.readParameters used to treat the closing quote as escaped whenever the previous character was a backslash, so parsing never terminated the label and column/type parsing could throw NumberFormatException on queries and TableSchema built from the type string.

The quoted-string loop in readParameters now consumes the character after each backslash, matching readNameOrQuotedString / skipQuotedString: \\ is one escaped backslash and the following quote ends the string; escaped quotes like \' still behave as before.

Unit tests cover readParameters, ClickHouseColumn enum constants inside Nullable, Array, Map, Tuple, and Variant, plus a RowBinaryFormatWriter integration case for Enum8('a\\' = 1, 'z' = 2). Changelog entry added under history/latest/3371.md.

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

readParameters treated a quote as escaped when the character before it
was a backslash. For a label that ends with an escaped backslash, such
as 'a\\', the closing quote was skipped, the rest of the type name was
read as part of the label and the parser failed with
NumberFormatException. A query that returned such a column failed
before the first row.

Skip the character after each backslash in a quoted string, the same
way as readNameOrQuotedString does. Escaped quotes are read as before.

Closes ClickHouse#3371
@Indian-boult
Indian-boult requested review from a team and mzitnik as code owners November 18, 2026 03:56
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.

[client-v2] An Enum label that ends with a backslash makes the type name fail to parse

1 participant