Skip to content

Commit ffdba68

Browse files
authored
Fix ANY ARRAY bug (#90)
1 parent 0d44c5d commit ffdba68

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

hoptimator-util/src/main/java/com/linkedin/hoptimator/util/DataTypeUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public static RelDataType flatten(RelDataType dataType, RelDataTypeFactory typeF
3939

4040
private static void flattenInto(RelDataTypeFactory typeFactory, RelDataType dataType,
4141
RelDataTypeFactory.Builder builder, List<String> path) {
42-
if (dataType.getComponentType() != null && (dataType.getComponentType().isStruct()
43-
|| dataType.getComponentType().getComponentType() != null)) {
42+
if (dataType.getComponentType() != null && dataType.getComponentType().isStruct()) {
4443
// demote complex arrays to just `ANY ARRAY`
4544
builder.add(path.stream().collect(Collectors.joining("$")), typeFactory.createArrayType(
4645
typeFactory.createSqlType(SqlTypeName.ANY), -1));

hoptimator-util/src/test/java/com/linkedin/hoptimator/util/TestDataTypeUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,20 @@ public void flattenNestedArrays() {
6363
RelDataTypeFactory.Builder builder3 = new RelDataTypeFactory.Builder(typeFactory);
6464
builder3.add("FOO", typeFactory.createArrayType(builder1.build(), -1));
6565
builder3.add("BAR", typeFactory.createArrayType(builder2.build(), -1));
66+
builder3.add("CAR", typeFactory.createArrayType(
67+
typeFactory.createSqlType(SqlTypeName.FLOAT), -1));
6668
RelDataType rowType = builder3.build();
67-
Assertions.assertEquals(2, rowType.getFieldList().size());
69+
Assertions.assertEquals(3, rowType.getFieldList().size());
6870
RelDataType flattenedType = DataTypeUtils.flatten(rowType, typeFactory);
69-
Assertions.assertEquals(2, flattenedType.getFieldList().size());
71+
Assertions.assertEquals(3, flattenedType.getFieldList().size());
7072
List<String> flattenedNames = flattenedType.getFieldList().stream().map(x -> x.getName())
7173
.collect(Collectors.toList());
72-
Assertions.assertIterableEquals(Arrays.asList(new String[]{"FOO", "BAR"}),
74+
Assertions.assertIterableEquals(Arrays.asList(new String[]{"FOO", "BAR", "CAR"}),
7375
flattenedNames);
7476
String flattenedConnector = new ScriptImplementor.ConnectorImplementor("T1",
7577
flattenedType, Collections.emptyMap()).sql();
7678
Assertions.assertEquals("CREATE TABLE IF NOT EXISTS `T1` (`FOO` ANY ARRAY, "
77-
+ "`BAR` ANY ARRAY) WITH ();", flattenedConnector,
79+
+ "`BAR` ANY ARRAY, `CAR` FLOAT ARRAY) WITH ();", flattenedConnector,
7880
"Flattened connector should have simplified arrays");
7981
}
8082
}

0 commit comments

Comments
 (0)