client-v2: java.util.Date / ZonedDateTime / OffsetDateTime / Instant query parameters are sent as toString() and rejected by the server
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 76/100
調査の方向性
Start with client-v2/src/main/java/com/clickhouse/client/api/internal/DataTypeConverter.java, especially convertParameterToString, and trace how container values are rendered through ClickHouseValues.convertToSqlExpression. Run the reproduction command mvn -pl client-v2 test -Dtest=DateParamTest against the reported cases. Done means supported JDK temporal values work as scalar and container query parameters for their declared ClickHouse date and datetime types.
索引モデルが issue の本文から書いたものです。
説明
Description
Client.query(sql, queryParams, settings) formats every scalar parameter through
DataTypeConverter.convertParameterToString(Object), which falls through to String.valueOf(value)
for anything that is not a CharSequence and not a container
(client-v2/src/main/java/com/clickhouse/client/api/internal/DataTypeConverter.java:269-289):
// Other scalars have no escapable characters and are read verbatim by the server, so they
// are passed through unquoted (e.g. Date, numbers, Identifier).
return String.valueOf(value);
That works for the temporal types whose toString() happens to be a ClickHouse-readable text form
(LocalDate -> 2026-05-15, java.sql.Date -> 2026-05-15, LocalDateTime -> 2026-05-15T10:20:30),
but it emits an unparsable value for the other common JDK temporal types:
value bound to {p:...} |
emitted param_p |
server |
|---|---|---|
java.util.Date |
Fri May 15 00:00:00 UTC 2026 |
rejected for Date, Date32 and DateTime |
ZonedDateTime |
2026-05-15T10:20:30Z[UTC] |
rejected for DateTime (code 457) |
OffsetDateTime |
2026-05-15T10:20:30Z |
rejected for DateTime (code 457, trailing Z) |
Instant |
2026-05-15T10:20:30Z |
rejected for DateTime (code 457, trailing Z) |
The container path has the same gap for java.util.Date: PR #2898 made container leaves be rendered with
ClickHouseValues.convertToSqlExpression, which single-quotes LocalDate/LocalDateTime/ZonedDateTime
leaves, but it does not know java.util.Date, so a List<java.util.Date> bound to {p:Array(Date)} is
emitted as [Fri May 15 00:00:00 UTC 2026] and fails too.
Note that Instant was reported before in #2456 and fixed by #2501, which special-cased Instant in
HttpAPIClientHelper/Client. That special case no longer exists on main (no Instant reference is
left in Client.java or HttpAPIClientHelper.java) - the parameter formatting was moved to
DataTypeConverter.convertParameterToString, which only does String.valueOf. So the Instant row above
is a regression of #2456.
ClickHouse server version
26.11.2.4 (local, HTTP), verified with the reproduction below run from client-v2's TestNG suite.
Repo state: main at b5f3cdf (client-v2 0.12.0-rc1-SNAPSHOT).
Reproduction
client-v2/src/test/java/com/clickhouse/client/query/DateParamTest.java:
package com.clickhouse.client.query;
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.internal.DataTypeConverter;
import com.clickhouse.client.api.query.QueryResponse;
import com.clickhouse.client.api.query.QuerySettings;
import com.clickhouse.data.ClickHouseFormat;
import org.testng.annotations.Test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.time.*;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
public class DateParamTest {
private Client client;
private void run(String label, String sql, Object value) {
Map<String, Object> params = Collections.singletonMap("p", value);
System.out.println(label + "\n wire: param_p="
+ DataTypeConverter.INSTANCE.convertParameterToString(value));
try (QueryResponse r = client.query(sql, params,
new QuerySettings().setFormat(ClickHouseFormat.JSONEachRow)).get()) {
BufferedReader br = new BufferedReader(new InputStreamReader(r.getInputStream()));
System.out.println(" OK -> " + br.readLine());
} catch (Exception e) {
Throwable c = e.getCause() != null ? e.getCause() : e;
System.out.println(" ERROR: " + c.getMessage().split("\n")[0]);
}
}
@Test
public void temporalScalarQueryParams() throws Exception {
client = new Client.Builder().addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("").build();
LocalDate ld = LocalDate.of(2026, 5, 15);
Date ud = Date.from(Instant.parse("2026-05-15T00:00:00Z"));
java.sql.Date sd = java.sql.Date.valueOf(ld);
ZonedDateTime zdt = ZonedDateTime.of(2026, 5, 15, 10, 20, 30, 0, ZoneId.of("UTC"));
run("Date <- LocalDate (control)", "SELECT {p:Date} AS v", ld);
run("Date <- java.util.Date", "SELECT {p:Date} AS v", ud);
run("Date32 <- java.util.Date", "SELECT {p:Date32} AS v", ud);
run("Date <- java.sql.Date (control)", "SELECT {p:Date} AS v", sd);
run("DateTime <- java.util.Date", "SELECT toTimeZone({p:DateTime},'UTC') AS v", ud);
run("DateTime <- ZonedDateTime", "SELECT toTimeZone({p:DateTime},'UTC') AS v", zdt);
run("DateTime <- OffsetDateTime", "SELECT toTimeZone({p:DateTime},'UTC') AS v", zdt.toOffsetDateTime());
run("DateTime <- Instant", "SELECT toTimeZone({p:DateTime},'UTC') AS v", zdt.toInstant());
run("DateTime <- LocalDateTime (control)", "SELECT toTimeZone({p:DateTime},'UTC') AS v",
LocalDateTime.of(2026, 5, 15, 10, 20, 30));
run("Array(Date) <- List<java.util.Date>", "SELECT {p:Array(Date)} AS v",
Collections.singletonList(ud));
run("Array(DateTime) <- List<ZonedDateTime> (control)", "SELECT {p:Array(DateTime)} AS v",
Collections.singletonList(zdt));
client.close();
}
}
Run with mvn -pl client-v2 test -Dtest=DateParamTest.
Expected: every binding of a value that is valid for the declared parameter type round-trips, as the
LocalDate / java.sql.Date / LocalDateTime controls do.
Actual output:
Date <- LocalDate (control)
wire: param_p=2026-05-15
OK -> {"v":"2026-05-15"}
Date <- java.util.Date
wire: param_p=Fri May 15 00:00:00 UTC 2026
ERROR: Code: 38. DB::Exception: Cannot parse date here: Fri May 15: value Fri May 15 00:00:00 UTC 2026 cannot be parsed as Date for query parameter 'p'. (CANNOT_PARSE_DATE)
Date32 <- java.util.Date
wire: param_p=Fri May 15 00:00:00 UTC 2026
ERROR: Code: 38. DB::Exception: Cannot parse date here: Fri May 15: value Fri May 15 00:00:00 UTC 2026 cannot be parsed as Date32 for query parameter 'p'. (CANNOT_PARSE_DATE)
Date <- java.sql.Date (control)
wire: param_p=2026-05-15
OK -> {"v":"2026-05-15"}
DateTime <- java.util.Date
wire: param_p=Fri May 15 00:00:00 UTC 2026
ERROR: Code: 41. DB::Exception: Cannot parse datetime: value Fri May 15 00:00:00 UTC 2026 cannot be parsed as DateTime for query parameter 'p'. (CANNOT_PARSE_DATETIME)
DateTime <- ZonedDateTime
wire: param_p=2026-05-15T10:20:30Z[UTC]
ERROR: Code: 457. DB::Exception: Value 2026-05-15T10:20:30Z[UTC] cannot be parsed as DateTime for query parameter 'p' because it isn't parsed completely: only 19 of 25 bytes was parsed: 2026-05-15T10:20:30. (BAD_QUERY_PARAMETER)
DateTime <- OffsetDateTime
wire: param_p=2026-05-15T10:20:30Z
ERROR: Code: 457. DB::Exception: Value 2026-05-15T10:20:30Z cannot be parsed as DateTime for query parameter 'p' because it isn't parsed completely: only 19 of 20 bytes was parsed: 2026-05-15T10:20:30. (BAD_QUERY_PARAMETER)
DateTime <- Instant
wire: param_p=2026-05-15T10:20:30Z
ERROR: Code: 457. DB::Exception: Value 2026-05-15T10:20:30Z cannot be parsed as DateTime for query parameter 'p' because it isn't parsed completely: only 19 of 20 bytes was parsed: 2026-05-15T10:20:30. (BAD_QUERY_PARAMETER)
DateTime <- LocalDateTime (control)
wire: param_p=2026-05-15T10:20:30
OK -> {"v":"2026-05-15 10:20:30"}
Array(Date) <- List<java.util.Date>
wire: param_p=[Fri May 15 00:00:00 UTC 2026]
ERROR: Code: 27. DB::Exception: Cannot parse input: expected '\'' before: 'Fri May 15 00:00:00 UTC 2026]': value [Fri May 15 00:00:00 UTC 2026] cannot be parsed as Array(Date) for query parameter 'p'. (CANNOT_PARSE_INPUT_ASSERTION_FAILED)
Array(DateTime) <- List<ZonedDateTime> (control)
wire: param_p=['2026-05-15 10:20:30']
OK -> {"v":["2026-05-15 10:20:30"]}
Suggested fix
In DataTypeConverter.convertParameterToString
(client-v2/src/main/java/com/clickhouse/client/api/internal/DataTypeConverter.java:269-289), handle
temporal scalars explicitly instead of letting them fall through to String.valueOf:
java.util.Date->yyyy-MM-dd HH:mm:ss[.SSS]in UTC (the class already has this conversion in
DataTypeConverterat lines 143-149 / 171-178 / 200-208, andDataTypeUtilshas the formatters).Instant/OffsetDateTime/ZonedDateTime-> the sameyyyy-MM-dd HH:mm:ss[.SSS]text, normalized to
UTC (or to the configured server time zone), so the trailingZ/[UTC]that the server's reader stops
at is not emitted. This also restores the behaviour #2501 added forInstantbefore the parameter
formatting moved intoDataTypeConverter.
For the container path, ClickHouseValues.convertToSqlExpression (or the caller in
convertParameterContainer) needs the same java.util.Date branch so that Array(Date) /
Array(DateTime) elements of that type are quoted and formatted like the java.time ones already are.
Note the same caveat as in the JS client: the formatter does not see the declared placeholder type, so a
single text form has to suit Date, Date32, DateTime and DateTime64 alike - a quoted/plain
YYYY-MM-DD HH:MM:SS[.fff] string is accepted by all four, whereas a bare Unix timestamp or an ISO string
with a zone suffix is not.
Link
Cross-client analog of https://github.com/ClickHouse/clickhouse-js/issues/1211 (scalar Date/Date32
query parameters serialized in a form the server rejects). Related here: #2456 / #2501 (Instant, closed,
regressed), #2897 / #2898 (container quoting), #3387 (a different LocalDateTime defect).
- 主要言語
- Java
- スター
- 1.6k
- フォーク
- 657
- 平均マージ
- 2日 6時間
- マージ済み PR(30日)
- 36
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ClickHouse/clickhouse-java のほかの issue
-
api-diagnostics bug jdbc
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
ClickHouse/clickhouse-java#3464 ·
メンテナーはふだん 1 日以内に返信
-
tests
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-java#3452 ·
メンテナーはふだん 1 日以内に返信
-
bug jdbc performance queries sql-parser
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
ClickHouse/clickhouse-java#3451 ·
メンテナーはふだん 1 日以内に返信
-
bug jdbc legacy queries
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ClickHouse/clickhouse-java#3444 ·
メンテナーはふだん 1 日以内に返信
-
api-diagnostics bug client jdbc
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-java#3439 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
ClickHouse/clickhouse-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
quelea-projection/Quelea#749 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
erkamyaman/rust-anything#963 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 76/100
-
Deferred
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Sanne/incus-spawn#2768 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
morluto/rea#15041 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信