Skip to content

Commit d60246f

Browse files
authored
Fixed ResultSetMetadata for SEA inline mode (#1010)
## Description <!-- Provide a brief summary of the changes made and the issue they aim to address.--> For SEA this type is parsed later using a function. So we need not strip the base type here. So reverted the code to use stripTypeName instead. But the stripTypeName function isn't correct either since it will incorrectly convert ARRAY<DECIMAL(10,2)> to ARRAY<DECIMAL and later parse it incorrectly. ## Testing <!-- Describe how the changes have been tested--> Tested the SQL smoke test locally ## Additional Notes to the Reviewer <!-- Share any additional context or insights that may help the reviewer understand the changes better. This could include challenges faced, limitations, or compromises made during the development process. Also, mention any areas of the code that you would like the reviewer to focus on specifically. --> NO_CHANGELOG=true
1 parent ccf62a9 commit d60246f

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

development/.release-freeze.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"freeze": true,
33
"reason": "Releasing JDBC - 16th Sep",
4-
"allow_list": ["jayantsing-db/default-max-rows-per-block"]
4+
"allow_list": ["jayantsing-db/default-max-rows-per-block", "ResultSetMetadataFix"]
55
}

src/main/java/com/databricks/jdbc/api/impl/DatabricksResultSetMetaData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public DatabricksResultSetMetaData(
108108
.columnTypeClassName(DatabricksTypeUtil.getColumnTypeClassName(columnTypeName))
109109
.columnType(columnType)
110110
.columnTypeText(
111-
metadataResultSetBuilder.stripBaseTypeName(
111+
metadataResultSetBuilder.stripTypeName(
112112
columnInfo
113113
.getTypeText())) // store base type eg. DECIMAL instead of DECIMAL(7,2)
114114
.typePrecision(precision)

src/test/java/com/databricks/jdbc/api/impl/DatabricksResultSetMetaDataTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,37 @@ public void testCloudFetchUsedSdk() {
413413
assertFalse(metaData.getIsCloudFetchUsed());
414414
}
415415

416+
@Test
417+
public void testSEAInlineComplexType() throws SQLException {
418+
ResultManifest resultManifest = new ResultManifest();
419+
resultManifest.setTotalRowCount(1L);
420+
ResultSchema schema = new ResultSchema();
421+
schema.setColumnCount(3L);
422+
423+
ColumnInfo arrayColumn = getColumn("array_col", ColumnInfoTypeName.ARRAY, "ARRAY<INT>");
424+
ColumnInfo structColumn =
425+
getColumn("struct_col", ColumnInfoTypeName.STRUCT, "STRUCT<field1:INT,field2:STRING>");
426+
ColumnInfo mapColumn = getColumn("map_col", ColumnInfoTypeName.MAP, "MAP<STRING,INT>");
427+
428+
schema.setColumns(List.of(arrayColumn, structColumn, mapColumn));
429+
resultManifest.setSchema(schema);
430+
431+
DatabricksResultSetMetaData metaData =
432+
new DatabricksResultSetMetaData(STATEMENT_ID, resultManifest, false, connectionContext);
433+
434+
assertEquals("ARRAY<INT>", metaData.getColumnTypeName(1));
435+
assertEquals("STRUCT<field1:INT,field2:STRING>", metaData.getColumnTypeName(2));
436+
assertEquals("MAP<STRING,INT>", metaData.getColumnTypeName(3));
437+
438+
assertEquals("array_col", metaData.getColumnName(1));
439+
assertEquals("struct_col", metaData.getColumnName(2));
440+
assertEquals("map_col", metaData.getColumnName(3));
441+
442+
assertEquals(Types.ARRAY, metaData.getColumnType(1));
443+
assertEquals(Types.STRUCT, metaData.getColumnType(2));
444+
assertEquals(Types.VARCHAR, metaData.getColumnType(3));
445+
}
446+
416447
private void verifyDefaultMetadataProperties(
417448
DatabricksResultSetMetaData metaData, StatementType type) throws SQLException {
418449
for (int i = 1; i <= metaData.getColumnCount(); i++) {

0 commit comments

Comments
 (0)