Repository navigation
Fix jdbc-v2: read Array(Nested(...)) columns - #3188
Open
polyglotAI-bot wants to merge 1 commit into
Open
polyglotAI-bot wants to merge 1 commit into
polyglotAI-bot wants to merge 1 commit into
Conversation
ResultSet#getObject/getArray on an Array(Nested(...)) column threw IllegalStateException "There is a child array at depth 0 where it is not expected". A Nested(...) value is an array of tuples, but JdbcUtils.convert passed only the Array levels of the column to convertList, so the list of tuples of each Nested value looked like an unexpected extra dimension. Count the Nested level as one more array dimension and keep its tuples as is, the same as Array(Array(Tuple)). Fixes: #3178 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
Client V1 CoverageCoverage Report
Class Coverage
|
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.



Description
Fixes #3178.
ResultSet#getObject/getArrayon anArray(Nested(...))column threwIllegalStateException: There is a child array at depth 0 where it is not expected.Root cause. The JDBC reader returns an
Arraycolumn as aList. AnArray(Nested(k String, v String))value is thereforeList<List<Object[]>>: eachNestedvalue is a list of tuples.JdbcUtils.convertpassedcolumn.getArrayNestedLevel()(1) toconvertListas the number of dimensions. That count includes only theArraylevels, not theNestedlevel. The base typeNestedmaps tojava.sql.Array. SoconvertListfound aListat its last level and threw.Fix. A
Nested(...)base column is an array of tuples (the same wire layout asArray(Tuple(...))). It now counts as one more array dimension, and its tuples are converted the same way as the tuples ofArray(Array(Tuple(...))). The column is now returned as ajava.sql.Arraywhose elements are the nested values (each anObject[]of tuples).getResultSet()returns each element as ajava.sql.Array, which is the same as reading a top-levelNested(...)column.Changes
JdbcUtils.convert: new private helpergetArrayDimensions(column)counts aNestedbase column as one more dimension. BothListbranches use it:java.sql.Arraytargets (getArray,getObject) and the typed-element branch (getObject(col, Class)). For aNestedbase the element class is the class ofTuple.history/latest/3178.md: change record.docs/features.md: one sentence about how anArray(Nested(...))column is read.No public API change. Columns that are not
Nested-based go through the same calls as before.Test
JdbcDataTypeTests.testArrayOfNestedType(integration). The table hasorder Int8, an Array(Nested(a Int8, b Nullable(String))), aan Array(Array(Nested(...))), aat Array(Array(Tuple(a Int8, b Nullable(String)))), tail Int32.Nestedvalues that are non-empty, empty, and contain aNULLfield. Row 2 has empty outer arrays. The test asserts every column of both rows.anis read throughgetArrayandgetObject. Each element is checked as raw data and throughgetResultSet().getObject(2), where it must be ajava.sql.Arraywith the expected tuples.aancovers aNestedbase below twoArraylevels.aat(Array(Array(Tuple)), same layout) is the contrast case. It uses the unchanged code path, andanmust equal it (Arrays.deepEquals) throughgetArray()and throughgetObject(col, Object[].class).Without the fix the test fails with the reported
IllegalStateException. With the fix it passes. jdbc-v2 unit tests: 1963 pass. Integration tests (JdbcDataTypeTests,ArrayResultSetTest,ResultSetImplTest,PreparedStatementTest,JdbcUtilsTest,StatementTest): 286 of 288 pass. The 2 others (StatementTest#testSetConnectionSchema,#testSwitchDatabase) fail the same way onmainwhen run again on a database that is not fresh (DATABASE_ALREADY_EXISTS). No existing test was changed.Pre-PR validation gate
main, passes on branch)ResultSetImpl#getObject→JdbcUtils.convert)history/latest/3178.md);docs/features.mdupdatedAGENTS.md/docs/changes_checklist.mdchanges_checklist.md— Conditional logic or guard changedNestedvalue, and aNULLtuple field are tested. ANestedcolumn cannot beNullable, so a null element cannot occur.Nested, which always threw before. No other output changes.convertList/convertArrayare not changed, so theirIllegalStateExceptionfor a list or array that is too deep with a scalar element type stays (pinned byJdbcUtilsTest).Compatibility
There is no breaking change. Only reads that threw before now return a value.
Out of scope
BinaryStreamReader.ArrayValuebranch (convertArray) is not changed. In JDBC,Arraycolumns always arrive asList(the default type hint), soArray(Nested)never gets to that branch.getStringon a column that holds tuples printsObject[]identity strings. This is the separate tuple-rendering issue Regression in JDBC 0.9.8 when reading Array(Tuple(...)) with named tuple elements. #3045.🤖 Generated with Claude Code