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 2 commits into
ClickHouse:mainfrom
pcbeingused333:c1719-array-getobject-time
Open

pcbeingused333 wants to merge 2 commits 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
Localized JDBC array/result-set conversion path with new tests; behavior change only affects typed java.time reads from array result sets when wire values are present.

Overview
Fixes #3284 by letting Array#getResultSet() satisfy getObject(i, LocalDate|LocalTime|LocalDateTime.class) using values as decoded from the server, not JDBC Date/Time/Timestamp intermediates.

jdbc-v2 now keeps a parallel sourceElements array on Array (wired through JdbcUtils.convert for BinaryStreamReader.ArrayValue) and passes it into ArrayResultSet. Typed getObject routes java.time targets through JdbcUtils.convert(sourceValue, type) when a non-array source element is available; nested array elements propagate the same source slice. Changelog entry added in history/latest/3284.md, with timezone-sensitive unit coverage in ArrayResultSetTest.

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

@security-ai-gate-reviewer

security-ai-gate-reviewer Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

AI review gate — the gate never ran on this head

The org-required gate workflow has no run on bcf40b1b8c80: this pull request was open before the repository was enrolled, and GitHub starts that workflow only on opened, synchronize and reopened. Nothing here can merge until it runs.

What to do: a maintainer runs rollout kick-gate --repo ClickHouse/clickhouse-java --pr 3311 --apply from infra/github/conformance in security-integrations (dry run without --apply), or closes and reopens this pull request (auto-merge is turned off by the close; re-enable it after).

History (latest 5 heads, newest first)

  • bcf40b1b8c80 gate never ran — needs a kick

@chernser

Copy link
Copy Markdown
Contributor

Thank you, @pcbeingused333 !

please see comment in the issue #3284 (comment)

…ad of converting java.sql types

Per review on ClickHouse#3284: do not add Date->LocalDate conversions in ValueConverters (time zone
concerns). Array now keeps the elements as read from the server and the array ResultSet
returns them for LocalDate/LocalTime/LocalDateTime targets.
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 20, 2026 01:55
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks @chernser, reworked following your comment on the issue (the Array was built from java.sql.Date objects): the ValueConverters Date/Time/Timestamp -> java.time conversions are removed. The Array now also keeps the elements as read from the server (e.g. LocalDate for Date32, ZonedDateTime for DateTime64), and the result set from getResultSet() serves getObject(i, LocalDate/LocalTime/LocalDateTime.class) from those values, so nothing is round-tripped through java.sql.Date/Time/Timestamp and the JVM time zone is not involved. getArray() and default getObject(i) still return the java.sql types. The new test runs with a default zone whose DST gap would shift a Timestamp round trip (00:30 -> 01:30) and passes; ArrayResultSetTest 41/41. Not covered: Time64 sub-millisecond precision when read as java.sql.Time.

This comment was prepared with the assistance of an AI coding tool (Claude Code).

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit f46174e. Configure here.

Object[] convertedValues = convertArray(arrayValue.getArray(), convertToJavaClass(baseType),
column.getArrayNestedLevel());
return new Array(column, convertedValues, multiDimensionalArrayElementType);
return new Array(column, convertedValues, multiDimensionalArrayElementType,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List arrays omit source elements

High Severity

sourceElements is only attached when converting a BinaryStreamReader.ArrayValue, but JDBC maps Array to List (defaultTypeHintMapping), so ResultSet.getArray() goes through convert’s List branch and builds Array without the wire values. Array#getResultSet().getObject(i, LocalDate/LocalTime/LocalDateTime.class) still fails with the original conversion error, so the reported issue is not fixed on the real read path. The new unit test only exercises the ArrayValue branch.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f46174e. Configure here.

sourceSlice = new Object[count];
System.arraycopy(sourceElements, (int) index, sourceSlice, 0, count);
}
return new ArrayResultSet(getArray(index, count), column, multiDimensionalElementType, sourceSlice);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slice copies before bounds checks

Medium Severity

getResultSet(index, count) copies sourceElements before getArray(index, count) validates the range. With sourceElements set, a negative count throws NegativeArraySizeException and an out-of-range index/count throws ArrayIndexOutOfBoundsException instead of the SQLException that getArray previously returned.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f46174e. Configure here.

multiDimensionalElementType);
multiDimensionalElementType,
sourceValue != null && sourceValue.getClass().isArray()
? JdbcUtils.arrayToObjectArray(sourceValue) : null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested array sources are dropped

Medium Severity

Nested date/time arrays lose sourceElements. Wire nested values are ArrayValue or List, not Java arrays, so sourceValue.getClass().isArray() is false and the nested Array is created with a null source. arrayToObjectArray(arrayValue.getArray()) also does not recurse (ArrayValue.toObjectArray() would). Inner getResultSet().getObject(i, LocalDate.class) still fails for Array(Array(Date32)) and similar types.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f46174e. Configure here.

@github-actions

Copy link
Copy Markdown

AI review gate — Cursor Bugbot found issues

  • Cursor Bugbot found issues that are not resolved (check concluded 'neutral').

Unresolved findings (3):

What to do:

  • Fix the findings and push. The reviewer re-reviews the new commit and the gate re-runs by itself.
  • Finding wrong, or reviewer stuck? Ask a human with write access who is not the PR author to approve this exact commit, then re-run the gate. Their approval stands in for the AI review (a new push needs a new approval).

Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically.

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

2 participants