Skip to content

[client-v2, jdbc-v2] JSON with a SHARED typed path cannot be read: "Unknown data type: a UInt64" #3527

Backlog

Description

@polyglotAI-bot

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 query with newBinaryFormatReader (RowBinaryWithNamesAndTypes and Native). This is not a ClientException;
  • client-v2 queryAll and getTableSchema (wrapped in ClientException);
  • jdbc-v2 Statement.executeQuery (wrapped in SQLException).

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

  1. Start a ClickHouse 26.11 server.
  2. 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.parseJSONColumn reads the first word SHARED as the path name (clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseColumn.java:883), and then a UInt64 as the type (ClickHouseColumn.java:896).
  • Dynamic values: when a typed path is SHARED, the binary type encoding of JSON has serialization version 1, with a flags byte after each typed path name (Data types binary encoding). BinaryStreamReader.readDynamicData reads 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 (main at f16f8e1a2)
  • 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 TABLE statements 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

  1. added
    client
    jdbc
    data-types
    native-format
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclientdata-typesjdbcnative-format

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions