Repository navigation
[client-v2] Fix reading Array(Point) and Array(Array(Point)) - #3381
Open
Indian-boult wants to merge 1 commit into
Open
Indian-boult wants to merge 1 commit into
Indian-boult wants to merge 1 commit into
Conversation
A Point is read as a double[]. A non-empty Array(Point) takes the class of its first element, and the ArrayValue constructor allocated an Object[][] for every array class. A double[] is not an Object[], so the read failed with "array element type mismatch" and the row was lost. The same happened for an Array(Point) inside a Map, Tuple, Variant or Dynamic value, and in jdbc-v2 ResultSet#next(). ArrayValue now allocates an Object[] when the element class is an array of a primitive type. Elements that are arrays of objects, such as a Ring, keep their Object[][]. The points stay double[], the same as in Array(Nullable(Point)) and in an empty Array(Point). Closes ClickHouse#3380
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
Array(Point)orArray(Array(Point))failed withIllegalArgumentException: array element type mismatchinClient#queryAll, the binary readers and jdbc-v2ResultSet#next(). AnArray(Point)inside aMap,Tuple,VariantorDynamicvalue failed the same way. APointis read asdouble[], andArrayValueallocated anObject[][]for every array element class. It now allocates anObject[]when the element is an array of a primitive type. The points staydouble[], the same as inArray(Nullable(Point))and an emptyArray(Point). Other arrays keep their classes and allocations. The new check runs once per array and only when the element class is an array.The
Nativereader does not decode the Native layout of arrays of tuples, which is #3156. For anArray(Point)with more than one point in a block it now returns wrong values, as it does forArray(Tuple(Float64, Float64)), instead of throwing. In jdbc-v2,getArrayandgetObjectof these columns also need #3378.Tests.
DataTypeTests#testReadArrayOfPointsandJdbcDataTypeTests#testReadArrayOfPointsreadArray(Point)andArray(Array(Point))with anInt64column after the array and check the whole row. All 4 rows fail on main and pass with the fix.Closes #3380
Checklist
Note
Medium Risk
Changes core array allocation in the binary reader used by client-v2 and jdbc-v2; scope is narrow but any regression in nested array handling could affect many types.
Overview
Fixes
Array(Point)andArray(Array(Point))decoding in client-v2 (and jdbc-v2 via the shared binary reader), which previously threwIllegalArgumentException: array element type mismatchand could drop whole rows inClient#queryAll, binary readers, andResultSet#next(). Points are materialized asdouble[], but nested array backing storage always usedObject[][], which cannot hold primitive-array elements.ArrayValuenow allocates anObject[]when the declared element type is an array whose component type is primitive (e.g.double[]forPoint), while non-primitive array elements still useObject[][]. Each point remains adouble[], consistent with emptyArray(Point)andArray(Nullable(Point)).Adds integration coverage in
DataTypeTests#testReadArrayOfPointsandJdbcDataTypeTests#testReadArrayOfPointsfor flat and nested point arrays, including a trailing column to ensure the full row is read. Documents the fix inhistory/latest/3380.md; notes related Native-format limitations (#3156).Reviewed by Cursor Bugbot for commit a885b85. Bugbot is set up for automated code reviews on this repo. Configure here.