|
15 | 15 | import org.apache.calcite.rel.type.RelRecordType; |
16 | 16 | import org.apache.calcite.sql.SqlNode; |
17 | 17 | import org.apache.calcite.sql.SqlOperatorTable; |
| 18 | +import org.apache.calcite.sql.type.ArraySqlType; |
| 19 | +import org.apache.calcite.sql.type.MapSqlType; |
| 20 | +import org.apache.calcite.sql.type.MultisetSqlType; |
| 21 | +import org.apache.calcite.sql.type.ObjectSqlType; |
18 | 22 | import org.apache.calcite.sql.type.SqlTypeName; |
19 | 23 | import org.apache.calcite.sql.validate.SqlValidatorCatalogReader; |
20 | 24 | import org.apache.calcite.sql.validate.SqlValidatorImpl; |
@@ -122,11 +126,31 @@ private RelDataType sqlTypeToUserDefinedType(RelDataType type) { |
122 | 126 |
|
123 | 127 | private RelDataType convertType(RelDataType type, Function<RelDataType, RelDataType> convert) { |
124 | 128 | if (type == null) return null; |
| 129 | + |
125 | 130 | if (type instanceof RelRecordType recordType) { |
126 | 131 | List<RelDataType> subTypes = |
127 | 132 | recordType.getFieldList().stream().map(RelDataTypeField::getType).map(convert).toList(); |
128 | | - return typeFactory.createStructType(subTypes, recordType.getFieldNames()); |
| 133 | + return typeFactory.createTypeWithNullability( |
| 134 | + typeFactory.createStructType(subTypes, recordType.getFieldNames()), |
| 135 | + recordType.isNullable()); |
| 136 | + } |
| 137 | + if (type instanceof ArraySqlType arrayType) { |
| 138 | + return typeFactory.createTypeWithNullability( |
| 139 | + typeFactory.createArrayType(convert.apply(arrayType.getComponentType()), -1), |
| 140 | + arrayType.isNullable()); |
| 141 | + } |
| 142 | + if (type instanceof MapSqlType mapType) { |
| 143 | + return typeFactory.createTypeWithNullability( |
| 144 | + typeFactory.createMapType( |
| 145 | + convert.apply(mapType.getKeyType()), convert.apply(mapType.getValueType())), |
| 146 | + mapType.isNullable()); |
129 | 147 | } |
| 148 | + if (type instanceof MultisetSqlType multisetType) { |
| 149 | + return typeFactory.createTypeWithNullability( |
| 150 | + typeFactory.createMultisetType(convert.apply(multisetType.getComponentType()), -1), |
| 151 | + multisetType.isNullable()); |
| 152 | + } |
| 153 | + |
130 | 154 | return convert.apply(type); |
131 | 155 | } |
132 | 156 | } |
0 commit comments