Skip to content

Commit e0590c3

Browse files
committed
Added reader for JSONEachRow format. Updated documentation and examples
1 parent 9e5367e commit e0590c3

51 files changed

Lines changed: 6571 additions & 648 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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
@@ -1651,6 +1651,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16511651
if (requestSettings.getFormat() == null) {
16521652
requestSettings.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes);
16531653
}
1654+
applyFormatSpecificSettings(requestSettings);
16541655
ClientStatisticsHolder clientStats = new ClientStatisticsHolder();
16551656
clientStats.start(ClientMetrics.OP_DURATION);
16561657

@@ -2242,6 +2243,30 @@ private Map<String, Object> buildRequestSettings(Map<String, Object> opSettings)
22422243
return requestSettings;
22432244
}
22442245

2246+
/**
2247+
* Applies format-specific server-side settings to the already merged request settings.
2248+
* Must be called after {@link #buildRequestSettings(Map)} and after the request format has been resolved
2249+
* (either provided by the caller or defaulted), so that the inspected format reflects the final value.
2250+
*
2251+
* <p>For {@link ClickHouseFormat#JSONEachRow}, callers may opt in to plain JSON numbers by setting
2252+
* {@link ClientConfigProperties#JSON_DISABLE_NUMBER_QUOTING}. Explicit server settings are otherwise
2253+
* left untouched.</p>
2254+
* <ul>
2255+
* <li>{@code output_format_json_quote_64bit_integers}</li>
2256+
* <li>{@code output_format_json_quote_64bit_floats}</li>
2257+
* <li>{@code output_format_json_quote_decimals}</li>
2258+
* </ul>
2259+
*/
2260+
private static void applyFormatSpecificSettings(QuerySettings requestSettings) {
2261+
boolean disableNumberQuoting = ClientConfigProperties.JSON_DISABLE_NUMBER_QUOTING
2262+
.getOrDefault(requestSettings.getAllSettings());
2263+
if (requestSettings.getFormat() == ClickHouseFormat.JSONEachRow && disableNumberQuoting) {
2264+
requestSettings.serverSetting("output_format_json_quote_64bit_integers", "0");
2265+
requestSettings.serverSetting("output_format_json_quote_64bit_floats", "0");
2266+
requestSettings.serverSetting("output_format_json_quote_decimals", "0");
2267+
}
2268+
}
2269+
22452270
private Duration durationSince(long sinceNanos) {
22462271
return Duration.ofNanos(System.nanoTime() - sinceNanos);
22472272
}

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
@@ -190,6 +190,11 @@ public Object parseValue(String value) {
190190
*/
191191
HTTP_SEND_PARAMS_IN_BODY("client.http.use_form_request_for_query", Boolean.class, "false"),
192192

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

194199
/**
195200
* Prefix for custom settings. Should be aligned with server configuration.

0 commit comments

Comments
 (0)