Repository navigation
Description
Description
client-v2 and jdbc-v2 cannot read a column of a JSON type with a SHARED typed path, for example JSON(SHARED a UInt64). The server added the SHARED modifier in 2026 (JSON data type: "SHARED some.path TypeName"). It changes only how MergeTree parts store the path: the values are encoded as for JSON(a UInt64). The same defect was reported for clickhouse-connect in ClickHouse/clickhouse-connect#1312.
These calls fail with IllegalArgumentException: Unknown data type: a UInt64, also for SELECT * of a table that has the column:
- client-v2
querywithnewBinaryFormatReader(RowBinaryWithNamesAndTypesandNative). This is not aClientException; - client-v2
queryAllandgetTableSchema(wrapped inClientException); - jdbc-v2
Statement.executeQuery(wrapped inSQLException).
All forms that I tested fail: two SHARED paths, a SHARED path and a plain typed path, SHARED with max_dynamic_paths and SKIP, a quoted path (SHARED `a.b` Array(String)), and the type in Nullable and Tuple. A plain typed path with the name SHARED is not affected (the server sends it quoted: JSON(`SHARED` UInt64)). jdbc-v2 PreparedStatement inserts and DatabaseMetaData.getColumns work.
A Dynamic value of such a type also fails: EOFException: End of stream reached before reading all data, or ClientException: Unsupported data type with tag 115 (two SHARED paths, 3 rows).
Workaround: cast the column in the query, CAST(j, 'JSON(a UInt64)').
Steps to reproduce
- Start a ClickHouse 26.11 server.
- Run the code example.
Error Log or Exception StackTrace
Output, the same in 2 of 2 runs:
{a=7, b=x}
Exception in thread "main" com.clickhouse.client.api.ClientException: Failed to get query response
at com.clickhouse.client.api.Client.queryAll(Client.java:2252)
Caused by: java.lang.IllegalArgumentException: Unknown data type: a UInt64
at com.clickhouse.data.ClickHouseDataType.of(ClickHouseDataType.java:497)
at com.clickhouse.data.ClickHouseColumn.readColumn(ClickHouseColumn.java:733)
at com.clickhouse.data.ClickHouseColumn.parseJSONColumn(ClickHouseColumn.java:896)
at com.clickhouse.data.ClickHouseColumn.readColumn(ClickHouseColumn.java:633)
at com.clickhouse.data.ClickHouseColumn.of(ClickHouseColumn.java:782)
at com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader.readSchema(RowBinaryWithNamesAndTypesFormatReader.java:52)
Expected Behaviour
The client reads the type and returns the value, as it does after the cast to JSON(a UInt64). The server (curl):
SELECT toTypeName(j), j FROM (SELECT '{"a": 7, "b": "x"}'::JSON(SHARED a UInt64) AS j) FORMAT JSONEachRow
{"toTypeName(j)":"JSON(SHARED a UInt64)","j":{"a":7,"b":"x"}}
Root cause
- Type names:
ClickHouseColumn.parseJSONColumnreads the first wordSHAREDas the path name (clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseColumn.java:883), and thena UInt64as the type (ClickHouseColumn.java:896). Dynamicvalues: when a typed path isSHARED, the binary type encoding ofJSONhas serialization version 1, with a flags byte after each typed path name (Data types binary encoding).BinaryStreamReader.readDynamicDatareads the version and does not use it (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:1738), so it reads the flags byte as the type of the path (BinaryStreamReader.java:1746).
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Code Example
try (Client client = new Client.Builder().addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("").build()) {
client.execute("CREATE OR REPLACE TABLE t_shared (id UInt32, j JSON(SHARED a UInt64), x Int32) "
+ "ENGINE = MergeTree ORDER BY id").get().close();
client.execute("INSERT INTO t_shared VALUES (1, '{\"a\": 7, \"b\": \"x\"}', 42)").get().close();
System.out.println(client.queryAll("SELECT id, CAST(j, 'JSON(a UInt64)') AS j, x FROM t_shared").get(0).getObject("j"));
System.out.println(client.queryAll("SELECT id, j, x FROM t_shared").get(0).getObject("j"));
}Configuration
Client Configuration
new Client.Builder().addEndpoint("http://localhost:8123").setUsername("default").setPassword("").build()Environment
- Cloud
- Client version:
0.12.0-rc1-SNAPSHOT(mainatf16f8e1a2) - Language version: JDK 17.0.21
- OS: Ubuntu 22.04 (container)
ClickHouse Server
- ClickHouse Server version: 26.11.7.10
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: in the code example- Sample data for all these tables: in the code example
Related
#3526: a separate defect of the Native reader for JSON columns.
Classification: impact: none · area: Data types & formats (JSON) · native: format
Found by automated analysis (Polyglot AI) while checking clickhouse-connect#1312 against the other client repos. Verified against a live server.
Activity