Skip to content

Commit

Permalink
SNOW-1416051: Fix getObject for array in json (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed May 21, 2024
1 parent 23db457 commit ffb87d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ static ColumnTypeInfo getSnowflakeType(
break;

case ARRAY:
int columnType = isStructuredType ? Types.ARRAY : Types.VARCHAR;
columnTypeInfo =
new ColumnTypeInfo(Types.ARRAY, defaultIfNull(extColTypeName, "ARRAY"), baseType);
new ColumnTypeInfo(columnType, defaultIfNull(extColTypeName, "ARRAY"), baseType);
break;

case MAP:
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/ResultSetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1056,4 +1056,22 @@ public void testNextNegative() throws SQLException {
}
}
}

/** SNOW-1416051; Added in > 3.16.0 */
@Test
public void shouldSerializeArrayAndObjectAsStringOnGetObject() throws SQLException {
try (Connection connection = init();
Statement statement = connection.createStatement();
ResultSet resultSet =
statement.executeQuery(
"select ARRAY_CONSTRUCT(1,2,3), OBJECT_CONSTRUCT('a', 4, 'b', 'test')")) {
assertTrue(resultSet.next());
String expectedArrayAsString = "[\n 1,\n 2,\n 3\n]";
assertEquals(expectedArrayAsString, resultSet.getObject(1));
assertEquals(expectedArrayAsString, resultSet.getString(1));
String expectedObjectAsString = "{\n \"a\": 4,\n \"b\": \"test\"\n}";
assertEquals(expectedObjectAsString, resultSet.getObject(2));
assertEquals(expectedObjectAsString, resultSet.getString(2));
}
}
}

0 comments on commit ffb87d7

Please sign in to comment.