fix(jdbc-v2): support explicit FORMAT JSON queries - #2927
Conversation
|
thank you for the contribution! However we plan to support JSON format in another way because it has metadata and data in one document. |
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
4c427f6 to
98ac1a7
Compare
| .getClient() | ||
| .query("SELECT 1 AS x FORMAT JSON") | ||
| .get(); | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader( |
There was a problem hiding this comment.
This is very inefficient way of parsing JSON - every JSON library supports reading from input stream.
Please provide example where it is demonstrated for example with Jackson library.
Besides JSON format (https://clickhouse.com/docs/reference/formats/JSON/JSON) has meta and data separated - so users need some instructions how to handle them.
|
|
||
| ## Usage in `jdbc-v2` | ||
|
|
||
| ### Document-oriented JSON output |
There was a problem hiding this comment.
It is not document oriented, I'd say. It is just JSON format output with very ClickHouse specific structure https://clickhouse.com/docs/reference/formats/JSON/JSON
| .get(); | ||
| BufferedReader reader = new BufferedReader( | ||
| new InputStreamReader(response.getInputStream(), StandardCharsets.UTF_8))) { | ||
| assertEquals(response.getFormat(), ClickHouseFormat.JSON); |
There was a problem hiding this comment.
we use tests as reference implementation sometimes. This test do not fit this needs.
Please align it with example in the document.
|
Thank you for the clarification. I’ve updated the PR accordingly in 2636d7e. |
Summary
FORMAT JSONqueries in JDBC v2ResultSetnamedresultsFORMAT JSONEachRowand defaultRowBinaryWithNamesAndTypespathsProblem
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
JSONoutput format fail inexecuteQuery():