BiteTheDDDDt commented on code in PR #20164: URL: https://github.com/apache/doris/pull/20164#discussion_r1217729841
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggStateFunctionBuilder.java: ########## @@ -0,0 +1,126 @@ +// 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.doris.nereids.trees.expressions.functions; + +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.SlotReference; +import org.apache.doris.nereids.trees.expressions.functions.combinator.MergeCombinator; +import org.apache.doris.nereids.trees.expressions.functions.combinator.StateCombinator; +import org.apache.doris.nereids.types.AggStateType; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * This class used to resolve AggState's combinators + */ +public class AggStateFunctionBuilder extends FunctionBuilder { + public static final String COMBINATOR_LINKER = "_"; + public static final String STATE = "state"; + public static final String MERGE = "merge"; + public static final String UNION = "union"; + + private FunctionBuilder nestedBuilder; + + private String combinatorSuffix; + + public AggStateFunctionBuilder(String combinatorSuffix, FunctionBuilder nestedBuilder) { + this.combinatorSuffix = combinatorSuffix; + this.nestedBuilder = nestedBuilder; + } + + @Override + public boolean canApply(List<? extends Object> arguments) { + if (combinatorSuffix.equals(STATE)) { + return nestedBuilder.canApply(arguments); + } else { + if (arguments.size() != 1) { + return false; + } + Expression argument = (Expression) arguments.get(0); + if (!argument.getDataType().isAggStateType()) { + return false; + } + + return nestedBuilder.canApply(((AggStateType) argument.getDataType()).getSubTypes().stream().map(t -> { + return new SlotReference("mocked", t); + }).collect(Collectors.toList())); + } + } + + private BoundFunction buildState(String nestedName, List<? extends Object> arguments) { + return nestedBuilder.build(nestedName, arguments); + } + + private BoundFunction buildMergeOrUnion(String nestedName, List<? extends Object> arguments) { + if (arguments.size() != 1 || !(arguments.get(0) instanceof Expression) + || !((Expression) arguments.get(0)).getDataType().isAggStateType()) { + String argString = arguments.stream().map(arg -> { + if (arg == null) { Review Comment: This code was copied from BuiltinFunctionBuilder.java (originally FunctionBuilder.java) -- 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...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org