Skip to content

client-v2: DataTypeConverter formats java.sql.Date as the previous day when the JVM time zone is east of UTC #3497

In review

Description

@monosoul

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

  1. Set the JVM default time zone to a zone east of UTC, for example TZ=Europe/Berlin.
  2. Run the code example below, or mvn -pl client-v2 test -Dtest=DataTypeConverterTest.
  3. 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 server

Environment

  • Cloud
  • Client version: client-v2 0.12.0-rc1-SNAPSHOT, main at 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 TABLE statements for tables involved: none
  • Sample data for all these tables: none

Classification: impact: Data integrity · area: Data types & formats (Date)

Activity

  1. added
    client
    data-types
    on Dec 2, 2026
  2. polyglotAI-bot commented on Dec 2, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — fix needed
    Review PR #3496. It formats java.sql.Date.toLocalDate(), and with its diff the issue's steps give 2022-01-04 in UTC, Europe/Berlin, Pacific/Kiritimati (UTC+14), and America/New_York. It closes this issue when it merges.

    • Category: Bug
    • Classification: impact: Data integrity · area: Data types & formats (Date, Date32)
    • Status on main: Reproduced on main — the issue's code example gives the output that the issue shows (TZ=UTC correct, TZ=Europe/Berlin one day earlier), on main 91e0ddf3a with JDK 17; no server is used.
    • Breaking change: No — DataTypeConverter is in an internal package, and the fix makes the output follow the java.sql.Date contract.
    • Duplicates / related: No others.

    Analysis: DataTypeConverter.java:143-145 formats Instant.ofEpochMilli(date.getTime()) in UTC, but java.sql.Date.valueOf gives midnight in the JVM default time zone, so in each zone east of UTC the date is the previous day. Date and Date32 both use this branch (DataTypeConverter.java:58-60). The query parameters of Client.query(sql, params) do not reach it: scalar values use String.valueOf (DataTypeConverter.java:288), and arrays and maps use ClickHouseValues.convertToSqlExpression (DataTypeConverter.java:356). So only code that calls DataTypeConverter directly gets the wrong date.

    Automated triage by Polyglot AI. A maintainer makes the final decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclientdata-types

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions