@@ -67,21 +67,24 @@ public void flattenUnflattenNestedArrays() {
67
67
builder3 .add ("BAR" , typeFactory .createArrayType (builder2 .build (), -1 ));
68
68
builder3 .add ("CAR" , typeFactory .createArrayType (
69
69
typeFactory .createSqlType (SqlTypeName .FLOAT ), -1 ));
70
+ builder3 .add ("DAY" , typeFactory .createArrayType (typeFactory .createArrayType (typeFactory .createArrayType (
71
+ typeFactory .createSqlType (SqlTypeName .VARCHAR ), -1 ), -1 ), -1 ));
70
72
RelDataType rowType = builder3 .build ();
71
- Assertions .assertEquals (3 , rowType .getFieldList ().size ());
73
+ Assertions .assertEquals (4 , rowType .getFieldList ().size ());
72
74
RelDataType flattenedType = DataTypeUtils .flatten (rowType , typeFactory );
73
- Assertions .assertEquals (6 , flattenedType .getFieldList ().size ());
75
+ Assertions .assertEquals (9 , flattenedType .getFieldList ().size ());
74
76
List <String > flattenedNames = flattenedType .getFieldList ().stream ().map (RelDataTypeField ::getName )
75
77
.collect (Collectors .toList ());
76
- Assertions .assertIterableEquals (Arrays .asList ("FOO" , "FOO$QUX" , "FOO$QIZ" , "BAR" , "BAR$BAZ" , "CAR" ) ,
77
- flattenedNames );
78
+ Assertions .assertIterableEquals (Arrays .asList ("FOO" , "FOO$QUX" , "FOO$QIZ" , "BAR" , "BAR$BAZ" , "CAR" , "DAY" ,
79
+ "DAY$__ARRTYPE__" , "DAY$__ARRTYPE__$__ARRTYPE__" ), flattenedNames );
78
80
String flattenedConnector = new ScriptImplementor .ConnectorImplementor ("S" , "T1" ,
79
81
flattenedType , Collections .emptyMap ()).sql ();
80
82
Assertions .assertEquals ("CREATE TABLE IF NOT EXISTS `S`.`T1` ("
81
83
+ "`FOO` ANY ARRAY, `FOO_QUX` VARCHAR, `FOO_QIZ` VARCHAR ARRAY, "
82
84
+ "`BAR` ANY ARRAY, `BAR_BAZ` VARCHAR, "
83
- + "`CAR` FLOAT ARRAY) WITH ();" , flattenedConnector ,
84
- "Flattened connector should have simplified arrays" );
85
+ + "`CAR` FLOAT ARRAY, "
86
+ + "`DAY` ANY ARRAY, `DAY___ARRTYPE__` ANY ARRAY, `DAY___ARRTYPE_____ARRTYPE__` VARCHAR ARRAY) WITH ();" ,
87
+ flattenedConnector , "Flattened connector should have simplified arrays" );
85
88
86
89
RelDataType unflattenedType = DataTypeUtils .unflatten (flattenedType , typeFactory );
87
90
RelOptUtil .eq ("original" , rowType , "flattened-unflattened" , unflattenedType , Litmus .THROW );
@@ -94,7 +97,8 @@ public void flattenUnflattenNestedArrays() {
94
97
Assertions .assertEquals ("CREATE TABLE IF NOT EXISTS `S`.`T1` ("
95
98
+ "`FOO` ROW(`QUX` VARCHAR, `QIZ` VARCHAR ARRAY) ARRAY, "
96
99
+ "`BAR` ROW(`BAZ` VARCHAR) ARRAY, "
97
- + "`CAR` FLOAT ARRAY) WITH ();" , unflattenedConnector ,
100
+ + "`CAR` FLOAT ARRAY, "
101
+ + "`DAY` VARCHAR ARRAY ARRAY ARRAY) WITH ();" , unflattenedConnector ,
98
102
"Flattened-unflattened connector should be correct" );
99
103
}
100
104
@@ -118,13 +122,13 @@ public void flattenUnflattenComplexMap() {
118
122
Assertions .assertEquals (3 , flattenedType .getFieldList ().size ());
119
123
List <String > flattenedNames = flattenedType .getFieldList ().stream ().map (RelDataTypeField ::getName )
120
124
.collect (Collectors .toList ());
121
- Assertions .assertIterableEquals (Arrays .asList ("FOO$keyType " , "FOO$valueType $QIZ$BAR" , "FOO$valueType $QIZ$CAR" ), flattenedNames );
125
+ Assertions .assertIterableEquals (Arrays .asList ("FOO$__MAPKEYTYPE__ " , "FOO$__MAPVALUETYPE__ $QIZ$BAR" , "FOO$__MAPVALUETYPE__ $QIZ$CAR" ), flattenedNames );
122
126
String flattenedConnector = new ScriptImplementor .ConnectorImplementor ("S" , "T1" ,
123
127
flattenedType , Collections .emptyMap ()).sql ();
124
128
Assertions .assertEquals ("CREATE TABLE IF NOT EXISTS `S`.`T1` ("
125
- + "`FOO_keyType ` ROW(`QUX` VARCHAR), "
126
- + "`FOO_valueType_QIZ_BAR ` VARCHAR, "
127
- + "`FOO_valueType_QIZ_CAR ` INTEGER) WITH ();" , flattenedConnector ,
129
+ + "`FOO___MAPKEYTYPE__ ` ROW(`QUX` VARCHAR), "
130
+ + "`FOO___MAPVALUETYPE___QIZ_BAR ` VARCHAR, "
131
+ + "`FOO___MAPVALUETYPE___QIZ_CAR ` INTEGER) WITH ();" , flattenedConnector ,
128
132
"Flattened connector should have simplified map" );
129
133
130
134
RelDataType unflattenedType = DataTypeUtils .unflatten (flattenedType , typeFactory );
0 commit comments