Repository navigation
Description
Description
In client-v2, DataTypeConverter formats a java.sql.Date as an instant in UTC (DataTypeConverter.dateToString, client-v2/src/main/java/com/clickhouse/client/api/internal/DataTypeConverter.java:143-145). A java.sql.Date is a local date: java.sql.Date.valueOf("2022-01-04") is midnight of that date in the JVM default time zone. In a time zone east of UTC, that midnight is on the previous day in UTC, so the converter returns the previous day, with no error.
This affects DataTypeConverter.convertToString and arrayToString (also through DataTypeConverter.INSTANCE, which #2897 gives as a workaround to format array query parameters). getString() of the readers on a Date column is not affected: it changes the value to LocalDate first.
DataTypeConverterTest.testDateToString shows the bug: it fails on a machine with a JVM time zone east of UTC. CI runs in UTC, so CI does not find it.
Steps to reproduce
- Set the JVM default time zone to a zone east of UTC, for example
TZ=Europe/Berlin. - Run the code example below, or
mvn -pl client-v2 test -Dtest=DataTypeConverterTest. - The result is one day earlier than the given date.
Error Log or Exception StackTrace
# TZ=UTC
[2022-01-04, 2022-01-05]
2022-01-04
# TZ=Europe/Berlin
[2022-01-03, 2022-01-04]
2022-01-03
# DataTypeConverterTest with TZ=Europe/Berlin
DataTypeConverterTest.testDateToString:98 expected [2022-01-04] but found [2022-01-03]
Expected Behaviour
A java.sql.Date is formatted as its local date (java.sql.Date.toLocalDate()), the same in each JVM time zone: 2022-01-04 for java.sql.Date.valueOf("2022-01-04").
Code Example
import com.clickhouse.client.api.internal.DataTypeConverter;
import com.clickhouse.data.ClickHouseColumn;
System.out.println(DataTypeConverter.INSTANCE.arrayToString(
java.util.Arrays.asList(java.sql.Date.valueOf("2022-01-04"), java.sql.Date.valueOf("2022-01-05")),
"Array(Date)"));
System.out.println(DataTypeConverter.INSTANCE.convertToString(
java.sql.Date.valueOf("2022-01-04"), ClickHouseColumn.of("d", "Date")));Configuration
Client Configuration
// none: the conversion does not use a client or a serverEnvironment
- Cloud
- Client version: client-v2
0.12.0-rc1-SNAPSHOT,mainat 91e0ddf (the code is from 0b5dddb, September 2025) - Language version: Java 17 and Java 25
- OS: Linux, JVM time zone
Europe/Berlin
ClickHouse Server
- ClickHouse Server version: not needed (client-side conversion)
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none- Sample data for all these tables: none
Classification: impact: Data integrity · area: Data types & formats (Date)
Activity
polyglotAI-bot commentedon Dec 2, 2026
Recommendation: Keep open — fix needed
Review PR #3496. It formats
java.sql.Date.toLocalDate(), and with its diff the issue's steps give2022-01-04in UTC,Europe/Berlin,Pacific/Kiritimati(UTC+14), andAmerica/New_York. It closes this issue when it merges.main: Reproduced on main — the issue's code example gives the output that the issue shows (TZ=UTCcorrect,TZ=Europe/Berlinone day earlier), onmain91e0ddf3awith JDK 17; no server is used.DataTypeConverteris in aninternalpackage, and the fix makes the output follow thejava.sql.Datecontract.Analysis:
DataTypeConverter.java:143-145formatsInstant.ofEpochMilli(date.getTime())in UTC, butjava.sql.Date.valueOfgives midnight in the JVM default time zone, so in each zone east of UTC the date is the previous day.DateandDate32both use this branch (DataTypeConverter.java:58-60). The query parameters ofClient.query(sql, params)do not reach it: scalar values useString.valueOf(DataTypeConverter.java:288), and arrays and maps useClickHouseValues.convertToSqlExpression(DataTypeConverter.java:356). So only code that callsDataTypeConverterdirectly gets the wrong date.Automated triage by Polyglot AI. A maintainer makes the final decision.