Skip to content

Reading an array date value as LocalDate fails, same for other temporal types #3284

Description

@anesterenok

Description

Reading an array value with conversion to another class fails, though the same conversion works for non-array values.

Steps to reproduce

  1. Create a MergeTree table with Array(Nullable(Date32)) and/or Array(Nullable(DateTime64)) and/or Array(Nullable(Time64)), add some values
  2. Query the table and read the array values as a ResultSet:
try (ResultSet trs = query.getResultSet() {
    trs.next();
    Array array = rs.getArray(columnIndex);

    ResultSet ars = array.getResultSet()) {
    while (ars.next()) {
        Object value = ars.getObject(2, LocalDate.class);  
        // or LocalDateTime.class for DateTime64, 
        // or LocalTime.class for Time64
    }
}
  1. getObject() fails

Error Log or Exception StackTrace

java.sql.SQLException: Value of class java.sql.Date cannot be converted to class java.time.LocalDate
	at com.clickhouse.jdbc.types.ArrayResultSet.convertValue(ArrayResultSet.java:146)
	at com.clickhouse.jdbc.types.ArrayResultSet.getValueAsObject(ArrayResultSet.java:168)
	at com.clickhouse.jdbc.types.ArrayResultSet.getObject(ArrayResultSet.java:1254)

Expected Behaviour

The same conversion works for row ResultSet, so I think it should work for array result sets as well.

I believe the cause is that for array conversions, com.clickhouse.client.api.data_formats.internal.ValueConverters class is used, and it does not have Date->LocalDate / Time -> LocalTime / Timestamp -> LocalDateTime conversions.

Code Example

see above

Configuration

Client Configuration

?

Environment

  • Cloud
  • Client version: JDBC driver version 0.11-all
  • Language version: JDK 17
  • OS: Ubuntu 24

ClickHouse Server

  • ClickHouse Server version: 26.10
  • ClickHouse Server non-default settings, if any: none

Activity

  1. anesterenok commented on Nov 2, 2026

    @anesterenok
    Author

    I also add that storing array time value as java.sql.Time means it gets rounded to milliseconds, while Time64 type is expected to be precise up to nanoseconds.

  2. chernser commented on Nov 17, 2026

    @chernser
    Contributor

    @anesterenok Thank you for reporting this!

    Just conversion is not a solution for this problem because converting Date to LocalDate should be done with care to timezone. LocalDate is date in some local timezone and DB value has none.

    Date values are already read as LocalDate internally and conversion to Date then to LocalDate back might be not correct.
    Issue is in Array object as I see it is created as array of Date objects.

    lets review together and decide.
    CC: @pcbeingused333

  3. anesterenok commented on Nov 19, 2026

    @anesterenok
    Author

    I don't quite get it.
    LocalDate (or Date, for that matter) is not influenced by TZ at all, as well as LocalTime.
    Even for LocalDateTime, its "naive" datetime which is not in any local time zone, its just bunch of numbers.

    And you already support that conversion for primitive fields, just as the JDBC spec tolds to.

    I don't really see how conversion of array elements is supposed to be different from converting primitive values. Yes, I understand that on physical level these are represented differently, but we're talking API, right?
    And from API viewpoint, it should not matter whether I read a "real" ResultSet, or an Array one. In fact, that's the whole point of JDBC specifying reading arrays as result sets in the first place.

  4. polyglotAI-bot commented on Nov 27, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — fix needed
    Open PR #3311 does not fix the issue's steps: with its diff, the three getObject calls still fail. It changes only the BinaryStreamReader.ArrayValue path, but jdbc-v2 reads an array as a List by default. It does not cover the Time64 fraction loss either; if #3311 closes this issue, that part needs its own issue.

    • Category: Bug
    • Classification: impact: Data integrity · area: Data types & formats (Array(Date32), Array(DateTime64), Array(Time64))
    • Status on main: Reproduced on main — the three calls fail with the reported error; a Time64 element loses its whole fraction, with no error.
    • Breaking change: No — can be done without a break, if the array elements keep their current Java classes.
    • Duplicates / related: None found

    Analysis: ArrayResultSet.java:157 throws because ValueConverters gives java.sql.Date, Time, and Timestamp only an identity and a String conversion (ValueConverters.java:110-115). The elements have these classes because jdbc-v2 reads an array as a List by default (JdbcConfiguration.java:568) and converts each element in JdbcUtils.convert (JdbcUtils.java:331, :420-426). The second defect in the comments: JdbcUtils.java:426 makes a Time64 element with Time.valueOf(LocalTime), which drops the whole fraction, not only the part below milliseconds (12:34:56.123456789 becomes 12:34:56.000).

    Reproduction: complete program and output

    Changed from the issue's steps: one table with the three types, a Date32 row column as a contrast, and a Time64(9) element read with getArray().

    import java.sql.Array;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.time.LocalDate;
    import java.time.LocalDateTime;
    import java.time.LocalTime;
    import java.util.Properties;
    
    public class Repro {
        static final String URL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
        static final String PASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
    
        public static void main(String[] args) throws Exception {
            Properties props = new Properties();
            props.setProperty("user", "default");
            props.setProperty("password", PASSWORD);
            String jdbcUrl = "jdbc:clickhouse:" + URL.replaceFirst("^https?:", "") + "/default";
            try (Connection conn = DriverManager.getConnection(jdbcUrl, props);
                 Statement stmt = conn.createStatement()) {
                stmt.execute("DROP TABLE IF EXISTS issue3284");
                stmt.execute("CREATE TABLE issue3284 (id Int32, d Array(Nullable(Date32)), dt Array(Nullable(DateTime64(3))),"
                        + " t Array(Nullable(Time64(9))), d1 Date32) ENGINE = MergeTree ORDER BY id");
                stmt.execute("INSERT INTO issue3284 VALUES (1, ['2024-01-02', NULL], ['2024-01-02 03:04:05.678'],"
                        + " ['12:34:56.123456789'], '2024-01-02')");
    
                Class<?>[] targets = {LocalDate.class, LocalDateTime.class, LocalTime.class};
                String[] cols = {"d", "dt", "t"};
                try (ResultSet rs = stmt.executeQuery("SELECT d, dt, t, d1 FROM issue3284")) {
                    rs.next();
                    for (int i = 0; i < cols.length; i++) {
                        Array array = rs.getArray(i + 1);
                        try (ResultSet ars = array.getResultSet()) {
                            ars.next();
                            try {
                                System.out.println(cols[i] + " array getObject(2, " + targets[i].getSimpleName() + "): "
                                        + ars.getObject(2, targets[i]));
                            } catch (Exception e) {
                                System.out.println(cols[i] + " array getObject(2, " + targets[i].getSimpleName() + "): "
                                        + e.getClass().getName() + ": " + e.getMessage());
                            }
                        }
                    }
                    Object t = ((Object[]) rs.getArray(3).getArray())[0];
                    System.out.println("t array element: " + t.getClass().getName() + " " + t
                            + ", getTime()=" + ((java.util.Date) t).getTime());
                    System.out.println("row d1 getObject(4, LocalDate): " + rs.getObject(4, LocalDate.class));
                }
                stmt.execute("DROP TABLE issue3284");
            }
        }
    }

    Output on main (8480ca001), ClickHouse 26.11.2.4:

    d array getObject(2, LocalDate): java.sql.SQLException: Value of class java.sql.Date cannot be converted to class java.time.LocalDate
    dt array getObject(2, LocalDateTime): java.sql.SQLException: Value of class java.sql.Timestamp cannot be converted to class java.time.LocalDateTime
    t array getObject(2, LocalTime): java.sql.SQLException: Value of class java.sql.Time cannot be converted to class java.time.LocalTime
    t array element: java.sql.Time 12:34:56, getTime()=45296000
    row d1 getObject(4, LocalDate): 2024-01-02
    

    Output with the diff of PR #3311:

    build=0
    d array getObject(2, LocalDate): java.sql.SQLException: Value of class java.sql.Date cannot be converted to class java.time.LocalDate
    dt array getObject(2, LocalDateTime): java.sql.SQLException: Value of class java.sql.Timestamp cannot be converted to class java.time.LocalDateTime
    t array getObject(2, LocalTime): java.sql.SQLException: Value of class java.sql.Time cannot be converted to class java.time.LocalTime
    t array element: java.sql.Time 12:34:56, getTime()=45296000
    row d1 getObject(4, LocalDate): 2024-01-02
    

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

  5. added
    data-types
    jdbc
    on Nov 27, 2026
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

    bugdata-typesjdbc

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions