Skip to content

[jdbc-v2] Fix getArray for arrays of geo types - #3379

Open
Indian-boult wants to merge 1 commit into
ClickHouse:mainfrom
Indian-boult:fix/jdbc-geo-array-elements
Open

Indian-boult wants to merge 1 commit into
ClickHouse:mainfrom
Indian-boult:fix/jdbc-geo-array-elements

Conversation

@Indian-boult

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

Copy link
Copy Markdown

Summary

ResultSet#getArray and ResultSet#getObject threw SQLException for an array of a geo type, for example Array(Ring), Array(Polygon), Array(Geometry), Array(Nullable(Point)) or Array(Array(Ring)). The cause was a NullPointerException in the constructor of com.clickhouse.jdbc.types.Array.

JdbcUtils.convert takes the element class from convertToJavaClass(baseType). For every geo type this is java.sql.Array. convertList then converted each element with convert(value, java.sql.Array.class), which has no column, so new Array(null, ...) failed. The fix keeps the elements as read when the element class is java.sql.Array. The conversion has no element column, so it cannot build an Array for an element. Only base types that map to java.sql.Array take the new branch, and for those a non-null element always failed before. The check runs once for each value, not for each element.

Behavior. getArray and getObject now return a java.sql.Array. Its getArray() is an Object[] of nested Java arrays, for example a double[][] for each Ring, which is the class that getObject returns for a Ring column. A NULL element is null. getBaseTypeName() is the element type, for example Ring, and getBaseType() is Types.ARRAY. getResultSet() returns each element as a java.sql.Array with the geo type. One result changes. For an empty array or an array with only NULL elements, getArray() returned a java.sql.Array[] and now returns an Object[]. That array could never hold a non-null element. There is no API change. docs/features.md does not describe arrays of geo types, so it does not change.

Array(Point) and Array(Array(Point)) still fail in client-v2 BinaryStreamReader with array element type mismatch. This happens before the JDBC conversion and is a separate bug.

Tests. JdbcDataTypeTests#testArrayOfGeoTypes has 9 rows, Array(Ring) with an empty ring, Array(LineString), Array(MultiPoint), Array(Polygon), Array(MultiLineString), Array(MultiPolygon), Array(Geometry) with a NULL element, Array(Nullable(Point)) with a NULL element and Array(Array(Ring)). Each row writes (rowId Int32, geom <type>, tail Int64), reads it with getArray and getObject, and checks the base type name, the base type, the element values and the columns before and after the array. The MultiPoint row is skipped before 26.8, the Geometry row before 25.11 and the Nullable(Point) row before 26.9. All 9 rows fail on main with the NullPointerException and pass with the fix on ClickHouse 26.10.

Closes #3378

Checklist


Note

Low Risk
Targeted JDBC read-path conversion fix for geo array columns with broad integration tests; minor behavior change only for empty/all-null geo arrays (Object[] vs java.sql.Array[]).

Overview
Fixes jdbc-v2 so ResultSet#getArray and getObject work on columns typed as arrays of geo shapes (e.g. Array(Ring), Array(Polygon), Array(Geometry), Array(Nullable(Point)), nested Array(Array(Ring))). Previously each element was converted as java.sql.Array, which triggered a NullPointerException in com.clickhouse.jdbc.types.Array because nested geo values have no per-element column metadata.

JdbcUtils.convert now detects when the array base type maps to java.sql.Array and keeps elements as already-read nested Java arrays (Object conversion) instead of wrapping them again. The outer value is still a java.sql.Array whose getArray() is an Object[] of nested coordinate arrays (and null for NULL elements), with getBaseTypeName() reporting the geo element type.

Adds integration coverage in JdbcDataTypeTests#testArrayOfGeoTypes (nine geo array variants, version skips where needed) and a changelog note in history/latest/3378.md.

Reviewed by Cursor Bugbot for commit 0878ce0. Bugbot is set up for automated code reviews on this repo. Configure here.

ResultSet#getArray and ResultSet#getObject threw SQLException for
Array(Ring), Array(Geometry) and other arrays of geo types. The cause was
a NullPointerException in the constructor of
com.clickhouse.jdbc.types.Array.

JdbcUtils.convert took the element class from convertToJavaClass, which
is java.sql.Array for every geo type. convertList then converted each
element with convert(value, java.sql.Array.class), which has no column,
and new Array(null, ...) failed.

Keep the elements as read when the element class is java.sql.Array.
getArray() of the result is now an Object[] of nested Java arrays, for
example a double[][] for each Ring.
@Indian-boult
Indian-boult requested review from a team and mzitnik as code owners November 18, 2026 04:50
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] getArray and getObject throw NullPointerException for Array(Ring), Array(Geometry) and other arrays of geo types

1 participant