Skip to content

[jdbc-v2] Fix Array#getResultSet() for createArrayOf arrays and geo values - #3376

Open
Indian-boult wants to merge 2 commits into
ClickHouse:mainfrom
Indian-boult:fix/array-resultset-element-column
Open

Indian-boult wants to merge 2 commits into
ClickHouse:mainfrom
Indian-boult:fix/array-resultset-element-column

Conversation

@Indian-boult

@Indian-boult Indian-boult commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

java.sql.Array#getResultSet() and getResultSet(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#getArray on a geo column also creates one, because a geo column has no array level and no nested columns.

ArrayResultSet.elementColumn() used getNestedColumns().get(0) as the element of every column that is not Nested and not a one level array. For a scalar type and for a geo type that list is empty, so the constructor threw an unchecked IndexOutOfBoundsException. For a Tuple or Map type the list holds the tuple fields or the map key and value, so the VALUE column got the first field or the key, and getObject(2) failed with SQLException.

The fix handles a column without an array level before that fallback. A geo column maps to its geo element type. Ring, LineString and MultiPoint map to Point, Polygon maps to Ring, MultiLineString maps to LineString, MultiPolygon maps to Polygon, and Point maps to its Float64 coordinates. This is what ClickHouse 26.10 returns for toTypeName(x[1]). 25.8 returns the plain names, for example Tuple(Float64, Float64) for an element of a Ring, which is the same type. Any other column is the element type itself. types.Array already treats such a column as its base column, so getBaseTypeName() and the VALUE column now agree. Nested, one level arrays, QBit and 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() and getBaseType() do not change. For a geo value, getBaseTypeName() still reports the geo type, for example Ring, which the existing geo tests in JdbcDataTypeTests check. The VALUE column reports the element type, for example Point. The arrays that getObject(2) returns for that column report Point from getBaseTypeName(), the same as getArray on a Point column. For createArrayOf, the VALUE column has the same type name, SQL type and class name as the VALUE column of the same Array(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 a Tuple or Geometry value, the VALUE column reported the first tuple field or the first variant, LineString. It now reports the Tuple(...) or Geometry type, the same as getBaseTypeName(). getObject(2) returns the same values as before. For Tuple(Int32, Int32) the VALUE SQL type changes from INTEGER to OTHER and the class name from java.lang.Integer to java.lang.Object. createArrayOf with a Variant element type now reports the Variant type, not its first member. docs/features.md does not describe the VALUE column 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#testCreateArrayOfResultSetMatchesReadArray has 7 rows, Int32, an empty Int32 array, Nullable(String) with a null element, LowCardinality(String), Date, Tuple(String, Int8) and Map(String, Int32). Each row compares createArrayOf(typeName, ...).getResultSet() with getResultSet() of the same array read from the server as Array(typeName). It checks the VALUE type name, SQL type and class name, a getResultSet(0, n) slice, every row, and the SQLException with message No current row after the last row. JdbcDataTypeTests#testGeoArrayResultSet has 8 rows. It reads a Point, Ring, LineString, MultiPoint, Polygon, MultiLineString, MultiPolygon and a Geometry value with getArray and goes down through getResultSet() level by level to the Float64 coordinates. The MultiPoint row is skipped before 26.8 and the Geometry row 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 full jdbc-v2 integration suite passes except 4 ConnectionTest tests 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 with Connection#createArrayOf and for geo values from ResultSet#getArray, instead of throwing IndexOutOfBoundsException or mis-typing the VALUE column.

ArrayResultSet now treats columns with no array nesting as the true element type (matching server Array(T)), maps geo types to their server element types (e.g. Ring → Point, Point → Float64), and keeps Tuple/Map/Geometry VALUE metadata aligned with getBaseTypeName(). ConnectionImpl#createArrayOf wraps geo element types as Array(T) so top-level VALUE is T while nested element result sets still expose part types.

Adds integration tests comparing createArrayOf vs server-read arrays and geo getResultSet traversal; 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 createArrayOf with a geo element type to the part type, so createArrayOf("Ring", rings) got the VALUE type Point, as Cursor Bugbot found. createArrayOf now gives an array with a geo element type the column of Array(T), the same as an array of that type read from the server, so VALUE is T and each element still maps to its part type. ConnectionTest#testCreateArrayOfGeoElementType covers Point, Ring, LineString, Polygon, MultiLineString and MultiPolygon. All six rows failed on the first version and pass now. The change in ConnectionImpl sits next to the line that #3363 changes, and the two branches merge without conflicts.

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
@Indian-boult
Indian-boult requested review from a team and mzitnik as code owners November 18, 2026 04:18

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 2c72dd6. Configure here.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

AI review gate — AI review passed

Clean 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jdbc-v2: Array#getResultSet() fails for createArrayOf arrays and geo columns (IndexOutOfBoundsException / wrong VALUE type)

1 participant