JingsongLi commented on a change in pull request #8001: [FLINK-11949][table-planner-blink] Introduce DeclarativeAggregateFunction and AggsHandlerCodeGenerator to blink planner URL: https://github.com/apache/flink/pull/8001#discussion_r267162956
########## File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/expressions/RexNodeGenExpressionVisitor.java ########## @@ -0,0 +1,206 @@ +/* + * 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.flink.table.expressions; + +import org.apache.flink.table.calcite.FlinkTypeFactory; +import org.apache.flink.table.calcite.RexAggLocalVariable; +import org.apache.flink.table.calcite.RexDistinctKeyVariable; +import org.apache.flink.table.type.DecimalType; +import org.apache.flink.table.type.InternalType; +import org.apache.flink.table.type.InternalTypes; + +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexBuilder; +import org.apache.calcite.rex.RexInputRef; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.tools.RelBuilder; + +import java.math.BigDecimal; +import java.util.List; +import java.util.stream.Collectors; + +import static org.apache.calcite.sql.type.SqlTypeName.VARCHAR; +import static org.apache.flink.table.calcite.FlinkTypeFactory.toInternalType; +import static org.apache.flink.table.type.TypeConverters.createInternalTypeFromTypeInfo; +import static org.apache.flink.table.typeutils.TypeCheckUtils.isString; +import static org.apache.flink.table.typeutils.TypeCheckUtils.isTemporal; +import static org.apache.flink.table.typeutils.TypeCheckUtils.isTimeInterval; + +/** + * Visit expression to generator {@link RexNode}. + */ +public class RexNodeGenExpressionVisitor implements ExpressionVisitor<RexNode> { + + private final RelBuilder relBuilder; + private final FlinkTypeFactory typeFactory; + + public RexNodeGenExpressionVisitor(RelBuilder relBuilder) { + this.relBuilder = relBuilder; + this.typeFactory = (FlinkTypeFactory) relBuilder.getRexBuilder().getTypeFactory(); + } + + @Override + public RexNode visitCall(CallExpression call) { + List<RexNode> child = call.getChildren().stream() + .map(expression -> expression.accept(RexNodeGenExpressionVisitor.this)) + .collect(Collectors.toList()); + switch (call.getFunctionDefinition().getType()) { + case SCALAR_FUNCTION: + return visitScalarFunc(call.getFunctionDefinition(), child); + default: throw new UnsupportedOperationException(); + } + } + + private RexNode visitScalarFunc(FunctionDefinition def, List<RexNode> child) { + switch (def.getName()) { Review comment: `if else` is OK, prefer Java code ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services