Repository navigation
[jdbc-v2] Fix getArray for arrays of geo types - #3379
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
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.
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
ResultSet#getArrayandResultSet#getObjectthrewSQLExceptionfor an array of a geo type, for exampleArray(Ring),Array(Polygon),Array(Geometry),Array(Nullable(Point))orArray(Array(Ring)). The cause was aNullPointerExceptionin the constructor ofcom.clickhouse.jdbc.types.Array.JdbcUtils.converttakes the element class fromconvertToJavaClass(baseType). For every geo type this isjava.sql.Array.convertListthen converted each element withconvert(value, java.sql.Array.class), which has no column, sonew Array(null, ...)failed. The fix keeps the elements as read when the element class isjava.sql.Array. The conversion has no element column, so it cannot build anArrayfor an element. Only base types that map tojava.sql.Arraytake 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.
getArrayandgetObjectnow return ajava.sql.Array. ItsgetArray()is anObject[]of nested Java arrays, for example adouble[][]for eachRing, which is the class thatgetObjectreturns for aRingcolumn. ANULLelement isnull.getBaseTypeName()is the element type, for exampleRing, andgetBaseType()isTypes.ARRAY.getResultSet()returns each element as ajava.sql.Arraywith the geo type. One result changes. For an empty array or an array with onlyNULLelements,getArray()returned ajava.sql.Array[]and now returns anObject[]. That array could never hold a non-null element. There is no API change.docs/features.mddoes not describe arrays of geo types, so it does not change.Array(Point)andArray(Array(Point))still fail in client-v2BinaryStreamReaderwitharray element type mismatch. This happens before the JDBC conversion and is a separate bug.Tests.
JdbcDataTypeTests#testArrayOfGeoTypeshas 9 rows,Array(Ring)with an empty ring,Array(LineString),Array(MultiPoint),Array(Polygon),Array(MultiLineString),Array(MultiPolygon),Array(Geometry)with aNULLelement,Array(Nullable(Point))with aNULLelement andArray(Array(Ring)). Each row writes(rowId Int32, geom <type>, tail Int64), reads it withgetArrayandgetObject, and checks the base type name, the base type, the element values and the columns before and after the array. TheMultiPointrow is skipped before 26.8, theGeometryrow before 25.11 and theNullable(Point)row before 26.9. All 9 rows fail on main with theNullPointerExceptionand 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[]vsjava.sql.Array[]).Overview
Fixes jdbc-v2 so
ResultSet#getArrayandgetObjectwork on columns typed as arrays of geo shapes (e.g.Array(Ring),Array(Polygon),Array(Geometry),Array(Nullable(Point)), nestedArray(Array(Ring))). Previously each element was converted asjava.sql.Array, which triggered a NullPointerException incom.clickhouse.jdbc.types.Arraybecause nested geo values have no per-element column metadata.JdbcUtils.convertnow detects when the array base type maps tojava.sql.Arrayand keeps elements as already-read nested Java arrays (Objectconversion) instead of wrapping them again. The outer value is still ajava.sql.ArraywhosegetArray()is anObject[]of nested coordinate arrays (andnullfor NULL elements), withgetBaseTypeName()reporting the geo element type.Adds integration coverage in
JdbcDataTypeTests#testArrayOfGeoTypes(nine geo array variants, version skips where needed) and a changelog note inhistory/latest/3378.md.Reviewed by Cursor Bugbot for commit 0878ce0. Bugbot is set up for automated code reviews on this repo. Configure here.