Skip to content

fix(jdbc-v2): support explicit FORMAT JSON queries - #2927

Merged
chernser merged 2 commits into
ClickHouse:mainfrom
014-code:fix/2715-jdbc-json-output
Aug 4, 2026
Merged

fix(jdbc-v2): support explicit FORMAT JSON queries#2927
chernser merged 2 commits into
ClickHouse:mainfrom
014-code:fix/2715-jdbc-json-output

Conversation

@014-code

@014-code 014-code commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • support explicit FORMAT JSON queries in JDBC v2
  • expose the server-rendered JSON through a streaming, single-column
    ResultSet named results
  • return one JDBC row for each line in the JSON response
  • preserve the existing FORMAT JSONEachRow and default
    RowBinaryWithNamesAndTypes paths
  • update the JDBC v2 feature contract and changelog

Problem

JDBC v2 rejects queries with an explicit JSON output format:

Issue

Related #2715.

After migrating from the legacy JDBC driver to JDBC v2, queries that explicitly
request ClickHouse's JSON output format fail in executeQuery():

SELECT 1 AS x FORMAT JSON

@chernser

Copy link
Copy Markdown
Contributor

@014-code

thank you for the contribution!

However we plan to support JSON format in another way because it has metadata and data in one document.
I've commented in the original issue.
Current problem is to make some call with internal client and get result. But for this com.clickhouse.jdbc.ConnectionImpl#getClient can be used.

@014-code

Copy link
Copy Markdown
Contributor Author

@014-code

thank you for the contribution!

However we plan to support JSON format in another way because it has metadata and data in one document. I've commented in the original issue. Current problem is to make some call with internal client and get result. But for this com.clickhouse.jdbc.ConnectionImpl#getClient can be used.

Thanks for the clarification.

I understand. I'll take a look at implementing it using ConnectionImpl#getClient() instead of handling the HTTP response directly.

Document how jdbc-v2 callers can unwrap ConnectionImpl and use the underlying client to consume document-oriented FORMAT JSON responses through QueryResponse. Add integration coverage for the supported path while preserving existing ResultSet format constraints.

Refs ClickHouse#2715
@014-code
014-code force-pushed the fix/2715-jdbc-json-output branch from 4c427f6 to 98ac1a7 Compare July 17, 2026 12:12
Comment thread docs/client-v2-json-support.md Outdated
Comment thread docs/client-v2-json-support.md Outdated
Comment thread jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java
@014-code

014-code commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the clarification. I’ve updated the PR accordingly in 2636d7e.
Reworded the documentation to describe FORMAT JSON as ClickHouse-specific JSON output rather than document-oriented output.
Replaced the line-by-line string collection with a Jackson example that parses QueryResponse#getInputStream() directly.
The example and integration test now handle the meta and data fields separately, including column metadata and row values.
Added a note to use Jackson’s streaming JsonParser for large data arrays.
The JDBC ResultSet behavior remains unchanged; this only documents and verifies access through ConnectionImpl#getClient() as discussed.

@chernser
chernser merged commit 601ade1 into ClickHouse:main Aug 4, 2026
19 of 22 checks passed
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.

2 participants