lgbo-ustc commented on code in PR #10022: URL: https://github.com/apache/incubator-gluten/pull/10022#discussion_r2163729265
########## gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/ReinterpretRexCallConverter.java: ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gluten.rexnode.functions; + +import org.apache.gluten.rexnode.RexConversionContext; +import org.apache.gluten.util.LogicalTypeConverter; + +import io.github.zhztheplayer.velox4j.expression.CallTypedExpr; +import io.github.zhztheplayer.velox4j.expression.TypedExpr; + +import org.apache.flink.table.planner.calcite.FlinkTypeFactory; +import org.apache.flink.table.runtime.types.PlannerTypeUtils; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.flink.table.types.logical.LogicalTypeRoot; + +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexFieldAccess; +import org.apache.calcite.rex.RexInputRef; +import org.apache.calcite.rex.RexNode; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; + +import static org.apache.flink.table.types.logical.LogicalTypeRoot.BIGINT; +import static org.apache.flink.table.types.logical.LogicalTypeRoot.DATE; +import static org.apache.flink.table.types.logical.LogicalTypeRoot.INTEGER; +import static org.apache.flink.table.types.logical.LogicalTypeRoot.INTERVAL_DAY_TIME; +import static org.apache.flink.table.types.logical.LogicalTypeRoot.INTERVAL_YEAR_MONTH; +import static org.apache.flink.table.types.logical.LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE; +import static org.apache.flink.table.types.logical.LogicalTypeRoot.TIME_WITHOUT_TIME_ZONE; + +public class ReinterpretRexCallConverter extends BaseRexCallConverter { + + private static final String FUNCTION_NAME = "cast"; + + public ReinterpretRexCallConverter() { + super(FUNCTION_NAME); + } + + private boolean isSupported(LogicalTypeRoot targetType, LogicalTypeRoot resultType) { + // internal reinterpretation of temporal types: from Flink + // `ScalaOperatorGens#generateReinterpret` + // Date -> Integer + // Time -> Integer + // Timestamp -> Long + // Integer -> Date + // Integer -> Time + // Long -> Timestamp + // Integer -> Interval Months + // Long -> Interval Millis + // Interval Months -> Integer + // Interval Millis -> Long + // Date -> Long + // Time -> Long + // Interval Months -> Long + if (targetType.equals(DATE) && resultType.equals(INTEGER)) { + return true; + } else if (targetType.equals(TIME_WITHOUT_TIME_ZONE) && resultType.equals(INTEGER)) { + return true; + } else if (targetType.equals(INTEGER) && resultType.equals(DATE)) { + return true; + } else if (targetType.equals(INTEGER) && resultType.equals(TIME_WITHOUT_TIME_ZONE)) { + return true; + } else if (targetType.equals(INTEGER) && resultType.equals(INTERVAL_YEAR_MONTH)) { + return true; + } else if (targetType.equals(BIGINT) && resultType.equals(INTERVAL_DAY_TIME)) { + return true; + } else if (targetType.equals(INTERVAL_YEAR_MONTH) && resultType.equals(INTEGER)) { + return true; + } else if (targetType.equals(INTERVAL_DAY_TIME) && resultType.equals(BIGINT)) { + return true; + } else if (targetType.equals(DATE) && resultType.equals(BIGINT)) { + return true; + } else if (targetType.equals(TIME_WITHOUT_TIME_ZONE) && resultType.equals(BIGINT)) { + return true; + } else if (targetType.equals(INTERVAL_YEAR_MONTH) && resultType.equals(BIGINT)) { + return true; + } else if (targetType.equals(TIMESTAMP_WITHOUT_TIME_ZONE) && resultType.equals(BIGINT)) { + return true; + } else if (targetType.equals(BIGINT) && resultType.equals(TIMESTAMP_WITHOUT_TIME_ZONE)) { + return true; + } + return false; + } + + @Override + public boolean isSupported(RexCall callNode, RexConversionContext context) { + if (callNode.getOperands().size() != 1) { + return false; + } + RexNode rexNode = callNode.getOperands().get(0); + LogicalType resultType = FlinkTypeFactory.toLogicalType(callNode.getType()); + LogicalType targetType = FlinkTypeFactory.toLogicalType(rexNode.getType()); + if (PlannerTypeUtils.isInteroperable(targetType, resultType)) { + return true; + } else if (resultType.equals(targetType)) { + return true; + } else { + LogicalTypeRoot targetTypeRoot = targetType.getTypeRoot(); + LogicalTypeRoot resultTypeRoot = resultType.getTypeRoot(); + return isSupported(targetTypeRoot, resultTypeRoot); + } + } + + private List<String> getRexNodeInputNames(RexNode node, List<String> fieldNames) { Review Comment: 👌 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@gluten.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@gluten.apache.org For additional commands, e-mail: commits-h...@gluten.apache.org