diff --git a/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java b/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java index a38a8199..cb92c02d 100644 --- a/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java +++ b/src/main/java/com/firebolt/jdbc/resultset/column/ColumnType.java @@ -41,6 +41,8 @@ public class ColumnType { private static final Set TIMEZONES = Arrays.stream(TimeZone.getAvailableIDs()) .collect(Collectors.toCollection(HashSet::new)); private static final Pattern COMMA_WITH_SPACES = Pattern.compile("\\s*,\\s*"); + // Regex to split on comma and ignoring commas that are between parenthesis + private static final String COMPLEX_TYPE_PATTERN = ",(?![^()]*\\))"; @EqualsAndHashCode.Exclude String name; FireboltDataType dataType; @@ -109,10 +111,9 @@ private static List getCollectionSubType(FireboltDataType fireboltDa } if (fireboltDataType.equals(TUPLE)) { - types = typeWithoutNullKeyword.split(",(?![^()]*\\))"); // Regex to split on comma and ignoring comma that are between - // parenthesis + types = typeWithoutNullKeyword.split(COMPLEX_TYPE_PATTERN); } else if (fireboltDataType.equals(STRUCT)) { - types = typeWithoutNullKeyword.split(","); + types = typeWithoutNullKeyword.split(COMPLEX_TYPE_PATTERN); } else { types = new String[] {typeWithoutNullKeyword}; } diff --git a/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java b/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java index 83312636..63ae686e 100644 --- a/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java +++ b/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java @@ -1490,8 +1490,8 @@ void shouldReturnStruct() throws SQLException { assertEquals("{\"a\":\"1\"}", resultSet.getObject("a_struct")); assertEquals("{\"a\":[1,2,3]}", resultSet.getObject(5)); assertEquals("{\"a\":[1,2,3]}", resultSet.getObject("array_struct")); - assertEquals("{\"x\":\"2\",\"a\":{\"b\":\"1\"}}", resultSet.getObject(6)); - assertEquals("{\"x\":\"2\",\"a\":{\"b\":\"1\"}}", resultSet.getObject("nested_struct")); + assertEquals("{\"x\":\"2\",\"a\":{\"b\":\"1\",\"c\":\"3\"}}", resultSet.getObject(6)); + assertEquals("{\"x\":\"2\",\"a\":{\"b\":\"1\",\"c\":\"3\"}}", resultSet.getObject("nested_struct")); // Returns native JDBC type for (int i = 2; i <= 6; i++) { assertEquals(Types.VARCHAR, resultSet.getMetaData().getColumnType(i)); @@ -1501,7 +1501,7 @@ void shouldReturnStruct() throws SQLException { assertEquals("STRUCT(A INT)", resultSet.getMetaData().getColumnTypeName(3)); assertEquals("STRUCT(A INT)", resultSet.getMetaData().getColumnTypeName(4)); assertEquals("STRUCT(A ARRAY(INT))", resultSet.getMetaData().getColumnTypeName(5)); - assertEquals("STRUCT(X INT, A STRUCT(B INT))", resultSet.getMetaData().getColumnTypeName(6)); + assertEquals("STRUCT(X INT, A STRUCT(B INT, C INT))", resultSet.getMetaData().getColumnTypeName(6)); } @Test diff --git a/src/test/resources/responses/firebolt-response-with-struct-nofalse b/src/test/resources/responses/firebolt-response-with-struct-nofalse index c19956fa..b706be02 100644 --- a/src/test/resources/responses/firebolt-response-with-struct-nofalse +++ b/src/test/resources/responses/firebolt-response-with-struct-nofalse @@ -1,4 +1,4 @@ id null_struct an_empty_struct a_struct array_struct nested_struct -Int64 struct(a int null) struct(a int) struct(a int) struct(a array(int)) struct(x int, a struct(b int)) -1 {"a":null} {"a":"1"} {"a":[1,2,3]} {"x":"2","a":{"b":"1"}} -2 {"a":null} {"a":"2"} {"a":[1,2,3]} {"x":"2","a":{"b":"1"}} +Int64 struct(a int null) struct(a int) struct(a int) struct(a array(int)) struct(x int, a struct(b int, c int)) +1 {"a":null} {"a":"1"} {"a":[1,2,3]} {"x":"2","a":{"b":"1","c":"3"}} +2 {"a":null} {"a":"2"} {"a":[1,2,3]} {"x":"2","a":{"b":"1","c":"3"}}