You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BinaryStreamReader.ArrayValue wrong return type #2846
Current implementation of BinaryStreamReader.readArrayItem(ClickHouseColumn itemTypeColumn, int len)
doesn't return correct expected type as it was in client v1.
Current implementation
if (itemTypeColumn.isNullable() || itemTypeColumn.getDataType() == ClickHouseDataType.Variant) {
array = new ArrayValue(Object.class, len);
for (int i = 0; i < len; i++) {
array.set(i, readValue(itemTypeColumn));
}
}
The logic here is wrong unless it was done on purpose.
We should add another condition to return an array with the correct type not Object.class
if (itemTypeColumn.isNullable() || itemTypeColumn.getDataType() == ClickHouseDataType.Variant) {
ClickHouseDataType type = column.getDataType();
array = new ArrayValue( type.getPrimitiveClass().isPrimitive()?Object.class: type.getPrimitiveClass(), len);
for (int i = 0; i < len; i++) {
array.set(i, readValue(itemTypeColumn));
}
}
Expected Behaviour
when we have a nullable non primitive type (example NullableDouble array) we should return Double[] instead of Object[]
Size: Small Type: Bug Affected Module: client-api-v2
Summary
BinaryStreamReader.readArrayItem unconditionally uses Object.class as the element type for nullable and Variant/Dynamic/Geometry columns, so a Nullable(Float64) array is returned as Object[] instead of Double[]. The fix is to derive the correct wrapper class from ClickHouseDataType.getPrimitiveClass() and fall back to Object.class only when the type is truly primitive (since primitives cannot hold null).
Recommended Labels & Priority
Labels: bug, client-api-v2, area:data-type
Missing Information / Questions for User
Can you confirm which specific ClickHouse data types expose the wrong array element type? (e.g. Nullable(Float64), Nullable(String), Nullable(UInt8), …)
Is the regression limited to reading via the binary/RowBinary path, or does it also affect the Native format reader (NativeFormatReader)?
What server version are you running? (Some newer types like Dynamic/Geometry were added in later ClickHouse releases and the branch condition may need version-gating.)
Tests to Add
Test 1: Nullable Double array returns Double[] not Object[]
// In BinaryStreamReaderTest (client-v2)@TestvoidtestNullableDoubleArrayElementType() throwsException {
// Arrange: build a ClickHouseColumn for Nullable(Float64)ClickHouseColumncol = ClickHouseColumn.of("v", "Array(Nullable(Float64))");
ClickHouseColumnitemCol = col.getArrayBaseColumn(); // Nullable(Float64)// Write a small binary payload: length=2, two non-null doublesByteArrayOutputStreambuf = newByteArrayOutputStream();
// (write RowBinary encoding for [1.0, 2.0] with nullable prefix bytes 0)buf.write(0); writeDouble(buf, 1.0);
buf.write(0); writeDouble(buf, 2.0);
BinaryStreamReaderreader = newBinaryStreamReader(
newDataInputStream(newByteArrayInputStream(buf.toByteArray())), ...);
BinaryStreamReader.ArrayValueresult = reader.readArrayItem(itemCol, 2);
assertEquals(Double.class, result.getItemType(),
"Nullable(Float64) array should use Double.class, not Object.class");
}
Test 2: Nullable String array retains Object[] (String is non-primitive, but nullable)
@TestvoidtestNullableStringArrayElementType() throwsException {
ClickHouseColumnitemCol = ClickHouseColumn.of("v", "Nullable(String)");
// write two non-null stringsBinaryStreamReader.ArrayValueresult = reader.readArrayItem(itemCol, 2);
// String.class is not primitive, so getPrimitiveClass() == String.class -> use String.classassertEquals(String.class, result.getItemType());
}
That is my fault - I've missed that we start bounding type to unrelated V1 mapping.
BinaryStreamReader is the internal class that should read things fast and any other conversion should be done in reader if needed.
We need to review this part again and do more testing to avoid breaking other types (I have a PR testing encoding)
Sorry about that.
Recommendation: Keep open — fix needed
After the revert in #3343 (first release v0.11.2), client-v2 gives Object[] again. #3395 is the same defect, seen through getStringArray(): one fix can close both.
Category: Bug
Classification: impact: none · area: Data types & formats (Array(Nullable(T)))
Status on main: Reproduced on main — getObject() gives an ArrayValue of Object[] for Array(Nullable(Float64)); v0.11.1 gave Double[].
Breaking change: No — Double[] is still an Object[], but docs/ai-review.md:63 treats a more specific returned class as a behavior change.
Duplicates / related: No others.
Analysis:BinaryStreamReader.java:801 makes an Object[] for every Nullable, Variant, Dynamic, and Geometry element type; for the other element types it uses the class of the first value. GenericRecord.getObject() returns this ArrayValue with no conversion. The JDBC Array of jdbc-v2 already gives Double[].
Activity
[-]BinaryStreamReader.ArrayValue wrong type[/-][+]BinaryStreamReader.ArrayValue wrong return type[/+]chernser commentedon May 1, 2026
@hakim-dc
thank you for pointing to the issue!
Will work on it soon.
github-actions commentedon Jun 16, 2026
Triage Report
Size: Small
Type: Bug
Affected Module: client-api-v2
Summary
BinaryStreamReader.readArrayItemunconditionally usesObject.classas the element type for nullable and Variant/Dynamic/Geometry columns, so aNullable(Float64)array is returned asObject[]instead ofDouble[]. The fix is to derive the correct wrapper class fromClickHouseDataType.getPrimitiveClass()and fall back toObject.classonly when the type is truly primitive (since primitives cannot hold null).Recommended Labels & Priority
Missing Information / Questions for User
Nullable(Float64),Nullable(String),Nullable(UInt8), …)NativeFormatReader)?Dynamic/Geometrywere added in later ClickHouse releases and the branch condition may need version-gating.)Tests to Add
Test 1: Nullable Double array returns Double[] not Object[]
Test 2: Nullable String array retains Object[] (String is non-primitive, but nullable)
kishansinghifs1 commentedon Jun 16, 2026
Hiii @chernser can I work on this ?
chernser commentedon Jun 16, 2026
@kishansinghifs1
yes, please go ahead.
kishansinghifs1 commentedon Jun 19, 2026
Hiii @chernser PTAL : Issue:2846.
chernser commentedon Jul 9, 2026
@kishansinghifs1
Please go ahead with implementation.
Thanks!
chernser commentedon Nov 13, 2026
@hakim-dc @kishansinghifs1
I have to revert the fix because of issues:
That is my fault - I've missed that we start bounding type to unrelated V1 mapping.
BinaryStreamReader is the internal class that should read things fast and any other conversion should be done in reader if needed.
We need to review this part again and do more testing to avoid breaking other types (I have a PR testing encoding)
Sorry about that.
polyglotAI-bot commentedon Nov 27, 2026
Recommendation: Keep open — fix needed
After the revert in #3343 (first release v0.11.2), client-v2 gives
Object[]again. #3395 is the same defect, seen throughgetStringArray(): one fix can close both.main: Reproduced on main —getObject()gives anArrayValueofObject[]forArray(Nullable(Float64)); v0.11.1 gaveDouble[].Double[]is still anObject[], butdocs/ai-review.md:63treats a more specific returned class as a behavior change.Analysis:
BinaryStreamReader.java:801makes anObject[]for everyNullable,Variant,Dynamic, andGeometryelement type; for the other element types it uses the class of the first value.GenericRecord.getObject()returns thisArrayValuewith no conversion. The JDBCArrayof jdbc-v2 already givesDouble[].Reproduction: complete program and output
Output on
main(8480ca0), ClickHouse 26.11.2.4:Output with the released
clickhouse-jdbc0.11.1 (the same server):Output with the released
clickhouse-jdbc0.11.2 (the same server):Automated triage by Polyglot AI. A maintainer makes the final decision.