Skip to content

fix(jdbc-v2): read Date/DateTime/Time array elements as java.time types via getObject(i, Class) - #3311

Open
pcbeingused333 wants to merge 1 commit into
ClickHouse:mainfrom
pcbeingused333:c1719-array-getobject-time
Open

pcbeingused333 wants to merge 1 commit into
ClickHouse:mainfrom
pcbeingused333:c1719-array-getobject-time

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3284

Summary

ArrayResultSet#getObject(int, Class) looks up the target class in the ValueConverters map for the element's source type. For java.sql.Date, java.sql.Time and java.sql.Timestamp that map only had the identity and String conversions, so asking for LocalDate, LocalTime or LocalDateTime on the result set from Array#getResultSet() threw Value of class java.sql.Date cannot be converted to class java.time.LocalDate, although the same call works on a regular row ResultSet.

This adds Date -> LocalDate, Time -> LocalTime and Timestamp -> LocalDateTime converters to ValueConverters, using the JDK's toLocalDate() / toLocalTime() / toLocalDateTime() (the array elements are built with Date/Time/Timestamp.valueOf(...), so this round-trips exactly).

New ArrayResultSetTest#testJavaTimeConversions (Date32, DateTime64(6) and Time arrays, including a null element) fails on main with the error from the issue and passes with the change; the rest of ArrayResultSetTest still passes (41 tests).

Not covered here: the millisecond rounding of Time64 array elements stored as java.sql.Time mentioned in the issue comments.

Checklist


This change was prepared with the assistance of an AI coding tool (Claude Code), and the author is responsible for it.


Note

Low Risk
Small, additive converter mappings in shared client code with unit tests; no auth, security, or persistence changes.

Overview
Fixes ResultSet#getObject(int, Class) on the result set from java.sql.Array#getResultSet() so array elements stored as java.sql.Date, Time, and Timestamp can be read as java.time.LocalDate, LocalTime, and LocalDateTime—matching behavior on ordinary row result sets.

ValueConverters now registers those java.time targets for the three JDBC temporal types and implements conversion via the JDK toLocalDate() / toLocalTime() / toLocalDateTime() helpers.

Adds ArrayResultSetTest#testJavaTimeConversions (Date32, DateTime64(6), Time arrays, including nulls) and a CHANGELOG note in history/latest/3284.md.

Reviewed by Cursor Bugbot for commit bcf40b1. Bugbot is set up for automated code reviews on this repo. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant