Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static Map<Class<?>, Integer> buildVariantMapping(List<ClickHouseDataType
return variantMapping;
}

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

Expand Down
20 changes: 19 additions & 1 deletion client-v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,26 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
Expand Down
25 changes: 25 additions & 0 deletions client-v2/src/main/java/com/clickhouse/client/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
if (requestSettings.getFormat() == null) {
requestSettings.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes);
}
applyFormatSpecificSettings(requestSettings);
ClientStatisticsHolder clientStats = new ClientStatisticsHolder();
clientStats.start(ClientMetrics.OP_DURATION);

Expand Down Expand Up @@ -2242,6 +2243,30 @@ private Map<String, Object> buildRequestSettings(Map<String, Object> opSettings)
return requestSettings;
}

/**
* Applies format-specific server-side settings to the already merged request settings.
* Must be called after {@link #buildRequestSettings(Map)} and after the request format has been resolved
* (either provided by the caller or defaulted), so that the inspected format reflects the final value.
*
* <p>For {@link ClickHouseFormat#JSONEachRow}, callers may opt in to plain JSON numbers by setting
* {@link ClientConfigProperties#JSON_DISABLE_NUMBER_QUOTING}. Explicit server settings are otherwise
* left untouched.</p>
* <ul>
* <li>{@code output_format_json_quote_64bit_integers}</li>
* <li>{@code output_format_json_quote_64bit_floats}</li>
* <li>{@code output_format_json_quote_decimals}</li>
* </ul>
*/
private static void applyFormatSpecificSettings(QuerySettings requestSettings) {
boolean disableNumberQuoting = ClientConfigProperties.JSON_DISABLE_NUMBER_QUOTING
.getOrDefault(requestSettings.getAllSettings());
if (requestSettings.getFormat() == ClickHouseFormat.JSONEachRow && disableNumberQuoting) {
requestSettings.serverSetting("output_format_json_quote_64bit_integers", "0");
requestSettings.serverSetting("output_format_json_quote_64bit_floats", "0");
requestSettings.serverSetting("output_format_json_quote_decimals", "0");
}
}

private Duration durationSince(long sinceNanos) {
return Duration.ofNanos(System.nanoTime() - sinceNanos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ public Object parseValue(String value) {
*/
HTTP_SEND_PARAMS_IN_BODY("client.http.use_form_request_for_query", Boolean.class, "false"),

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

/**
* Prefix for custom settings. Should be aligned with server configuration.
Expand Down
Loading
Loading