Repository navigation
[client-v2] Parse Enum labels that end with a backslash - #3372
Open
Indian-boult wants to merge 1 commit into
Open
Indian-boult wants to merge 1 commit into
Indian-boult wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ClickHouseUtils.readParameterstreated a quote inside a quoted string as escaped when the character before it was a backslash. The server writes the Enum labela\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 withNumberFormatException. A client-v2 or jdbc-v2 query that returned such a column failed before the first row, and so did aTableSchemabuilt from the type name.Nullable,Array,Map,TupleandVariantof such an Enum failed the same way.The loop now skips the character after each backslash in a quoted string, the same way
readNameOrQuotedStringalready 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#testReadParametershas a new case with'a\\','b\\\''and'c'.ClickHouseColumnTesthas 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 insideNullable,Array,Map,TupleandVariant.RowBinaryFormatWriterTest#writeEnumWithSchemaFromTypeNameTesthas 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, whichClickHouseColumnuses 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.readParametersused 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 throwNumberFormatExceptionon queries andTableSchemabuilt from the type string.The quoted-string loop in
readParametersnow consumes the character after each backslash, matchingreadNameOrQuotedString/skipQuotedString:\\is one escaped backslash and the following quote ends the string; escaped quotes like\'still behave as before.Unit tests cover
readParameters,ClickHouseColumnenum constants insideNullable,Array,Map,Tuple, andVariant, plus a RowBinaryFormatWriter integration case forEnum8('a\\' = 1, 'z' = 2). Changelog entry added underhistory/latest/3371.md.Reviewed by Cursor Bugbot for commit 8ba876b. Bugbot is set up for automated code reviews on this repo. Configure here.