Skip to content

Commit a5e9d08

Browse files
authored
Merge pull request #2871 from ClickHouse/06/10/26/jsonl_support
Added reader for JSONEachRow format. Updated documentation and examples
2 parents 2c1a01d + fb3ce31 commit a5e9d08

39 files changed

Lines changed: 5793 additions & 648 deletions

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseDataType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static Map<Class<?>, Integer> buildVariantMapping(List<ClickHouseDataType
177177
return variantMapping;
178178
}
179179

180-
static final Map<ClickHouseDataType, Set<Class<?>>> DATA_TYPE_TO_CLASS = dataTypeClassMap();
180+
public static final Map<ClickHouseDataType, Set<Class<?>>> DATA_TYPE_TO_CLASS = Collections.unmodifiableMap(dataTypeClassMap());
181181
static Map<ClickHouseDataType, Set<Class<?>>> dataTypeClassMap() {
182182
Map<ClickHouseDataType, Set<Class<?>>> map = new HashMap<>();
183183

client-v2/pom.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,26 @@
8888
<dependency>
8989
<groupId>com.fasterxml.jackson.core</groupId>
9090
<artifactId>jackson-databind</artifactId>
91-
<scope>test</scope>
9291
<version>${jackson.version}</version>
92+
<scope>provided</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>com.fasterxml.jackson.core</groupId>
96+
<artifactId>jackson-core</artifactId>
97+
<version>${jackson.version}</version>
98+
<scope>provided</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>com.fasterxml.jackson.core</groupId>
102+
<artifactId>jackson-annotations</artifactId>
103+
<version>${jackson.version}</version>
104+
<scope>provided</scope>
105+
</dependency>
106+
<dependency>
107+
<groupId>com.google.code.gson</groupId>
108+
<artifactId>gson</artifactId>
109+
<version>${gson.version}</version>
110+
<scope>provided</scope>
93111
</dependency>
94112
<dependency>
95113
<groupId>${project.parent.groupId}</groupId>

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
17101710
if (requestSettings.getFormat() == null) {
17111711
requestSettings.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes);
17121712
}
1713+
applyFormatSpecificSettings(requestSettings);
17131714
ClientStatisticsHolder clientStats = new ClientStatisticsHolder();
17141715
clientStats.start(ClientMetrics.OP_DURATION);
17151716

@@ -2295,6 +2296,30 @@ private Map<String, Object> buildRequestSettings(Map<String, Object> opSettings)
22952296
return requestSettings;
22962297
}
22972298

2299+
/**
2300+
* Applies format-specific server-side settings to the already merged request settings.
2301+
* Must be called after {@link #buildRequestSettings(Map)} and after the request format has been resolved
2302+
* (either provided by the caller or defaulted), so that the inspected format reflects the final value.
2303+
*
2304+
* <p>For {@link ClickHouseFormat#JSONEachRow}, callers may opt in to plain JSON numbers by setting
2305+
* {@link ClientConfigProperties#JSON_DISABLE_NUMBER_QUOTING}. Explicit server settings are otherwise
2306+
* left untouched.</p>
2307+
* <ul>
2308+
* <li>{@code output_format_json_quote_64bit_integers}</li>
2309+
* <li>{@code output_format_json_quote_64bit_floats}</li>
2310+
* <li>{@code output_format_json_quote_decimals}</li>
2311+
* </ul>
2312+
*/
2313+
private static void applyFormatSpecificSettings(QuerySettings requestSettings) {
2314+
boolean disableNumberQuoting = ClientConfigProperties.JSON_DISABLE_NUMBER_QUOTING
2315+
.getOrDefault(requestSettings.getAllSettings());
2316+
if (requestSettings.getFormat() == ClickHouseFormat.JSONEachRow && disableNumberQuoting) {
2317+
requestSettings.serverSetting("output_format_json_quote_64bit_integers", "0");
2318+
requestSettings.serverSetting("output_format_json_quote_64bit_floats", "0");
2319+
requestSettings.serverSetting("output_format_json_quote_decimals", "0");
2320+
}
2321+
}
2322+
22982323
private Duration durationSince(long sinceNanos) {
22992324
return Duration.ofNanos(System.nanoTime() - sinceNanos);
23002325
}

client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ public Object parseValue(String value) {
193193
*/
194194
HTTP_SEND_PARAMS_IN_BODY("client.http.use_form_request_for_query", Boolean.class, "false"),
195195

196+
/**
197+
* When enabled for JSONEachRow queries, asks ClickHouse to emit large integer,
198+
* floating-point, and decimal values as JSON numbers instead of quoted strings.
199+
*/
200+
JSON_DISABLE_NUMBER_QUOTING("json_disable_number_quoting", Boolean.class, "false"),
196201

197202
/**
198203
* Prefix for custom settings. Should be aligned with server configuration.

0 commit comments

Comments
 (0)