Skip to content

Commit 82a0d79

Browse files
committed
Fix #76: handle lists of UDTs properly in ResultSet.getObject() methods
1 parent 8d4f030 commit 82a0d79

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1414
### Fixed
1515
- Add codec for conversion between `Short` and CQL type `tinyint` (see issue
1616
[#76](https://github.com/ing-bank/cassandra-jdbc-wrapper/issues/76)).
17+
- Handle lists of User-Defined Types (UDT) properly when using `CassandraResultSet.getObject(String|int)` methods (see
18+
issue [#76](https://github.com/ing-bank/cassandra-jdbc-wrapper/issues/76)).
1719

1820
## [4.14.0] - 2024-12-24
1921
### Added

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraResultSet.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,10 @@ public Object getObject(final int columnIndex) throws SQLException {
934934
final DataType elementsType = listType.getElementType();
935935
final List<?> resultList;
936936

937-
if (elementsType instanceof TupleType) {
937+
if (elementsType instanceof UserDefinedType) {
938+
resultList = this.currentRow.getList(columnIndex - 1,
939+
TypesMap.getTypeForComparator(DataTypeEnum.UDT.asLowercaseCql()).getType());
940+
} else if (elementsType instanceof TupleType) {
938941
resultList = this.currentRow.getList(columnIndex - 1,
939942
TypesMap.getTypeForComparator(DataTypeEnum.TUPLE.asLowercaseCql()).getType());
940943
} else {
@@ -1069,7 +1072,10 @@ public Object getObject(final String columnLabel) throws SQLException {
10691072
final DataType elementsType = listType.getElementType();
10701073
final List<?> resultList;
10711074

1072-
if (elementsType instanceof TupleType) {
1075+
if (elementsType instanceof UserDefinedType) {
1076+
resultList = this.currentRow.getList(columnLabel,
1077+
TypesMap.getTypeForComparator(DataTypeEnum.UDT.asLowercaseCql()).getType());
1078+
} else if (elementsType instanceof TupleType) {
10731079
resultList = this.currentRow.getList(columnLabel,
10741080
TypesMap.getTypeForComparator(DataTypeEnum.TUPLE.asLowercaseCql()).getType());
10751081
} else {

Diff for: src/test/java/com/ing/data/cassandra/jdbc/CollectionsUnitTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.hamcrest.CoreMatchers.is;
3939
import static org.hamcrest.MatcherAssert.assertThat;
4040
import static org.hamcrest.Matchers.instanceOf;
41+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4142
import static org.junit.jupiter.api.Assertions.assertEquals;
4243
import static org.junit.jupiter.api.Assertions.assertFalse;
4344
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -356,6 +357,9 @@ void givenFrozenTypesSelectStatement_whenExecute_getExpectedResultSet() throws E
356357
assertEquals("test", udtValue.getString("value1"));
357358
assertTrue(udtValue.getBoolean("value2"));
358359

360+
// Check retrieving a list of UDTs does not throw an exception (see issue #76).
361+
assertDoesNotThrow(() -> resultSet.getObject("innerUdt"));
362+
359363
Object outerUdt = resultSet.getObject("outerUdt");
360364
assertInstanceOf(UdtValue.class, outerUdt);
361365
assertEquals(1, ((UdtValue) outerUdt).getInt("key"));

0 commit comments

Comments
 (0)