Repository navigation
[client-v2] Fix reading Array(Nullable(T)) when values are read as another class - #3293
Open
payallenka wants to merge 2 commits into
Open
payallenka wants to merge 2 commits into
payallenka wants to merge 2 commits into
Conversation
Reading Array(Nullable(T)) failed with "array element type mismatch" when readValue returns a different class than the one declared for T: UInt64 (BigInteger, array was UnsignedLong[]), DateTime and DateTime64 (ZonedDateTime, array was LocalDateTime[]) and IPv6 holding IPv4-mapped addresses (Inet4Address). Allocate the array with the common class of the values read, and use the declared type only for an array of NULLs. Correct that fallback for UInt64, DateTime and Tuple. Fixes ClickHouse#3283 Fixes ClickHouse#3287
payallenka
force-pushed
the
fix/3283-nullable-array-item-type
branch
from
November 4, 2026 19:59
9935557 to
2bdba37
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 2bdba37. Configure here.
|
|
Typing nullable arrays by the values read made Array(Nullable(Point)) fail: a Point is read as double[], and ArrayValue allocates Object[][] for an array class, which cannot hold a double[]. Use an Object array for primitive array values, as before.
Author
Already Agreed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Reading an
Array(Nullable(T))column fails withIllegalArgumentException: array element type mismatchwhenreadValuereturns a different class than the oneresolveArrayItemClasspredicts forT. The reported cases:readValuereturnsUInt64(#3283)UnsignedLong[]BigIntegerDateTime,DateTime64(#3287)LocalDateTime[]ZonedDateTimeIPv6holding an IPv4-mapped addressInet6Address[]Inet4AddressOther types disagree with the table too (
Tuple→Object[],Interval*→Duration/Period,Stringwith binary strings →StringValue). So instead of correcting each entry, the nullable branch ofreadArrayItemnow reads the elements first and allocates the array with the most specific common class of the non-null values.resolveArrayItemClassis used only when every element isNULL. There I correctedUInt64(BigInteger),DateTime/DateTime32/DateTime64(ZonedDateTime) andTuple(Object[]), so an all-NULLarray gets the same component type as one with values. For element types that already worked, the result is unchanged.Closes #3283
Closes #3287
Checklist
ClickHouseBinaryFormatReaderNullableArrayTest#testNullableArraysOfTypesReadAsOtherClassescoversArray(Nullable(UInt64))(including the max value),Array(Nullable(DateTime64(3, 'UTC'))),Array(Nullable(IPv6))with an IPv4-mapped and an IPv6 address, and an all-NULLArray(Nullable(UInt64)). It fails onmainwith the error from [client-v2] Reading Array(Nullable(UInt64)) fails: "Failed to set value ... of class java.math.BigInteger when array type is class [Lcom.clickhouse.data.value.UnsignedLong;" #3283.latest, the table and query from Reading Array(Nullable(DateTime64)) throws 'array element type mismatch' #3287 throw the reported error onmainand return both rows with this change.mvn -pl client-v2,jdbc-v2 installpasses: client-v2 825 + 1201, jdbc-v2 1975 + 799 (21 skipped). Note:DataTypeConverterTest.testDateToStringfails onmaintoo when the JVM timezone is east of UTC (I'm in IST), so I ran the suite with-Duser.timezone=UTC.history/latest/3283.md)Note
Medium Risk
Changes core binary array decoding for all nullable array columns; behavior should match actual read types but affects JDBC/client-v2 result shapes for edge cases like UInt64 and DateTime arrays.
Overview
Fixes
IllegalArgumentExceptionwhen readingArray(Nullable(T))from RowBinary/Native paths becauseArrayValuewas sized withresolveArrayItemClass, whilereadValueoften returns a different class (e.g.BigIntegerforUInt64,ZonedDateTimeforDateTime64,Inet4Addressfor IPv4-mappedIPv6).For nullable element columns,
readArrayItemnow reads all elements first, picks the most specific common superclass of non-null values via newcommonSuperclass, and only falls back toresolveArrayItemClasswhen every element isNULL.resolveArrayItemClassfor nullable types is updated forUInt64,DateTime/DateTime32/DateTime64, andTupleso all-null arrays match populated ones.Adds
testNullableArraysOfTypesReadAsOtherClassesand a changelog note for #3283 / #3287.Reviewed by Cursor Bugbot for commit 2bdba37. Bugbot is set up for automated code reviews on this repo. Configure here.
Update (Payal Lenka, 2026-11-06): the first commit broke
Array(Nullable(Point)), as Cursor Bugbot reported: aPointis read asdouble[], whichArrayValuecannot store in theObject[][]it allocates for array classes.4bacdc3uses anObjectarray for primitive array values, andtestNullableArraysOfArrayBackedTypescoversPoint,RingandTuple. It fails without that commit.This also corrects the sentence above that the result is unchanged for types that already worked. The values are unchanged, but the array's component type can now be more specific where it was declared as
Object(for exampleHashMap[]instead ofObject[]forArray(Nullable(JSON))).mvn -pl client-v2,jdbc-v2 installpasses with-Duser.timezone=UTC: client-v2 826 + 1201, jdbc-v2 1975 + 799 (21 skipped).