Repository navigation
Description
Description
A type name with an Enum label that ends with a backslash cannot be parsed. The server writes the label a\ as 'a\\', and ClickHouseUtils.readParameters then treats the closing quote as escaped because the character before it is a backslash. The rest of the type name is read as part of the label, and the parser fails with NumberFormatException on the next value. Every type that holds such an Enum fails the same way, for example Nullable, Array, Map, Tuple and Variant.
A query that returns such a column fails before the first row, because the client cannot parse the type from the RowBinaryWithNamesAndTypes header. A TableSchema or Client#register that uses the type name fails the same way.
The check in readParameters in clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java is args.charAt(j - 1) != '\\', so it looks only at the previous character. 'a\\' ends with an escaped backslash, and the quote after it closes the string. The fix is to skip the character after each backslash inside a quoted string, the same as readNameOrQuotedString does.
Steps to reproduce
CREATE TABLE t (id Int32, e Enum8('a\\' = 1, 'z' = 2)) ORDER BY idINSERT INTO t VALUES (1, 'a\\')client.queryAll("SELECT id, e FROM t")with client-v2, orClickHouseColumn.of("e", "Enum8('a\\\\' = 1, 'z' = 2)")with no server.
Error Log or Exception StackTrace
With client-v2, client.queryAll("SELECT id, e FROM t") throws this.
com.clickhouse.client.api.ClientException: Failed to get query response
Caused by: java.lang.NumberFormatException: For input string: " 2)"
at java.base/java.lang.Integer.parseInt(Integer.java:648)
at java.base/java.lang.Integer.parseInt(Integer.java:778)
at com.clickhouse.data.ClickHouseEnum.<init>(ClickHouseEnum.java:47)
at com.clickhouse.data.ClickHouseColumn.update(ClickHouseColumn.java:180)
at com.clickhouse.data.ClickHouseColumn.readColumn(ClickHouseColumn.java:751)
at com.clickhouse.data.ClickHouseColumn.of(ClickHouseColumn.java:782)
With jdbc-v2, executeQuery("SELECT id, e FROM t") throws java.sql.SQLException: For input string: " 2)" with the same cause.
Expected Behaviour
The label is read as a\. On the server SELECT hex(toString(e)) returns 615C.
Code Example
ClickHouseColumn.of("e", "Enum8('a\\\\' = 1, 'z' = 2)"); // NumberFormatException: For input string: " 2)"
ClickHouseColumn.of("e", "Map(String, Enum8('a\\\\' = 1, 'z' = 2))"); // NumberFormatException: For input string: " 2))"
ClickHouseColumn.of("e", "Tuple(Enum8('a\\\\' = 1, 'z' = 2), String)"); // NumberFormatException: For input string: " 2), String"Configuration
Environment
- Client version: main at 7506301
- Language version: Java 21
- OS: macOS
ClickHouse Server
- ClickHouse Server version: 26.10.4.207
CREATE TABLEstatements for tables involved: see the steps above
Activity