github-actions[bot] commented on code in PR #66942:
URL: https://github.com/apache/doris/pull/66942#discussion_r3842438029


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggCombinerFunctionBuilder.java:
##########
@@ -65,7 +70,21 @@ public Class<? extends BoundFunction> functionClass() {
 
     @Override
     public boolean canApply(List<?> arguments) {
-        if (combinatorSuffix.equalsIgnoreCase(STATE) || 
combinatorSuffix.equalsIgnoreCase(FOREACH)) {
+        if 
(!AggregateFunction.class.isAssignableFrom(nestedBuilder.functionClass())) {
+            return false;
+        }
+        if 
(NotSupportAggState.class.isAssignableFrom(nestedBuilder.functionClass())) {

Review Comment:
   [P1] Keep the non-AggState `_foreach` suffix available
   
   `NotSupportAggState` is checked before suffix dispatch, so marking 
`OrthogonalBitmapUnionCount` also removes 
`orthogonal_bitmap_union_count_foreach(array_bitmap)`. That path was valid 
before this change: `_foreach` maps array items into the nested aggregate and 
the BE foreach wrapper performs ordinary nested serialize/merge/final-result 
handling; it never performs `_combine`'s extra state-valued final serialization 
that motivated this marker. Please scope the fence to state-producing/consuming 
suffixes (or add a narrower capability) and retain a positive `_foreach` test.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMaterializedViewCommand.java:
##########
@@ -659,6 +660,10 @@ private void checkNoNondeterministicFunctionOrUnnest(Plan 
plan) {
         }
 
         private void validateAggFunnction(AggregateFunction aggregateFunction) 
{
+            if (aggregateFunction instanceof CombineCombinator) {

Review Comment:
   [P1] Apply AggState capability checks to synchronous MV rewrites
   
   This rejects a view-side `CombineCombinator`, but generic raw aggregates are 
later rewritten with `StateCombinator.create()` directly, bypassing both new 
capability markers. A synchronous MV over raw `ai_agg` therefore still creates 
`ai_agg_state` without QueryContext propagation, and a marked orthogonal 
aggregate re-enters the terminal serializer path that this PR deliberately 
disabled. Please enforce the markers at the common state-construction boundary 
or reject marked aggregates here, with negative MV tests. This is distinct from 
the earlier `_combine` MV thread because no suffix builder runs.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/AggCombinerFunctionBuilder.java:
##########
@@ -139,6 +158,12 @@ public Pair<BoundFunction, AggregateFunction> build(String 
name, List<?> argumen
                 arguments = arguments.subList(1, arguments.size());
             }
             return Pair.of(new StateCombinator((List<Expression>) arguments, 
nestedFunction), nestedFunction);
+        } else if (combinatorSuffix.equalsIgnoreCase(COMBINE)) {
+            AggregateFunction nestedFunction = buildState(nestedName, 
arguments);
+            if (!arguments.isEmpty() && arguments.get(0) instanceof Boolean && 
(Boolean) arguments.get(0)) {
+                throw new IllegalStateException(name + " doesn't support 
DISTINCT");

Review Comment:
   [P2] Reject DISTINCT during SQL binding
   
   `ExpressionAnalyzer` prepends the DISTINCT boolean to the builder arguments. 
For `avg_combine(DISTINCT v)`, `canApply()` still succeeds through 
`Avg(boolean, Expression)`, `buildState()` constructs the distinct nested 
aggregate, and this throws unchecked `IllegalStateException`; 
`visitUnboundFunction()` does not convert it to an analysis error. The added 
direct `withDistinctAndChildren()` test does not exercise this binding path. 
Please reject the marker before building (or make the builder inapplicable) and 
add an unbound SQL-binding test.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/combinator/CombineCombinator.java:
##########
@@ -0,0 +1,164 @@
+// 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.combinator;
+
+import org.apache.doris.catalog.BuiltinAggregateFunctions;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.FunctionRegistry;
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.common.Pair;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.OrderExpression;
+import 
org.apache.doris.nereids.trees.expressions.functions.AggCombinerFunctionBuilder;
+import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
+import org.apache.doris.nereids.trees.expressions.functions.BoundFunction;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
+import org.apache.doris.nereids.trees.expressions.functions.Function;
+import org.apache.doris.nereids.trees.expressions.functions.FunctionBuilder;
+import 
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
+import 
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunctionParams;
+import org.apache.doris.nereids.trees.expressions.functions.agg.AggregatePhase;
+import org.apache.doris.nereids.trees.expressions.functions.agg.RollUpTrait;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.AggStateType;
+import org.apache.doris.nereids.types.DataType;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Aggregate inputs into the nested function's serialized state.
+ */
+public class CombineCombinator extends AggregateFunction
+        implements ExplicitlyCastableSignature, AlwaysNotNullable, Combinator, 
RollUpTrait {
+
+    private final AggregateFunction nested;
+    private final AggStateType returnType;
+
+    /** Constructor of CombineCombinator. */
+    public CombineCombinator(List<Expression> arguments, AggregateFunction 
nested) {
+        super(nested.getName() + AggCombinerFunctionBuilder.COMBINE_SUFFIX, 
arguments);
+        checkArguments(arguments, nested);
+        this.nested = Objects.requireNonNull(nested, "nested can not be null");
+        this.returnType = createReturnType(arguments, nested);
+    }
+
+    private CombineCombinator(AggregateFunctionParams functionParams, 
AggregateFunction nested) {
+        super(functionParams);
+        checkArguments(functionParams.arguments, nested);
+        this.nested = Objects.requireNonNull(nested, "nested can not be null");
+        this.returnType = createReturnType(functionParams.arguments, nested);
+    }
+
+    private static void checkArguments(List<Expression> arguments, 
AggregateFunction nested) {
+        if (arguments.isEmpty()) {
+            throw new AnalysisException(String.format(
+                    "%s_combine requires at least one argument", 
nested.getName()));
+        }
+        for (Expression argument : arguments) {
+            if (argument instanceof OrderExpression) {
+                throw new AnalysisException(String.format(
+                        "%s_combine doesn't support order by expression", 
nested.getName()));
+            }
+        }
+    }
+
+    private static AggStateType createReturnType(List<Expression> arguments, 
AggregateFunction nested) {
+        return new AggStateType(nested.getName(),

Review Comment:
   [P1] Preserve Decimal256 AVG state metadata
   
   With `enable_decimal256=true`, `avg_combine(CAST(v AS DECIMALV3(20,6)))` 
records the DECIMAL128 argument subtype here, while FE derives a 
DECIMAL256(76,6) result for the downstream `avg_merge`. BE reconstructs the 
nested AVG from the stored subtype and its explicit Decimal256 TODO chooses 
DECIMAL128(38,6), so `AggFnEvaluator::prepare()` rejects the return-type 
mismatch. Please make the state metadata select the same AVG result family on 
both sides and add a Decimal256 combine/merge regression; the new AVG coverage 
currently uses only integer input.



##########
be/src/exprs/vectorized_agg_fn.cpp:
##########
@@ -256,7 +292,7 @@ Status AggFnEvaluator::prepare(RuntimeState* state, const 
RowDescriptor& desc,
                                                    _sort_description, state);
     }
 
-    if (_fn.name.function_name == "ai_agg") {
+    if (_fn.name.function_name.starts_with("ai_agg")) {

Review Comment:
   [P1] Forward AI context through stored-state wrappers
   
   Only `_state`/`_combine` are rejected by `NotSupportAggStateCreation`, so 
`ai_agg_merge` and `ai_agg_union` remain resolvable for an existing 
`AggState(ai_agg, ...)`. BE constructs 
`AggregateStateMerge`/`AggregateStateUnion`; neither overrides 
`set_query_context()`, so this prefix match calls the fatal base implementation 
during prepare instead of reaching the nested AI aggregate. Please reject these 
suffixes too while AI AggState is deferred, or forward QueryContext (and 
blockability for merge) through the wrappers and cover stored AI state. This is 
distinct from the earlier `_combine` thread.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to