Repository navigation
[jdbc-v2] Fix Array#getResultSet() for createArrayOf arrays and geo values - #3376
Open
Indian-boult wants to merge 2 commits into
Open
Indian-boult wants to merge 2 commits into
Indian-boult wants to merge 2 commits into
Conversation
ArrayResultSet.elementColumn() used getNestedColumns().get(0) as the element of every column that is not Nested and not a one level array. A column from Connection#createArrayOf is the element type itself, and a geo column has no nested columns. So getResultSet() threw an unchecked IndexOutOfBoundsException for a scalar element type and for Point, Ring, LineString, MultiPoint, Polygon, MultiLineString and MultiPolygon values. For a Tuple or Map element type the VALUE column got the first tuple field or the map key. A column without an array level is now the element type itself, the same as in types.Array. A geo column maps to its geo element type. Ring, LineString and MultiPoint map to Point, Polygon to Ring, MultiLineString to LineString, MultiPolygon to Polygon and Point to Float64. Closes ClickHouse#3216
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 2c72dd6. Configure here.
AI review gate — AI review passedClean review from: Cursor Bugbot. |
A geo column without an array level now maps to its part type, so
createArrayOf("Ring", rings) got the VALUE type Point. An array created
with a geo element type holds whole geo values. createArrayOf now gives
such an array the column of Array(T), the same as an array of that type
read from the server, so its VALUE column is T and the elements of each
value still map to the part type.
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
java.sql.Array#getResultSet()andgetResultSet(long, int)failed for an array whose column has no array level.Connection#createArrayOf(typeName, ...)creates such an array, because it builds the column from the element type.ResultSet#getArrayon a geo column also creates one, because a geo column has no array level and no nested columns.ArrayResultSet.elementColumn()usedgetNestedColumns().get(0)as the element of every column that is notNestedand not a one level array. For a scalar type and for a geo type that list is empty, so the constructor threw an uncheckedIndexOutOfBoundsException. For aTupleorMaptype the list holds the tuple fields or the map key and value, so theVALUEcolumn got the first field or the key, andgetObject(2)failed withSQLException.The fix handles a column without an array level before that fallback. A geo column maps to its geo element type.
Ring,LineStringandMultiPointmap toPoint,Polygonmaps toRing,MultiLineStringmaps toLineString,MultiPolygonmaps toPolygon, andPointmaps to itsFloat64coordinates. This is what ClickHouse 26.10 returns fortoTypeName(x[1]). 25.8 returns the plain names, for exampleTuple(Float64, Float64)for an element of aRing, which is the same type. Any other column is the element type itself.types.Arrayalready treats such a column as its base column, sogetBaseTypeName()and theVALUEcolumn now agree.Nested, one level arrays,QBitand arrays with two or more levels keep the current code path. The geo element columns are built once, so the per row path does not parse type names.getBaseTypeName()andgetBaseType()do not change. For a geo value,getBaseTypeName()still reports the geo type, for exampleRing, which the existing geo tests inJdbcDataTypeTestscheck. TheVALUEcolumn reports the element type, for examplePoint. The arrays thatgetObject(2)returns for that column reportPointfromgetBaseTypeName(), the same asgetArrayon aPointcolumn. ForcreateArrayOf, theVALUEcolumn has the same type name, SQL type and class name as theVALUEcolumn of the sameArray(T)read from the server.Compatibility. There is no API change. Calls that threw before now return a result set. One result changes for values read with
getArray. For aTupleorGeometryvalue, theVALUEcolumn reported the first tuple field or the first variant,LineString. It now reports theTuple(...)orGeometrytype, the same asgetBaseTypeName().getObject(2)returns the same values as before. ForTuple(Int32, Int32)theVALUESQL type changes fromINTEGERtoOTHERand the class name fromjava.lang.Integertojava.lang.Object.createArrayOfwith aVariantelement type now reports theVarianttype, not its first member.docs/features.mddoes not describe theVALUEcolumn for these arrays, so it does not change.Tests. The new tests are integration tests, because the expected element types come from the server.
ConnectionTest#testCreateArrayOfResultSetMatchesReadArrayhas 7 rows,Int32, an emptyInt32array,Nullable(String)with a null element,LowCardinality(String),Date,Tuple(String, Int8)andMap(String, Int32). Each row comparescreateArrayOf(typeName, ...).getResultSet()withgetResultSet()of the same array read from the server asArray(typeName). It checks theVALUEtype name, SQL type and class name, agetResultSet(0, n)slice, every row, and theSQLExceptionwith messageNo current rowafter the last row.JdbcDataTypeTests#testGeoArrayResultSethas 8 rows. It reads aPoint,Ring,LineString,MultiPoint,Polygon,MultiLineString,MultiPolygonand aGeometryvalue withgetArrayand goes down throughgetResultSet()level by level to theFloat64coordinates. TheMultiPointrow is skipped before 26.8 and theGeometryrow before 25.11. All 15 rows fail without the change and pass with it on ClickHouse 26.10.4.207. The unit tests of the client and JDBC modules pass, and the fulljdbc-v2integration suite passes except 4ConnectionTesttests that need TLS on port 8443 or a custom settings prefix on the server, which fail the same way without this change.Closes #3216
Checklist
Note
Medium Risk
Changes JDBC array result-set metadata and element-type resolution for geo, tuple, and client-created arrays; behavior shifts for some previously broken or mis-reported VALUE columns, covered by new integration tests.
Overview
Fixes
java.sql.Array#getResultSet()(and sliced variants) so they work for arrays built withConnection#createArrayOfand for geo values fromResultSet#getArray, instead of throwingIndexOutOfBoundsExceptionor mis-typing theVALUEcolumn.ArrayResultSetnow treats columns with no array nesting as the true element type (matching serverArray(T)), maps geo types to their server element types (e.g.Ring→Point,Point→Float64), and keepsTuple/Map/GeometryVALUEmetadata aligned withgetBaseTypeName().ConnectionImpl#createArrayOfwraps geo element types asArray(T)so top-levelVALUEisTwhile nested element result sets still expose part types.Adds integration tests comparing
createArrayOfvs server-read arrays and geogetResultSettraversal; changelog entry for #3216.Reviewed by Cursor Bugbot for commit ad6a509. Bugbot is set up for automated code reviews on this repo. Configure here.
Update by Indian-boult, 2026-11-18. The first version mapped
createArrayOfwith a geo element type to the part type, socreateArrayOf("Ring", rings)got theVALUEtypePoint, as Cursor Bugbot found.createArrayOfnow gives an array with a geo element type the column ofArray(T), the same as an array of that type read from the server, soVALUEisTand each element still maps to its part type.ConnectionTest#testCreateArrayOfGeoElementTypecoversPoint,Ring,LineString,Polygon,MultiLineStringandMultiPolygon. All six rows failed on the first version and pass now. The change inConnectionImplsits next to the line that #3363 changes, and the two branches merge without conflicts.