Search in sources :

Example 1 with TypeLiteralExpression

use of org.apache.flink.table.expressions.TypeLiteralExpression in project flink by apache.

the class TryCastConverter method convert.

@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
    checkArgumentNumber(call, 2);
    final FlinkTypeFactory typeFactory = context.getTypeFactory();
    final RexNode child = context.toRexNode(call.getChildren().get(0));
    final TypeLiteralExpression targetType = (TypeLiteralExpression) call.getChildren().get(1);
    RelDataType targetRelDataType = typeFactory.createTypeWithNullability(typeFactory.createFieldTypeFromLogicalType(targetType.getOutputDataType().getLogicalType()), true);
    return context.getRelBuilder().getRexBuilder().makeCall(targetRelDataType, FlinkSqlOperatorTable.TRY_CAST, Collections.singletonList(child));
}
Also used : FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) TypeLiteralExpression(org.apache.flink.table.expressions.TypeLiteralExpression) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 2 with TypeLiteralExpression

use of org.apache.flink.table.expressions.TypeLiteralExpression in project flink by apache.

the class ReinterpretCastConverter method convert.

@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
    checkArgumentNumber(call, 3);
    RexNode child = context.toRexNode(call.getChildren().get(0));
    TypeLiteralExpression type = (TypeLiteralExpression) call.getChildren().get(1);
    RexNode checkOverflow = context.toRexNode(call.getChildren().get(2));
    return context.getRelBuilder().getRexBuilder().makeReinterpretCast(context.getTypeFactory().createFieldTypeFromLogicalType(type.getOutputDataType().getLogicalType().copy(child.getType().isNullable())), child, checkOverflow);
}
Also used : TypeLiteralExpression(org.apache.flink.table.expressions.TypeLiteralExpression) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with TypeLiteralExpression

use of org.apache.flink.table.expressions.TypeLiteralExpression in project flink by apache.

the class ThrowExceptionConverter method convert.

@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
    checkArgumentNumber(call, 2);
    DataType type = ((TypeLiteralExpression) call.getChildren().get(1)).getOutputDataType();
    SqlThrowExceptionFunction function = new SqlThrowExceptionFunction(context.getTypeFactory().createFieldTypeFromLogicalType(fromDataTypeToLogicalType(type)));
    return context.getRelBuilder().call(function, context.toRexNode(call.getChildren().get(0)));
}
Also used : SqlThrowExceptionFunction(org.apache.flink.table.planner.functions.sql.SqlThrowExceptionFunction) DataType(org.apache.flink.table.types.DataType) TypeLiteralExpression(org.apache.flink.table.expressions.TypeLiteralExpression)

Example 4 with TypeLiteralExpression

use of org.apache.flink.table.expressions.TypeLiteralExpression in project flink by apache.

the class CastConverter method convert.

@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
    checkArgumentNumber(call, 2);
    final RexNode child = context.toRexNode(call.getChildren().get(0));
    final TypeLiteralExpression targetType = (TypeLiteralExpression) call.getChildren().get(1);
    final RelDataType targetRelDataType = context.getTypeFactory().createFieldTypeFromLogicalType(targetType.getOutputDataType().getLogicalType());
    return context.getRelBuilder().getRexBuilder().makeAbstractCast(targetRelDataType, child);
}
Also used : TypeLiteralExpression(org.apache.flink.table.expressions.TypeLiteralExpression) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

TypeLiteralExpression (org.apache.flink.table.expressions.TypeLiteralExpression)4 RexNode (org.apache.calcite.rex.RexNode)3 RelDataType (org.apache.calcite.rel.type.RelDataType)2 FlinkTypeFactory (org.apache.flink.table.planner.calcite.FlinkTypeFactory)1 SqlThrowExceptionFunction (org.apache.flink.table.planner.functions.sql.SqlThrowExceptionFunction)1 DataType (org.apache.flink.table.types.DataType)1