|
19 | 19 | package org.apache.flink.table.planner.functions.inference; |
20 | 20 |
|
21 | 21 | import org.apache.flink.annotation.Internal; |
| 22 | +import org.apache.flink.sql.parser.type.SqlRawTypeNameSpec; |
22 | 23 | import org.apache.flink.table.api.ValidationException; |
23 | 24 | import org.apache.flink.table.catalog.DataTypeFactory; |
24 | 25 | import org.apache.flink.table.functions.FunctionDefinition; |
25 | 26 | import org.apache.flink.table.planner.calcite.FlinkTypeFactory; |
| 27 | +import org.apache.flink.table.planner.plan.schema.RawRelDataType; |
26 | 28 | import org.apache.flink.table.types.DataType; |
27 | 29 | import org.apache.flink.table.types.inference.ArgumentCount; |
28 | 30 | import org.apache.flink.table.types.inference.CallContext; |
|
32 | 34 | import org.apache.flink.table.types.inference.TypeInference; |
33 | 35 | import org.apache.flink.table.types.inference.TypeInferenceUtil; |
34 | 36 | import org.apache.flink.table.types.logical.LogicalType; |
| 37 | +import org.apache.flink.table.types.logical.RawType; |
35 | 38 | import org.apache.flink.table.types.logical.utils.LogicalTypeChecks; |
36 | 39 |
|
37 | 40 | import org.apache.calcite.rel.type.RelDataType; |
38 | 41 | import org.apache.calcite.rel.type.RelDataTypeFactory; |
39 | 42 | import org.apache.calcite.rel.type.StructKind; |
40 | 43 | import org.apache.calcite.sql.SqlCallBinding; |
| 44 | +import org.apache.calcite.sql.SqlDataTypeSpec; |
41 | 45 | import org.apache.calcite.sql.SqlKind; |
| 46 | +import org.apache.calcite.sql.SqlLiteral; |
42 | 47 | import org.apache.calcite.sql.SqlNode; |
43 | 48 | import org.apache.calcite.sql.SqlOperandCountRange; |
44 | 49 | import org.apache.calcite.sql.SqlOperator; |
| 50 | +import org.apache.calcite.sql.SqlTypeNameSpec; |
45 | 51 | import org.apache.calcite.sql.fun.SqlStdOperatorTable; |
46 | 52 | import org.apache.calcite.sql.parser.SqlParserPos; |
47 | 53 | import org.apache.calcite.sql.type.SqlOperandMetadata; |
@@ -240,10 +246,28 @@ private void insertImplicitCasts(SqlCallBinding callBinding, List<DataType> expe |
240 | 246 |
|
241 | 247 | /** Adopted from {@link org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion}. */ |
242 | 248 | private SqlNode castTo(SqlNode node, RelDataType type) { |
243 | | - return SqlStdOperatorTable.CAST.createCall( |
244 | | - SqlParserPos.ZERO, |
245 | | - node, |
246 | | - SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable())); |
| 249 | + final SqlDataTypeSpec dataType; |
| 250 | + if (type instanceof RawRelDataType) { |
| 251 | + dataType = createRawDataTypeSpec((RawRelDataType) type); |
| 252 | + } else { |
| 253 | + dataType = SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()); |
| 254 | + } |
| 255 | + |
| 256 | + return SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, dataType); |
| 257 | + } |
| 258 | + |
| 259 | + private SqlDataTypeSpec createRawDataTypeSpec(RawRelDataType type) { |
| 260 | + final RawType<?> rawType = type.getRawType(); |
| 261 | + |
| 262 | + SqlNode className = |
| 263 | + SqlLiteral.createCharString( |
| 264 | + rawType.getOriginatingClass().getName(), SqlParserPos.ZERO); |
| 265 | + SqlNode serializer = |
| 266 | + SqlLiteral.createCharString(rawType.getSerializerString(), SqlParserPos.ZERO); |
| 267 | + |
| 268 | + SqlTypeNameSpec rawSpec = new SqlRawTypeNameSpec(className, serializer, SqlParserPos.ZERO); |
| 269 | + |
| 270 | + return new SqlDataTypeSpec(rawSpec, null, type.isNullable(), SqlParserPos.ZERO); |
247 | 271 | } |
248 | 272 |
|
249 | 273 | /** Adopted from {@link org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion}. */ |
|
0 commit comments