Repository navigation
fix(jdbc-v2): read Date/DateTime/Time array elements as java.time types via getObject(i, Class) - #3311
fix(jdbc-v2): read Date/DateTime/Time array elements as java.time types via getObject(i, Class)#3311pcbeingused333 wants to merge 2 commits into
Conversation
…es via getObject(i, Class) Fixes ClickHouse#3284
AI review gate — the gate never ran on this headThe org-required gate workflow has no run on What to do: a maintainer runs History (latest 5 heads, newest first)
|
|
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.
|
Thanks @chernser, reworked following your comment on the issue (the This comment was prepared with the assistance of an AI coding tool (Claude Code). |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.
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, |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit f46174e. Configure here.
| multiDimensionalElementType); | ||
| multiDimensionalElementType, | ||
| sourceValue != null && sourceValue.getClass().isArray() | ||
| ? JdbcUtils.arrayToObjectArray(sourceValue) : null); |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit f46174e. Configure here.
AI review gate — Cursor Bugbot found issues
Unresolved findings (3):
What to do:
Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically. |


Fixes #3284
Summary
ArrayResultSet#getObject(int, Class)looks up the target class in theValueConvertersmap for the element's source type. Forjava.sql.Date,java.sql.Timeandjava.sql.Timestampthat map only had the identity andStringconversions, so asking forLocalDate,LocalTimeorLocalDateTimeon the result set fromArray#getResultSet()threwValue 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 -> LocalTimeandTimestamp -> LocalDateTimeconverters toValueConverters, using the JDK'stoLocalDate()/toLocalTime()/toLocalDateTime()(the array elements are built withDate/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 ofArrayResultSetTeststill passes (41 tests).Not covered here: the millisecond rounding of
Time64array elements stored asjava.sql.Timementioned in the issue comments.Checklist
history/latest/3284.md)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()satisfygetObject(i, LocalDate|LocalTime|LocalDateTime.class)using values as decoded from the server, not JDBCDate/Time/Timestampintermediates.jdbc-v2 now keeps a parallel
sourceElementsarray onArray(wired throughJdbcUtils.convertforBinaryStreamReader.ArrayValue) and passes it intoArrayResultSet. TypedgetObjectroutesjava.timetargets throughJdbcUtils.convert(sourceValue, type)when a non-array source element is available; nested array elements propagate the same source slice. Changelog entry added inhistory/latest/3284.md, with timezone-sensitive unit coverage inArrayResultSetTest.Reviewed by Cursor Bugbot for commit f46174e. Bugbot is set up for automated code reviews on this repo. Configure here.