From bb8bc75af490702b6fb74746d2f507f44696c250 Mon Sep 17 00:00:00 2001 From: Jensen Date: Thu, 28 Mar 2024 11:46:31 +0800 Subject: [PATCH] [feature](agg) add aggregate function sum0 (#32541) --- .../aggregate_function_simple_factory.cpp | 2 + .../aggregate_function_sum.cpp | 4 + .../catalog/BuiltinAggregateFunctions.java | 4 + .../org/apache/doris/catalog/FunctionSet.java | 109 ++- .../functions/agg/MultiDistinctSum0.java | 82 ++ .../trees/expressions/functions/agg/Sum0.java | 125 +++ .../visitor/AggregateFunctionVisitor.java | 10 + .../nereids_function_p0/agg_function/agg.out | 848 ++++++++++++++---- .../agg_function/agg.groovy | 185 ++++ 9 files changed, 1161 insertions(+), 208 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Sum0.java diff --git a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp index c33b8b5060..2069e8ae8a 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp @@ -31,6 +31,7 @@ void register_aggregate_function_combinator_distinct(AggregateFunctionSimpleFact void register_aggregate_function_combinator_foreach(AggregateFunctionSimpleFactory& factory); void register_aggregate_function_sum(AggregateFunctionSimpleFactory& factory); +void register_aggregate_function_sum0(AggregateFunctionSimpleFactory& factory); void register_aggregate_function_minmax(AggregateFunctionSimpleFactory& factory); void register_aggregate_function_min_by(AggregateFunctionSimpleFactory& factory); void register_aggregate_function_max_by(AggregateFunctionSimpleFactory& factory); @@ -70,6 +71,7 @@ AggregateFunctionSimpleFactory& AggregateFunctionSimpleFactory::instance() { static AggregateFunctionSimpleFactory instance; std::call_once(oc, [&]() { register_aggregate_function_sum(instance); + register_aggregate_function_sum0(instance); register_aggregate_function_minmax(instance); register_aggregate_function_min_by(instance); register_aggregate_function_max_by(instance); diff --git a/be/src/vec/aggregate_functions/aggregate_function_sum.cpp b/be/src/vec/aggregate_functions/aggregate_function_sum.cpp index 3ee7dc6ff4..e0676957d4 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_sum.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_sum.cpp @@ -31,4 +31,8 @@ void register_aggregate_function_sum(AggregateFunctionSimpleFactory& factory) { "sum_decimal256", creator_with_type::creator); } +void register_aggregate_function_sum0(AggregateFunctionSimpleFactory& factory) { + factory.register_function_both("sum0", creator_with_type::creator); +} + } // namespace doris::vectorized diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinAggregateFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinAggregateFunctions.java index e6134cfc31..49e6d66f50 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinAggregateFunctions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinAggregateFunctions.java @@ -50,6 +50,7 @@ import org.apache.doris.nereids.trees.expressions.functions.agg.MinBy; import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctCount; import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctGroupConcat; import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctSum; +import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctSum0; import org.apache.doris.nereids.trees.expressions.functions.agg.Ndv; import org.apache.doris.nereids.trees.expressions.functions.agg.OrthogonalBitmapIntersect; import org.apache.doris.nereids.trees.expressions.functions.agg.OrthogonalBitmapIntersectCount; @@ -64,6 +65,7 @@ import org.apache.doris.nereids.trees.expressions.functions.agg.SequenceMatch; import org.apache.doris.nereids.trees.expressions.functions.agg.Stddev; import org.apache.doris.nereids.trees.expressions.functions.agg.StddevSamp; import org.apache.doris.nereids.trees.expressions.functions.agg.Sum; +import org.apache.doris.nereids.trees.expressions.functions.agg.Sum0; import org.apache.doris.nereids.trees.expressions.functions.agg.TopN; import org.apache.doris.nereids.trees.expressions.functions.agg.TopNArray; import org.apache.doris.nereids.trees.expressions.functions.agg.TopNWeighted; @@ -118,6 +120,7 @@ public class BuiltinAggregateFunctions implements FunctionHelper { agg(MultiDistinctCount.class, "multi_distinct_count"), agg(MultiDistinctGroupConcat.class, "multi_distinct_group_concat"), agg(MultiDistinctSum.class, "multi_distinct_sum"), + agg(MultiDistinctSum0.class, "multi_distinct_sum0"), agg(Ndv.class, "approx_count_distinct", "ndv"), agg(OrthogonalBitmapIntersect.class, "orthogonal_bitmap_intersect"), agg(OrthogonalBitmapIntersectCount.class, "orthogonal_bitmap_intersect_count"), @@ -132,6 +135,7 @@ public class BuiltinAggregateFunctions implements FunctionHelper { agg(Stddev.class, "stddev_pop", "stddev"), agg(StddevSamp.class, "stddev_samp"), agg(Sum.class, "sum"), + agg(Sum0.class, "sum0"), agg(TopN.class, "topn"), agg(TopNArray.class, "topn_array"), agg(TopNWeighted.class, "topn_weighted"), diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java index b69d52b2c1..29ff913b8a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java @@ -46,6 +46,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; public class FunctionSet { @@ -924,6 +925,17 @@ public class FunctionSet { // sum in multi distinct if (t.equals(Type.BIGINT) || t.equals(Type.LARGEINT) || t.equals(Type.DOUBLE)) { addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", Lists.newArrayList(t), + t, + t, + "", + "", + "", + "", + null, + null, + "", + false, true, false, true)); + addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum0", Lists.newArrayList(t), t, t, "", @@ -937,6 +949,17 @@ public class FunctionSet { } else if (t.equals(Type.MAX_DECIMALV2_TYPE)) { // vectorized addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", Lists.newArrayList(t), + MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), + Type.MAX_DECIMALV2_TYPE, + "", + "", + "", + "", + null, + null, + "", + false, true, false, true)); + addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum0", Lists.newArrayList(t), MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), Type.MAX_DECIMALV2_TYPE, "", @@ -950,6 +973,17 @@ public class FunctionSet { } else if (t.equals(Type.DECIMAL32)) { // vectorized addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", Lists.newArrayList(t), + MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), + Type.DECIMAL32, + "", + "", + "", + "", + null, + null, + "", + false, true, false, true)); + addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum0", Lists.newArrayList(t), MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), Type.DECIMAL32, "", @@ -962,6 +996,17 @@ public class FunctionSet { false, true, true, true)); } else if (t.equals(Type.DECIMAL64)) { addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", Lists.newArrayList(t), + MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), + Type.DECIMAL64, + "", + "", + "", + "", + null, + null, + "", + false, true, false, true)); + addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum0", Lists.newArrayList(t), MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), Type.DECIMAL64, "", @@ -974,6 +1019,17 @@ public class FunctionSet { false, true, true, true)); } else if (t.equals(Type.DECIMAL128)) { addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", Lists.newArrayList(t), + MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), + Type.DECIMAL128, + "", + "", + "", + "", + null, + null, + "", + false, true, false, true)); + addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum0", Lists.newArrayList(t), MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), Type.DECIMAL128, "", @@ -1174,86 +1230,91 @@ public class FunctionSet { } // Sum - String []sumNames = {"sum", "sum_distinct"}; - for (String name : sumNames) { - addBuiltin(AggregateFunction.createBuiltin(name, + // functionName(String) -> returnsNonNullOnEmpty(Boolean) + Map sumNames = ImmutableMap.of( + "sum", false, + "sum_distinct", false, + "sum0", true + ); + for (Entry nameWithReturn : sumNames.entrySet()) { + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.BOOLEAN), Type.BIGINT, Type.BIGINT, "", "", "", null, null, "", - null, false, true, false, true)); + null, false, true, nameWithReturn.getValue(), true)); - addBuiltin(AggregateFunction.createBuiltin(name, + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.TINYINT), Type.BIGINT, Type.BIGINT, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.SMALLINT), Type.BIGINT, Type.BIGINT, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.INT), Type.BIGINT, Type.BIGINT, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.BIGINT), Type.BIGINT, Type.BIGINT, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.DOUBLE), Type.DOUBLE, Type.DOUBLE, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.MAX_DECIMALV2_TYPE), Type.MAX_DECIMALV2_TYPE, Type.MAX_DECIMALV2_TYPE, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.DECIMAL32), ScalarType.DECIMAL128, Type.DECIMAL128, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.DECIMAL64), Type.DECIMAL128, Type.DECIMAL128, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.DECIMAL128), Type.DECIMAL128, Type.DECIMAL128, "", "", "", null, null, "", - null, false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin(name, + null, false, true, nameWithReturn.getValue(), true)); + addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(), Lists.newArrayList(Type.LARGEINT), Type.LARGEINT, Type.LARGEINT, "", "", "", null, null, "", - null, false, true, false, true)); + null, false, true, nameWithReturn.getValue(), true)); } Type[] types = {Type.SMALLINT, Type.TINYINT, Type.INT, Type.BIGINT, Type.FLOAT, Type.DOUBLE, Type.CHAR, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java new file mode 100644 index 0000000000..8999925871 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctSum0.java @@ -0,0 +1,82 @@ +// 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.agg; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; +import org.apache.doris.nereids.trees.expressions.functions.ComputePrecisionForSum; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.BigIntType; +import org.apache.doris.nereids.types.DoubleType; +import org.apache.doris.nereids.types.LargeIntType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** MultiDistinctSum0 */ +public class MultiDistinctSum0 extends AggregateFunction implements UnaryExpression, + ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction, AlwaysNotNullable { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(BigIntType.INSTANCE).varArgs(BigIntType.INSTANCE), + FunctionSignature.ret(BigIntType.INSTANCE).varArgs(DoubleType.INSTANCE), + FunctionSignature.ret(BigIntType.INSTANCE).varArgs(LargeIntType.INSTANCE) + ); + + public MultiDistinctSum0(Expression arg0) { + super("multi_distinct_sum0", true, arg0); + } + + public MultiDistinctSum0(boolean distinct, Expression arg0) { + super("multi_distinct_sum0", true, arg0); + } + + @Override + public void checkLegalityBeforeTypeCoercion() { + if (child().getDataType().isDateLikeType()) { + throw new AnalysisException("Sum0 in multi distinct functions do not support Date/Datetime type"); + } + } + + @Override + public List getSignatures() { + return new Sum0(getArgument(0)).getSignatures(); + } + + @Override + public FunctionSignature searchSignature(List signatures) { + return new Sum0(getArgument(0)).searchSignature(signatures); + } + + @Override + public MultiDistinctSum0 withDistinctAndChildren(boolean distinct, List children) { + Preconditions.checkArgument(children.size() == 1); + return new MultiDistinctSum0(distinct, children.get(0)); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitMultiDistinctSum0(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Sum0.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Sum0.java new file mode 100644 index 0000000000..b25dd5fe60 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Sum0.java @@ -0,0 +1,125 @@ +// 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.agg; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; +import org.apache.doris.nereids.trees.expressions.functions.ComputePrecisionForSum; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.Function; +import org.apache.doris.nereids.trees.expressions.functions.window.SupportWindowAnalytic; +import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.BigIntType; +import org.apache.doris.nereids.types.BooleanType; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.DecimalV3Type; +import org.apache.doris.nereids.types.DoubleType; +import org.apache.doris.nereids.types.FloatType; +import org.apache.doris.nereids.types.IntegerType; +import org.apache.doris.nereids.types.LargeIntType; +import org.apache.doris.nereids.types.SmallIntType; +import org.apache.doris.nereids.types.TinyIntType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * AggregateFunction 'sum0'. sum0 returns the sum of the values which go into it like sum. + * It differs in that when no non null values are applied zero is returned instead of null. + */ +public class Sum0 extends AggregateFunction + implements UnaryExpression, AlwaysNotNullable, ExplicitlyCastableSignature, ComputePrecisionForSum, + SupportWindowAnalytic, CouldRollUp { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(BigIntType.INSTANCE).args(BooleanType.INSTANCE), + FunctionSignature.ret(BigIntType.INSTANCE).args(TinyIntType.INSTANCE), + FunctionSignature.ret(BigIntType.INSTANCE).args(SmallIntType.INSTANCE), + FunctionSignature.ret(BigIntType.INSTANCE).args(IntegerType.INSTANCE), + FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE), + FunctionSignature.ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE), + FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD), + FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE) + ); + + /** + * constructor with 1 argument. + */ + public Sum0(Expression arg) { + this(false, arg); + } + + /** + * constructor with 2 argument. + */ + public Sum0(boolean distinct, Expression arg) { + super("sum0", distinct, arg); + } + + public MultiDistinctSum0 convertToMultiDistinct() { + Preconditions.checkArgument(distinct, + "can't convert to multi_distinct_sum because there is no distinct args"); + return new MultiDistinctSum0(false, child()); + } + + @Override + public void checkLegalityBeforeTypeCoercion() { + DataType argType = child().getDataType(); + if ((!argType.isNumericType() && !argType.isBooleanType() && !argType.isNullType()) + || argType.isOnlyMetricType()) { + throw new AnalysisException("sum0 requires a numeric or boolean parameter: " + this.toSql()); + } + } + + /** + * withDistinctAndChildren. + */ + @Override + public Sum0 withDistinctAndChildren(boolean distinct, List children) { + Preconditions.checkArgument(children.size() == 1); + return new Sum0(distinct, children.get(0)); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitSum0(this, context); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public FunctionSignature searchSignature(List signatures) { + if (getArgument(0).getDataType() instanceof FloatType) { + return FunctionSignature.ret(DoubleType.INSTANCE).args(FloatType.INSTANCE); + } + return ExplicitlyCastableSignature.super.searchSignature(signatures); + } + + @Override + public Function constructRollUp(Expression param, Expression... varParams) { + return new Sum0(this.distinct, param); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java index 594f9c7543..febe93974f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/AggregateFunctionVisitor.java @@ -51,6 +51,7 @@ import org.apache.doris.nereids.trees.expressions.functions.agg.MinBy; import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctCount; import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctGroupConcat; import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctSum; +import org.apache.doris.nereids.trees.expressions.functions.agg.MultiDistinctSum0; import org.apache.doris.nereids.trees.expressions.functions.agg.Ndv; import org.apache.doris.nereids.trees.expressions.functions.agg.NullableAggregateFunction; import org.apache.doris.nereids.trees.expressions.functions.agg.OrthogonalBitmapIntersect; @@ -66,6 +67,7 @@ import org.apache.doris.nereids.trees.expressions.functions.agg.SequenceMatch; import org.apache.doris.nereids.trees.expressions.functions.agg.Stddev; import org.apache.doris.nereids.trees.expressions.functions.agg.StddevSamp; import org.apache.doris.nereids.trees.expressions.functions.agg.Sum; +import org.apache.doris.nereids.trees.expressions.functions.agg.Sum0; import org.apache.doris.nereids.trees.expressions.functions.agg.TopN; import org.apache.doris.nereids.trees.expressions.functions.agg.TopNArray; import org.apache.doris.nereids.trees.expressions.functions.agg.TopNWeighted; @@ -162,6 +164,10 @@ public interface AggregateFunctionVisitor { return visitAggregateFunction(multiDistinctSum, context); } + default R visitMultiDistinctSum0(MultiDistinctSum0 multiDistinctSum0, C context) { + return visitAggregateFunction(multiDistinctSum0, context); + } + default R visitGroupBitAnd(GroupBitAnd groupBitAnd, C context) { return visitNullableAggregateFunction(groupBitAnd, context); } @@ -274,6 +280,10 @@ public interface AggregateFunctionVisitor { return visitNullableAggregateFunction(sum, context); } + default R visitSum0(Sum0 sum0, C context) { + return visitAggregateFunction(sum0, context); + } + default R visitTopN(TopN topN, C context) { return visitAggregateFunction(topN, context); } diff --git a/regression-test/data/nereids_function_p0/agg_function/agg.out b/regression-test/data/nereids_function_p0/agg_function/agg.out index bfd27bf07d..fc4dd3c611 100644 --- a/regression-test/data/nereids_function_p0/agg_function/agg.out +++ b/regression-test/data/nereids_function_p0/agg_function/agg.out @@ -265,7 +265,7 @@ -- !sql_avg_Double_gb -- \N -0.39999999999999997 +0.4 1.0 -- !sql_avg_Double -- @@ -298,7 +298,7 @@ 12 0.65 -- !sql_avg_Double_gb_notnull -- -0.39999999999999997 +0.4 1.0 -- !sql_avg_Double_notnull -- @@ -323,7 +323,7 @@ -- !sql_avg_Double_agg_phase_3_notnull -- 0 \N -7 0.39999999999999997 +7 0.4 5 1.0 -- !sql_avg_Double_agg_phase_4_notnull -- @@ -397,11 +397,11 @@ -- !sql_avg_weighted_TinyInt_Double_gb -- \N -5.0 +5.000000000000001 10.2 -- !sql_avg_weighted_TinyInt_Double -- -8.333333333333332 +8.333333333333334 -- !sql_avg_weighted_TinyInt_Double_agg_phase_1 -- 0 \N @@ -419,22 +419,22 @@ 1 12.0 -- !sql_avg_weighted_TinyInt_Double_agg_phase_2 -- -12 8.333333333333334 +12 8.333333333333332 -- !sql_avg_weighted_TinyInt_Double_agg_phase_3 -- 0 \N -7 5.0 +7 4.999999999999999 5 10.2 -- !sql_avg_weighted_TinyInt_Double_agg_phase_4 -- -12 8.333333333333334 +12 8.333333333333332 -- !sql_avg_weighted_TinyInt_Double_gb_notnull -- -5.0 -10.200000000000001 +4.999999999999999 +10.2 -- !sql_avg_weighted_TinyInt_Double_notnull -- -8.333333333333334 +8.333333333333332 -- !sql_avg_weighted_TinyInt_Double_agg_phase_1_notnull -- 1 1.0 @@ -451,19 +451,19 @@ 1 12.0 -- !sql_avg_weighted_TinyInt_Double_agg_phase_2_notnull -- -12 8.333333333333332 +12 8.333333333333334 -- !sql_avg_weighted_TinyInt_Double_agg_phase_3_notnull -- 0 \N -7 5.0 +7 4.999999999999999 5 10.2 -- !sql_avg_weighted_TinyInt_Double_agg_phase_4_notnull -- -12 8.333333333333332 +12 8.333333333333334 -- !sql_avg_weighted_SmallInt_Double_gb -- \N -4.999999999999999 +5.0 10.2 -- !sql_avg_weighted_SmallInt_Double -- @@ -485,18 +485,18 @@ 1 12.0 -- !sql_avg_weighted_SmallInt_Double_agg_phase_2 -- -12 8.333333333333332 +12 8.333333333333334 -- !sql_avg_weighted_SmallInt_Double_agg_phase_3 -- 0 \N -7 5.0 +7 4.999999999999999 5 10.2 -- !sql_avg_weighted_SmallInt_Double_agg_phase_4 -- -12 8.333333333333334 +12 8.333333333333332 -- !sql_avg_weighted_SmallInt_Double_gb_notnull -- -5.0 +4.999999999999999 10.2 -- !sql_avg_weighted_SmallInt_Double_notnull -- @@ -517,19 +517,19 @@ 1 12.0 -- !sql_avg_weighted_SmallInt_Double_agg_phase_2_notnull -- -12 8.333333333333332 +12 8.333333333333334 -- !sql_avg_weighted_SmallInt_Double_agg_phase_3_notnull -- 0 \N -7 5.0 +7 4.999999999999999 5 10.2 -- !sql_avg_weighted_SmallInt_Double_agg_phase_4_notnull -- -12 8.333333333333332 +12 8.333333333333334 -- !sql_avg_weighted_Integer_Double_gb -- \N -4.999999999999999 +5.000000000000001 10.2 -- !sql_avg_weighted_Integer_Double -- @@ -551,7 +551,7 @@ 1 12.0 -- !sql_avg_weighted_Integer_Double_agg_phase_2 -- -12 8.333333333333334 +12 8.333333333333332 -- !sql_avg_weighted_Integer_Double_agg_phase_3 -- 0 \N @@ -559,14 +559,14 @@ 5 10.2 -- !sql_avg_weighted_Integer_Double_agg_phase_4 -- -12 8.333333333333334 +12 8.333333333333332 -- !sql_avg_weighted_Integer_Double_gb_notnull -- -4.999999999999999 -10.2 +5.0 +10.199999999999998 -- !sql_avg_weighted_Integer_Double_notnull -- -8.333333333333332 +8.333333333333334 -- !sql_avg_weighted_Integer_Double_agg_phase_1_notnull -- 1 1.0 @@ -583,12 +583,12 @@ 1 12.0 -- !sql_avg_weighted_Integer_Double_agg_phase_2_notnull -- -12 8.333333333333334 +12 8.333333333333332 -- !sql_avg_weighted_Integer_Double_agg_phase_3_notnull -- 0 \N 7 5.0 -5 10.199999999999998 +5 10.2 -- !sql_avg_weighted_Integer_Double_agg_phase_4_notnull -- 12 8.333333333333332 @@ -617,7 +617,7 @@ 1 12.0 -- !sql_avg_weighted_BigInt_Double_agg_phase_2 -- -12 8.333333333333332 +12 8.333333333333334 -- !sql_avg_weighted_BigInt_Double_agg_phase_3 -- 0 \N @@ -628,11 +628,11 @@ 12 8.333333333333334 -- !sql_avg_weighted_BigInt_Double_gb_notnull -- -5.000000000000001 +4.999999999999999 10.2 -- !sql_avg_weighted_BigInt_Double_notnull -- -8.333333333333332 +8.333333333333334 -- !sql_avg_weighted_BigInt_Double_agg_phase_1_notnull -- 1 1.0 @@ -661,11 +661,11 @@ -- !sql_avg_weighted_Float_Double_gb -- \N -0.5000000045235669 +0.5000000045235667 1.0200000143051147 -- !sql_avg_weighted_Float_Double -- -0.833333344127123 +0.8333333441271231 -- !sql_avg_weighted_Float_Double_agg_phase_1 -- 0 \N @@ -683,7 +683,7 @@ 1 1.2000000476837158 -- !sql_avg_weighted_Float_Double_agg_phase_2 -- -12 0.8333333441271231 +12 0.833333344127123 -- !sql_avg_weighted_Float_Double_agg_phase_3 -- 0 \N @@ -691,14 +691,14 @@ 5 1.0200000143051147 -- !sql_avg_weighted_Float_Double_agg_phase_4 -- -12 0.8333333441271233 +12 0.833333344127123 -- !sql_avg_weighted_Float_Double_gb_notnull -- -0.5000000045235666 +0.5000000045235669 1.0200000143051147 -- !sql_avg_weighted_Float_Double_notnull -- -0.8333333441271233 +0.833333344127123 -- !sql_avg_weighted_Float_Double_agg_phase_1_notnull -- 1 0.10000000149011612 @@ -727,11 +727,11 @@ -- !sql_avg_weighted_Double_Double_gb -- \N -0.5 +0.49999999999999994 1.02 -- !sql_avg_weighted_Double_Double -- -0.8333333333333333 +0.8333333333333334 -- !sql_avg_weighted_Double_Double_agg_phase_1 -- 0 \N @@ -749,22 +749,22 @@ 1 1.2 -- !sql_avg_weighted_Double_Double_agg_phase_2 -- -12 0.8333333333333334 +12 0.8333333333333335 -- !sql_avg_weighted_Double_Double_agg_phase_3 -- 0 \N 7 0.5000000000000001 -5 1.0199999999999998 +5 1.02 -- !sql_avg_weighted_Double_Double_agg_phase_4 -- -12 0.8333333333333333 +12 0.8333333333333334 -- !sql_avg_weighted_Double_Double_gb_notnull -- 0.5 -1.0199999999999998 +1.02 -- !sql_avg_weighted_Double_Double_notnull -- -0.8333333333333335 +0.8333333333333331 -- !sql_avg_weighted_Double_Double_agg_phase_1_notnull -- 1 0.10000000000000002 @@ -781,23 +781,23 @@ 1 1.2 -- !sql_avg_weighted_Double_Double_agg_phase_2_notnull -- -12 0.8333333333333333 +12 0.8333333333333334 -- !sql_avg_weighted_Double_Double_agg_phase_3_notnull -- 0 \N -7 0.49999999999999994 +7 0.5000000000000001 5 1.02 -- !sql_avg_weighted_Double_Double_agg_phase_4_notnull -- -12 0.8333333333333335 +12 0.8333333333333333 -- !sql_avg_weighted_DecimalV2_Double_gb -- \N -0.5000000000000001 +0.5 1.02 -- !sql_avg_weighted_DecimalV2_Double -- -0.8333333333333334 +0.8333333333333333 -- !sql_avg_weighted_DecimalV2_Double_agg_phase_1 -- 0 \N @@ -819,7 +819,7 @@ -- !sql_avg_weighted_DecimalV2_Double_agg_phase_3 -- 0 \N -7 0.5000000000000001 +7 0.49999999999999994 5 1.02 -- !sql_avg_weighted_DecimalV2_Double_agg_phase_4 -- @@ -827,7 +827,7 @@ -- !sql_avg_weighted_DecimalV2_Double_gb_notnull -- 0.5 -1.02 +1.0199999999999998 -- !sql_avg_weighted_DecimalV2_Double_notnull -- 0.8333333333333333 @@ -852,10 +852,10 @@ -- !sql_avg_weighted_DecimalV2_Double_agg_phase_3_notnull -- 0 \N 7 0.5000000000000001 -5 1.02 +5 1.0199999999999998 -- !sql_avg_weighted_DecimalV2_Double_agg_phase_4_notnull -- -12 0.8333333333333333 +12 0.8333333333333334 -- !sql_bitmap_intersect_Bitmap_gb -- \N @@ -3327,7 +3327,7 @@ true -- !sql_stddev_TinyInt_agg_phase_3 -- 0 \N -7 2.0 +7 1.9999999999999998 5 1.4142135623730951 -- !sql_stddev_TinyInt_agg_phase_4 -- @@ -3367,7 +3367,7 @@ true -- !sql_stddev_SmallInt_gb -- \N -1.9999999999999998 +2.0 1.4142135623730951 -- !sql_stddev_SmallInt -- @@ -3393,7 +3393,7 @@ true -- !sql_stddev_SmallInt_agg_phase_3 -- 0 \N -7 2.0 +7 1.9999999999999998 5 1.4142135623730951 -- !sql_stddev_SmallInt_agg_phase_4 -- @@ -3426,7 +3426,7 @@ true -- !sql_stddev_SmallInt_agg_phase_3_notnull -- 0 \N 7 2.0 -5 1.4142135623730951 +5 1.4142135623730954 -- !sql_stddev_SmallInt_agg_phase_4_notnull -- 12 3.452052529534663 @@ -3434,10 +3434,10 @@ true -- !sql_stddev_Integer_gb -- \N 1.9999999999999998 -1.414213562373095 +1.4142135623730951 -- !sql_stddev_Integer -- -3.452052529534664 +3.452052529534663 -- !sql_stddev_Integer_agg_phase_1 -- 0 \N @@ -3459,7 +3459,7 @@ true -- !sql_stddev_Integer_agg_phase_3 -- 0 \N -7 1.9999999999999998 +7 2.0 5 1.4142135623730951 -- !sql_stddev_Integer_agg_phase_4 -- @@ -3491,7 +3491,7 @@ true -- !sql_stddev_Integer_agg_phase_3_notnull -- 0 \N -7 2.0 +7 1.9999999999999998 5 1.4142135623730951 -- !sql_stddev_Integer_agg_phase_4_notnull -- @@ -3503,7 +3503,7 @@ true 1.4142135623730951 -- !sql_stddev_BigInt -- -3.452052529534664 +3.452052529534663 -- !sql_stddev_BigInt_agg_phase_1 -- 0 \N @@ -3587,7 +3587,7 @@ true 1 0.0 -- !sql_stddev_Float_agg_phase_2 -- -12 0.3452052585470726 +12 0.34520525854707257 -- !sql_stddev_Float_agg_phase_3 -- 0 \N @@ -3595,7 +3595,7 @@ true 5 0.1414213730960499 -- !sql_stddev_Float_agg_phase_4 -- -12 0.3452052585470726 +12 0.34520525854707257 -- !sql_stddev_Float_gb_notnull -- 0.1999999992549422 @@ -3631,7 +3631,7 @@ true -- !sql_stddev_Double_gb -- \N -0.19999999999999998 +0.2 0.1414213562373095 -- !sql_stddev_Double -- @@ -3653,7 +3653,7 @@ true 1 0.0 -- !sql_stddev_Double_agg_phase_2 -- -12 0.34520525295346627 +12 0.3452052529534663 -- !sql_stddev_Double_agg_phase_3 -- 0 \N @@ -3685,11 +3685,11 @@ true 1 0.0 -- !sql_stddev_Double_agg_phase_2_notnull -- -12 0.34520525295346627 +12 0.3452052529534663 -- !sql_stddev_Double_agg_phase_3_notnull -- 0 \N -7 0.19999999999999996 +7 0.2 5 0.1414213562373095 -- !sql_stddev_Double_agg_phase_4_notnull -- @@ -3716,18 +3716,18 @@ true 1 0.0 -- !sql_stddev_DecimalV2_agg_phase_2 -- -12 0.34520525295346627 +12 0.3452052529534663 -- !sql_stddev_DecimalV2_agg_phase_3 -- 0 \N -7 0.19999999999999996 +7 0.19999999999999998 5 0.1414213562373095 -- !sql_stddev_DecimalV2_agg_phase_4 -- 12 0.3452052529534663 -- !sql_stddev_DecimalV2_gb_notnull -- -0.19999999999999998 +0.19999999999999996 0.1414213562373095 -- !sql_stddev_DecimalV2_agg_phase_1_notnull -- @@ -3745,11 +3745,11 @@ true 1 0.0 -- !sql_stddev_DecimalV2_agg_phase_2_notnull -- -12 0.34520525295346627 +12 0.3452052529534663 -- !sql_stddev_DecimalV2_agg_phase_3_notnull -- 0 \N -7 0.19999999999999998 +7 0.19999999999999996 5 0.1414213562373095 -- !sql_stddev_DecimalV2_agg_phase_4_notnull -- @@ -3784,7 +3784,7 @@ true -- !sql_stddev_samp_TinyInt_agg_phase_3 -- 0 \N 7 2.160246899469287 -5 1.5811388300841898 +5 1.58113883008419 -- !sql_stddev_samp_TinyInt_agg_phase_4 -- 12 3.605551275463989 @@ -3794,7 +3794,7 @@ true 1.5811388300841898 -- !sql_stddev_samp_TinyInt_notnull -- -3.605551275463989 +3.6055512754639896 -- !sql_stddev_samp_TinyInt_agg_phase_1_notnull -- 1 \N @@ -3815,7 +3815,7 @@ true -- !sql_stddev_samp_TinyInt_agg_phase_3_notnull -- 0 \N -7 2.160246899469287 +7 2.1602468994692865 5 1.5811388300841898 -- !sql_stddev_samp_TinyInt_agg_phase_4_notnull -- @@ -3823,7 +3823,7 @@ true -- !sql_stddev_samp_SmallInt_gb -- \N -2.160246899469287 +2.1602468994692865 1.5811388300841898 -- !sql_stddev_samp_SmallInt -- @@ -3849,7 +3849,7 @@ true -- !sql_stddev_samp_SmallInt_agg_phase_3 -- 0 \N -7 2.1602468994692865 +7 2.160246899469287 5 1.5811388300841898 -- !sql_stddev_samp_SmallInt_agg_phase_4 -- @@ -3881,7 +3881,7 @@ true -- !sql_stddev_samp_SmallInt_agg_phase_3_notnull -- 0 \N -7 2.160246899469287 +7 2.1602468994692865 5 1.5811388300841898 -- !sql_stddev_samp_SmallInt_agg_phase_4_notnull -- @@ -3915,14 +3915,14 @@ true -- !sql_stddev_samp_Integer_agg_phase_3 -- 0 \N -7 2.160246899469287 +7 2.1602468994692865 5 1.5811388300841898 -- !sql_stddev_samp_Integer_agg_phase_4 -- 12 3.605551275463989 -- !sql_stddev_samp_Integer_gb_notnull -- -2.1602468994692865 +2.160246899469287 1.5811388300841898 -- !sql_stddev_samp_Integer_notnull -- @@ -3947,8 +3947,8 @@ true -- !sql_stddev_samp_Integer_agg_phase_3_notnull -- 0 \N -7 2.1602468994692865 -5 1.5811388300841898 +7 2.160246899469287 +5 1.58113883008419 -- !sql_stddev_samp_Integer_agg_phase_4_notnull -- 12 3.605551275463989 @@ -3956,10 +3956,10 @@ true -- !sql_stddev_samp_BigInt_gb -- \N 2.1602468994692865 -1.5811388300841893 +1.5811388300841898 -- !sql_stddev_samp_BigInt -- -3.605551275463989 +3.6055512754639896 -- !sql_stddev_samp_BigInt_agg_phase_1 -- 0 \N @@ -3981,8 +3981,8 @@ true -- !sql_stddev_samp_BigInt_agg_phase_3 -- 0 \N -7 2.160246899469287 -5 1.58113883008419 +7 2.1602468994692865 +5 1.5811388300841898 -- !sql_stddev_samp_BigInt_agg_phase_4 -- 12 3.605551275463989 @@ -3992,7 +3992,7 @@ true 1.5811388300841898 -- !sql_stddev_samp_BigInt_notnull -- -3.605551275463989 +3.6055512754639896 -- !sql_stddev_samp_BigInt_agg_phase_1_notnull -- 1 \N @@ -4054,7 +4054,7 @@ true 12 0.36055513338873013 -- !sql_stddev_samp_Float_gb_notnull -- -0.2160246891421743 +0.21602468914217424 0.15811390185706375 -- !sql_stddev_samp_Float_notnull -- @@ -4088,7 +4088,7 @@ true -- !sql_stddev_samp_Double_gb -- \N 0.21602468994692867 -0.15811388300841897 +0.15811388300841894 -- !sql_stddev_samp_Double -- 0.36055512754639896 @@ -4109,19 +4109,19 @@ true 1 \N -- !sql_stddev_samp_Double_agg_phase_2 -- -12 0.36055512754639896 +12 0.3605551275463989 -- !sql_stddev_samp_Double_agg_phase_3 -- 0 \N 7 0.21602468994692867 -5 0.15811388300841894 +5 0.15811388300841897 -- !sql_stddev_samp_Double_agg_phase_4 -- 12 0.36055512754639896 -- !sql_stddev_samp_Double_gb_notnull -- -0.21602468994692864 -0.15811388300841897 +0.21602468994692867 +0.15811388300841894 -- !sql_stddev_samp_Double_notnull -- 0.36055512754639896 @@ -4146,10 +4146,10 @@ true -- !sql_stddev_samp_Double_agg_phase_3_notnull -- 0 \N 7 0.21602468994692864 -5 0.15811388300841894 +5 0.15811388300841897 -- !sql_stddev_samp_Double_agg_phase_4_notnull -- -12 0.36055512754639896 +12 0.3605551275463989 -- !sql_stddev_samp_DecimalV2_agg_phase_1 -- 0 \N @@ -4172,10 +4172,10 @@ true -- !sql_stddev_samp_DecimalV2_agg_phase_3 -- 0 \N 7 0.21602468994692864 -5 0.15811388300841897 +5 0.15811388300841894 -- !sql_stddev_samp_DecimalV2_agg_phase_4 -- -12 0.36055512754639896 +12 0.3605551275463989 -- !sql_stddev_samp_DecimalV2_agg_phase_1_notnull -- 1 \N @@ -4196,8 +4196,8 @@ true -- !sql_stddev_samp_DecimalV2_agg_phase_3_notnull -- 0 \N -7 0.21602468994692864 -5 0.15811388300841894 +7 0.21602468994692867 +5 0.15811388300841897 -- !sql_stddev_samp_DecimalV2_agg_phase_4_notnull -- 12 0.36055512754639896 @@ -4486,11 +4486,11 @@ true -- !sql_sum_Double_gb -- \N -2.8 +2.8000000000000003 5.0 -- !sql_sum_Double -- -7.8 +7.800000000000001 -- !sql_sum_Double_agg_phase_1 -- 0 \N @@ -4508,7 +4508,7 @@ true 1 1.2 -- !sql_sum_Double_agg_phase_2 -- -12 7.800000000000001 +12 7.8 -- !sql_sum_Double_agg_phase_3 -- 0 \N @@ -4516,14 +4516,14 @@ true 5 5.0 -- !sql_sum_Double_agg_phase_4 -- -12 7.8 +12 7.800000000000001 -- !sql_sum_Double_gb_notnull -- -2.8000000000000003 +2.8 5.0 -- !sql_sum_Double_notnull -- -7.800000000000001 +7.8 -- !sql_sum_Double_agg_phase_1_notnull -- 1 0.1 @@ -4540,7 +4540,7 @@ true 1 1.2 -- !sql_sum_Double_agg_phase_2_notnull -- -12 7.800000000000001 +12 7.8 -- !sql_sum_Double_agg_phase_3_notnull -- 0 \N @@ -4548,7 +4548,7 @@ true 5 5.0 -- !sql_sum_Double_agg_phase_4_notnull -- -12 7.800000000000001 +12 7.799999999999999 -- !sql_sum_DecimalV2_gb -- \N @@ -4682,6 +4682,486 @@ true -- !sql_sum_LargeInt_agg_phase_4_notnull -- 12 78 +-- !sql_sum0_Boolean -- +5 + +-- !sql_sum0_Boolean_gb -- +0 +0 +0 +0 +0 +0 +0 +0 +1 +1 +1 +1 +1 + +-- !sql_sum0_TinyInt_gb -- +0 +28 +50 + +-- !sql_sum0_TinyInt -- +78 + +-- !sql_sum0_TinyInt_agg_phase_1 -- +0 0 +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_TinyInt_agg_phase_2 -- +12 78 + +-- !sql_sum0_TinyInt_agg_phase_3 -- +0 0 +7 28 +5 50 + +-- !sql_sum0_TinyInt_agg_phase_4 -- +12 78 + +-- !sql_sum0_TinyInt_gb_notnull -- +28 +50 + +-- !sql_sum0_TinyInt_notnull -- +78 + +-- !sql_sum0_TinyInt_agg_phase_1_notnull -- +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_TinyInt_agg_phase_2_notnull -- +12 78 + +-- !sql_sum0_TinyInt_agg_phase_3_notnull -- +0 0 +7 28 +5 50 + +-- !sql_sum0_TinyInt_agg_phase_4_notnull -- +12 78 + +-- !sql_sum0_SmallInt_gb -- +0 +28 +50 + +-- !sql_sum0_SmallInt -- +78 + +-- !sql_sum0_SmallInt_agg_phase_1 -- +0 0 +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_SmallInt_agg_phase_2 -- +12 78 + +-- !sql_sum0_SmallInt_agg_phase_3 -- +0 0 +7 28 +5 50 + +-- !sql_sum0_SmallInt_agg_phase_4 -- +12 78 + +-- !sql_sum0_SmallInt_gb_notnull -- +28 +50 + +-- !sql_sum0_SmallInt_notnull -- +78 + +-- !sql_sum0_SmallInt_agg_phase_1_notnull -- +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_SmallInt_agg_phase_2_notnull -- +12 78 + +-- !sql_sum0_SmallInt_agg_phase_3_notnull -- +0 0 +7 28 +5 50 + +-- !sql_sum0_SmallInt_agg_phase_4_notnull -- +12 78 + +-- !sql_sum0_Integer_gb -- +0 +28 +50 + +-- !sql_sum0_Integer -- +78 + +-- !sql_sum0_Integer_agg_phase_1 -- +0 0 +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_Integer_agg_phase_2 -- +12 78 + +-- !sql_sum0_Integer_agg_phase_3 -- +0 0 +7 28 +5 50 + +-- !sql_sum0_Integer_agg_phase_4 -- +12 78 + +-- !sql_sum0_Integer_gb_notnull -- +28 +50 + +-- !sql_sum0_Integer_notnull -- +78 + +-- !sql_sum0_Integer_agg_phase_1_notnull -- +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_Integer_agg_phase_2_notnull -- +12 78 + +-- !sql_sum0_Integer_agg_phase_3_notnull -- +0 0 +7 28 +5 50 + +-- !sql_sum0_Integer_agg_phase_4_notnull -- +12 78 + +-- !sql_sum0_BigInt_gb -- +0 +28 +50 + +-- !sql_sum0_BigInt -- +78 + +-- !sql_sum0_BigInt_agg_phase_1 -- +0 0 +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_BigInt_agg_phase_2 -- +12 78 + +-- !sql_sum0_BigInt_agg_phase_3 -- +0 0 +7 28 +5 50 + +-- !sql_sum0_BigInt_agg_phase_4 -- +12 78 + +-- !sql_sum0_BigInt_gb_notnull -- +28 +50 + +-- !sql_sum0_BigInt_notnull -- +78 + +-- !sql_sum0_BigInt_agg_phase_1_notnull -- +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_BigInt_agg_phase_2_notnull -- +12 78 + +-- !sql_sum0_BigInt_agg_phase_3_notnull -- +0 0 +7 28 +5 50 + +-- !sql_sum0_BigInt_agg_phase_4_notnull -- +12 78 + +-- !sql_sum0_Double_gb -- +0.0 +2.8 +5.0 + +-- !sql_sum0_Double -- +7.800000000000001 + +-- !sql_sum0_Double_agg_phase_1 -- +0 0.0 +1 0.1 +1 0.2 +1 0.3 +1 0.4 +1 0.5 +1 0.6 +1 0.7 +1 0.8 +1 0.9 +1 1.0 +1 1.1 +1 1.2 + +-- !sql_sum0_Double_agg_phase_2 -- +12 7.800000000000001 + +-- !sql_sum0_Double_agg_phase_3 -- +0 0.0 +7 2.8000000000000003 +5 5.0 + +-- !sql_sum0_Double_agg_phase_4 -- +12 7.8 + +-- !sql_sum0_Double_gb_notnull -- +2.8 +5.0 + +-- !sql_sum0_Double_notnull -- +7.8 + +-- !sql_sum0_Double_agg_phase_1_notnull -- +1 0.1 +1 0.2 +1 0.3 +1 0.4 +1 0.5 +1 0.6 +1 0.7 +1 0.8 +1 0.9 +1 1.0 +1 1.1 +1 1.2 + +-- !sql_sum0_Double_agg_phase_2_notnull -- +12 7.8 + +-- !sql_sum0_Double_agg_phase_3_notnull -- +0 0.0 +7 2.8 +5 5.0 + +-- !sql_sum0_Double_agg_phase_4_notnull -- +12 7.800000000000001 + +-- !sql_sum0_DecimalV2_gb -- +0.000 +2.800 +5.000 + +-- !sql_sum0_DecimalV2 -- +7.800 + +-- !sql_sum0_DecimalV2_agg_phase_1 -- +0 0.000 +1 0.100 +1 0.200 +1 0.300 +1 0.400 +1 0.500 +1 0.600 +1 0.700 +1 0.800 +1 0.900 +1 1.000 +1 1.100 +1 1.200 + +-- !sql_sum0_DecimalV2_agg_phase_2 -- +12 7.800 + +-- !sql_sum0_DecimalV2_agg_phase_3 -- +0 0.000 +7 2.800 +5 5.000 + +-- !sql_sum0_DecimalV2_agg_phase_4 -- +12 7.800 + +-- !sql_sum0_DecimalV2_gb_notnull -- +2.800 +5.000 + +-- !sql_sum0_DecimalV2_notnull -- +7.800 + +-- !sql_sum0_DecimalV2_agg_phase_1_notnull -- +1 0.100 +1 0.200 +1 0.300 +1 0.400 +1 0.500 +1 0.600 +1 0.700 +1 0.800 +1 0.900 +1 1.000 +1 1.100 +1 1.200 + +-- !sql_sum0_DecimalV2_agg_phase_2_notnull -- +12 7.800 + +-- !sql_sum0_DecimalV2_agg_phase_3_notnull -- +0 0.000 +7 2.800 +5 5.000 + +-- !sql_sum0_DecimalV2_agg_phase_4_notnull -- +12 7.800 + +-- !sql_sum0_LargeInt_gb -- +0 +28 +50 + +-- !sql_sum0_LargeInt -- +78 + +-- !sql_sum0_LargeInt_agg_phase_1 -- +0 0 +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_LargeInt_agg_phase_2 -- +12 78 + +-- !sql_sum0_LargeInt_agg_phase_3 -- +0 0 +7 28 +5 50 + +-- !sql_sum0_LargeInt_agg_phase_4 -- +12 78 + +-- !sql_sum0_LargeInt_gb_notnull -- +28 +50 + +-- !sql_sum0_LargeInt_notnull -- +78 + +-- !sql_sum0_LargeInt_agg_phase_1_notnull -- +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +1 12 + +-- !sql_sum0_LargeInt_agg_phase_2_notnull -- +12 78 + +-- !sql_sum0_LargeInt_agg_phase_3_notnull -- +0 0 +7 28 +5 50 + +-- !sql_sum0_LargeInt_agg_phase_4_notnull -- +12 78 + -- !sql_topn_Varchar_Integer_gb -- {"null":1} {"varchar11":3,"varchar13":2,"varchar12":2} @@ -4949,7 +5429,7 @@ true -- !sql_variance_TinyInt_gb -- \N 3.9999999999999996 -2.0000000000000004 +1.9999999999999993 -- !sql_variance_TinyInt -- 11.916666666666666 @@ -4975,14 +5455,14 @@ true -- !sql_variance_TinyInt_agg_phase_3 -- 0 \N 7 4.0 -5 2.0 +5 2.000000000000001 -- !sql_variance_TinyInt_agg_phase_4 -- 12 11.916666666666666 -- !sql_variance_TinyInt_gb_notnull -- 4.0 -2.0 +2.0000000000000004 -- !sql_variance_TinyInt_notnull -- 11.916666666666666 @@ -5007,7 +5487,7 @@ true -- !sql_variance_TinyInt_agg_phase_3_notnull -- 0 \N 7 4.0 -5 2.0 +5 2.000000000000001 -- !sql_variance_TinyInt_agg_phase_4_notnull -- 12 11.916666666666666 @@ -5015,7 +5495,7 @@ true -- !sql_variance_SmallInt_gb -- \N 3.9999999999999996 -2.0 +1.9999999999999993 -- !sql_variance_SmallInt -- 11.916666666666666 @@ -5040,18 +5520,18 @@ true -- !sql_variance_SmallInt_agg_phase_3 -- 0 \N -7 3.9999999999999996 -5 2.0 +7 4.0 +5 2.000000000000001 -- !sql_variance_SmallInt_agg_phase_4 -- 12 11.916666666666666 -- !sql_variance_SmallInt_gb_notnull -- -4.0 +3.9999999999999996 2.0 -- !sql_variance_SmallInt_notnull -- -11.91666666666667 +11.916666666666666 -- !sql_variance_SmallInt_agg_phase_1_notnull -- 1 0.0 @@ -5072,16 +5552,16 @@ true -- !sql_variance_SmallInt_agg_phase_3_notnull -- 0 \N -7 3.9999999999999996 -5 2.0 +7 4.0 +5 2.000000000000001 -- !sql_variance_SmallInt_agg_phase_4_notnull -- 12 11.916666666666666 -- !sql_variance_Integer_gb -- \N -4.0 -2.0000000000000004 +3.9999999999999996 +2.0 -- !sql_variance_Integer -- 11.916666666666666 @@ -5106,15 +5586,15 @@ true -- !sql_variance_Integer_agg_phase_3 -- 0 \N -7 4.0 -5 2.000000000000001 +7 3.9999999999999996 +5 2.0000000000000004 -- !sql_variance_Integer_agg_phase_4 -- 12 11.916666666666666 -- !sql_variance_Integer_gb_notnull -- -3.9999999999999996 -2.0 +4.0 +2.0000000000000004 -- !sql_variance_Integer_notnull -- 11.916666666666666 @@ -5138,15 +5618,15 @@ true -- !sql_variance_Integer_agg_phase_3_notnull -- 0 \N -7 4.0 -5 2.0 +7 3.9999999999999996 +5 1.9999999999999993 -- !sql_variance_Integer_agg_phase_4_notnull -- 12 11.916666666666666 -- !sql_variance_BigInt_gb -- \N -4.0 +3.999999999999999 2.0 -- !sql_variance_BigInt -- @@ -5172,14 +5652,14 @@ true -- !sql_variance_BigInt_agg_phase_3 -- 0 \N -7 4.000000000000001 +7 3.9999999999999996 5 2.0 -- !sql_variance_BigInt_agg_phase_4 -- 12 11.916666666666666 -- !sql_variance_BigInt_gb_notnull -- -3.9999999999999996 +4.0 2.0 -- !sql_variance_BigInt_notnull -- @@ -5204,16 +5684,16 @@ true -- !sql_variance_BigInt_agg_phase_3_notnull -- 0 \N -7 4.0 -5 2.0 +7 3.9999999999999996 +5 2.0000000000000004 -- !sql_variance_BigInt_agg_phase_4_notnull -- 12 11.916666666666666 -- !sql_variance_Float_gb -- \N -0.039999999701976874 -0.020000004768372152 +0.03999999970197688 +0.02000000476837215 -- !sql_variance_Float -- 0.11916667052855125 @@ -5245,7 +5725,7 @@ true 12 0.11916667052855125 -- !sql_variance_Float_gb_notnull -- -0.039999999701976874 +0.03999999970197688 0.020000004768372152 -- !sql_variance_Float_notnull -- @@ -5270,19 +5750,19 @@ true -- !sql_variance_Float_agg_phase_3_notnull -- 0 \N -7 0.039999999701976874 +7 0.03999999970197688 5 0.020000004768372152 -- !sql_variance_Float_agg_phase_4_notnull -- -12 0.11916667052855123 +12 0.11916667052855125 -- !sql_variance_Double_gb -- \N 0.039999999999999994 -0.019999999999999997 +0.019999999999999993 -- !sql_variance_Double -- -0.11916666666666668 +0.11916666666666666 -- !sql_variance_Double_agg_phase_1 -- 0 \N @@ -5300,15 +5780,15 @@ true 1 0.0 -- !sql_variance_Double_agg_phase_2 -- -12 0.11916666666666666 +12 0.11916666666666668 -- !sql_variance_Double_agg_phase_3 -- 0 \N 7 0.03999999999999999 -5 0.019999999999999993 +5 0.019999999999999997 -- !sql_variance_Double_agg_phase_4 -- -12 0.11916666666666666 +12 0.11916666666666668 -- !sql_variance_Double_gb_notnull -- 0.039999999999999994 @@ -5332,23 +5812,23 @@ true 1 0.0 -- !sql_variance_Double_agg_phase_2_notnull -- -12 0.11916666666666666 +12 0.11916666666666668 -- !sql_variance_Double_agg_phase_3_notnull -- 0 \N -7 0.039999999999999994 +7 0.03999999999999999 5 0.019999999999999997 -- !sql_variance_Double_agg_phase_4_notnull -- -12 0.11916666666666664 +12 0.11916666666666666 -- !sql_variance_DecimalV2_gb -- \N -0.039999999999999994 +0.04 0.02 -- !sql_variance_DecimalV2 -- -0.11916666666666668 +0.11916666666666666 -- !sql_variance_DecimalV2_agg_phase_1 -- 0 \N @@ -5366,11 +5846,11 @@ true 1 0.0 -- !sql_variance_DecimalV2_agg_phase_2 -- -12 0.11916666666666666 +12 0.11916666666666664 -- !sql_variance_DecimalV2_agg_phase_3 -- 0 \N -7 0.039999999999999994 +7 0.04 5 0.02 -- !sql_variance_DecimalV2_agg_phase_4 -- @@ -5378,7 +5858,7 @@ true -- !sql_variance_DecimalV2_gb_notnull -- 0.039999999999999994 -0.01999999999999999 +0.02 -- !sql_variance_DecimalV2_notnull -- 0.11916666666666666 @@ -5398,20 +5878,20 @@ true 1 0.0 -- !sql_variance_DecimalV2_agg_phase_2_notnull -- -12 0.11916666666666668 +12 0.11916666666666666 -- !sql_variance_DecimalV2_agg_phase_3_notnull -- 0 \N 7 0.039999999999999994 -5 0.02 +5 0.019999999999999987 -- !sql_variance_DecimalV2_agg_phase_4_notnull -- 12 0.11916666666666666 -- !sql_variance_samp_TinyInt_gb -- \N -4.666666666666667 -2.5 +4.666666666666666 +2.499999999999999 -- !sql_variance_samp_TinyInt -- 13.0 @@ -5436,14 +5916,14 @@ true -- !sql_variance_samp_TinyInt_agg_phase_3 -- 0 \N -7 4.666666666666667 +7 4.666666666666666 5 2.5 -- !sql_variance_samp_TinyInt_agg_phase_4 -- 12 13.0 -- !sql_variance_samp_TinyInt_gb_notnull -- -4.666666666666667 +4.666666666666666 2.5 -- !sql_variance_samp_TinyInt_notnull -- @@ -5468,8 +5948,8 @@ true -- !sql_variance_samp_TinyInt_agg_phase_3_notnull -- 0 \N -7 4.666666666666668 -5 2.5 +7 4.666666666666667 +5 2.500000000000001 -- !sql_variance_samp_TinyInt_agg_phase_4_notnull -- 12 13.0 @@ -5477,7 +5957,7 @@ true -- !sql_variance_samp_SmallInt_gb -- \N 4.666666666666667 -2.5000000000000004 +2.5 -- !sql_variance_samp_SmallInt -- 13.0 @@ -5502,7 +5982,7 @@ true -- !sql_variance_samp_SmallInt_agg_phase_3 -- 0 \N -7 4.666666666666667 +7 4.666666666666666 5 2.5 -- !sql_variance_samp_SmallInt_agg_phase_4 -- @@ -5510,10 +5990,10 @@ true -- !sql_variance_samp_SmallInt_gb_notnull -- 4.666666666666666 -2.499999999999999 +2.5 -- !sql_variance_samp_SmallInt_notnull -- -13.000000000000002 +13.0 -- !sql_variance_samp_SmallInt_agg_phase_1_notnull -- 1 \N @@ -5534,8 +6014,8 @@ true -- !sql_variance_samp_SmallInt_agg_phase_3_notnull -- 0 \N -7 4.666666666666667 -5 2.5 +7 4.666666666666666 +5 2.499999999999999 -- !sql_variance_samp_SmallInt_agg_phase_4_notnull -- 12 13.0 @@ -5543,7 +6023,7 @@ true -- !sql_variance_samp_Integer_gb -- \N 4.666666666666667 -2.5 +2.5000000000000004 -- !sql_variance_samp_Integer -- 13.0 @@ -5568,8 +6048,8 @@ true -- !sql_variance_samp_Integer_agg_phase_3 -- 0 \N -7 4.666666666666667 -5 2.5 +7 4.666666666666666 +5 2.5000000000000004 -- !sql_variance_samp_Integer_agg_phase_4 -- 12 13.0 @@ -5600,7 +6080,7 @@ true -- !sql_variance_samp_Integer_agg_phase_3_notnull -- 0 \N -7 4.666666666666666 +7 4.666666666666668 5 2.5 -- !sql_variance_samp_Integer_agg_phase_4_notnull -- @@ -5641,7 +6121,7 @@ true 12 13.0 -- !sql_variance_samp_BigInt_gb_notnull -- -4.666666666666667 +4.666666666666666 2.5 -- !sql_variance_samp_BigInt_notnull -- @@ -5666,7 +6146,7 @@ true -- !sql_variance_samp_BigInt_agg_phase_3_notnull -- 0 \N -7 4.666666666666666 +7 4.666666666666668 5 2.5 -- !sql_variance_samp_BigInt_agg_phase_4_notnull -- @@ -5674,8 +6154,8 @@ true -- !sql_variance_samp_Float_gb -- \N -0.04666666631897304 -0.025000005960465192 +0.04666666631897303 +0.02500000596046519 -- !sql_variance_samp_Float -- 0.130000004212965 @@ -5696,7 +6176,7 @@ true 1 \N -- !sql_variance_samp_Float_agg_phase_2 -- -12 0.130000004212965 +12 0.13000000421296498 -- !sql_variance_samp_Float_agg_phase_3 -- 0 \N @@ -5736,12 +6216,12 @@ true 5 0.02500000596046519 -- !sql_variance_samp_Float_agg_phase_4_notnull -- -12 0.130000004212965 +12 0.13000000421296498 -- !sql_variance_samp_Double_gb -- \N 0.04666666666666666 -0.024999999999999988 +0.024999999999999998 -- !sql_variance_samp_Double -- 0.13 @@ -5767,14 +6247,14 @@ true -- !sql_variance_samp_Double_agg_phase_3 -- 0 \N 7 0.04666666666666666 -5 0.024999999999999984 +5 0.024999999999999998 -- !sql_variance_samp_Double_agg_phase_4 -- 12 0.13 -- !sql_variance_samp_Double_gb_notnull -- 0.04666666666666666 -0.024999999999999994 +0.025 -- !sql_variance_samp_Double_notnull -- 0.13 @@ -5794,12 +6274,12 @@ true 1 \N -- !sql_variance_samp_Double_agg_phase_2_notnull -- -12 0.13 +12 0.12999999999999998 -- !sql_variance_samp_Double_agg_phase_3_notnull -- 0 \N 7 0.046666666666666655 -5 0.024999999999999988 +5 0.024999999999999994 -- !sql_variance_samp_Double_agg_phase_4_notnull -- 12 0.13 @@ -5825,10 +6305,10 @@ true -- !sql_variance_samp_DecimalV2_agg_phase_3 -- 0 \N 7 0.04666666666666666 -5 0.02499999999999999 +5 0.024999999999999994 -- !sql_variance_samp_DecimalV2_agg_phase_4 -- -12 0.13 +12 0.12999999999999998 -- !sql_variance_samp_DecimalV2_agg_phase_1_notnull -- 1 \N @@ -5849,7 +6329,7 @@ true -- !sql_variance_samp_DecimalV2_agg_phase_3_notnull -- 0 \N -7 0.046666666666666655 +7 0.04666666666666666 5 0.024999999999999988 -- !sql_variance_samp_DecimalV2_agg_phase_4_notnull -- diff --git a/regression-test/suites/nereids_function_p0/agg_function/agg.groovy b/regression-test/suites/nereids_function_p0/agg_function/agg.groovy index 81c84ad32d..087ca2cf9f 100644 --- a/regression-test/suites/nereids_function_p0/agg_function/agg.groovy +++ b/regression-test/suites/nereids_function_p0/agg_function/agg.groovy @@ -2269,6 +2269,191 @@ suite("nereids_agg_fn") { qt_sql_sum_LargeInt_agg_phase_4_notnull ''' select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum(klint) from fn_test''' + qt_sql_sum0_Boolean ''' + select sum0(kbool) from fn_test''' + qt_sql_sum0_Boolean_gb ''' + select sum0(kbool) from fn_test group by id order by id''' + qt_sql_sum0_TinyInt_gb ''' + select sum0(ktint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_TinyInt ''' + select sum0(ktint) from fn_test''' + qt_sql_sum0_TinyInt_agg_phase_1 ''' + select count(id), sum0(ktint) from fn_test group by id order by id''' + qt_sql_sum0_TinyInt_agg_phase_2 ''' + select count(distinct id), sum0(ktint) from fn_test''' + qt_sql_sum0_TinyInt_agg_phase_3 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(ktint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_TinyInt_agg_phase_4 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(ktint) from fn_test''' + qt_sql_sum0_TinyInt_gb_notnull ''' + select sum0(ktint) from fn_test_not_nullable group by kbool order by kbool''' + qt_sql_sum0_TinyInt_notnull ''' + select sum0(ktint) from fn_test_not_nullable''' + qt_sql_sum0_TinyInt_agg_phase_1_notnull ''' + select count(id), sum0(ktint) from fn_test_not_nullable group by id order by id''' + qt_sql_sum0_TinyInt_agg_phase_2_notnull ''' + select count(distinct id), sum0(ktint) from fn_test_not_nullable''' + qt_sql_sum0_TinyInt_agg_phase_3_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(ktint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_TinyInt_agg_phase_4_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(ktint) from fn_test''' + + qt_sql_sum0_SmallInt_gb ''' + select sum0(ksint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_SmallInt ''' + select sum0(ksint) from fn_test''' + qt_sql_sum0_SmallInt_agg_phase_1 ''' + select count(id), sum0(ksint) from fn_test group by id order by id''' + qt_sql_sum0_SmallInt_agg_phase_2 ''' + select count(distinct id), sum0(ksint) from fn_test''' + qt_sql_sum0_SmallInt_agg_phase_3 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(ksint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_SmallInt_agg_phase_4 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(ksint) from fn_test''' + qt_sql_sum0_SmallInt_gb_notnull ''' + select sum0(ksint) from fn_test_not_nullable group by kbool order by kbool''' + qt_sql_sum0_SmallInt_notnull ''' + select sum0(ksint) from fn_test_not_nullable''' + qt_sql_sum0_SmallInt_agg_phase_1_notnull ''' + select count(id), sum0(ksint) from fn_test_not_nullable group by id order by id''' + qt_sql_sum0_SmallInt_agg_phase_2_notnull ''' + select count(distinct id), sum0(ksint) from fn_test_not_nullable''' + qt_sql_sum0_SmallInt_agg_phase_3_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(ksint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_SmallInt_agg_phase_4_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(ksint) from fn_test''' + + qt_sql_sum0_Integer_gb ''' + select sum0(kint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_Integer ''' + select sum0(kint) from fn_test''' + qt_sql_sum0_Integer_agg_phase_1 ''' + select count(id), sum0(kint) from fn_test group by id order by id''' + qt_sql_sum0_Integer_agg_phase_2 ''' + select count(distinct id), sum0(kint) from fn_test''' + qt_sql_sum0_Integer_agg_phase_3 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_Integer_agg_phase_4 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kint) from fn_test''' + qt_sql_sum0_Integer_gb_notnull ''' + select sum0(kint) from fn_test_not_nullable group by kbool order by kbool''' + qt_sql_sum0_Integer_notnull ''' + select sum0(kint) from fn_test_not_nullable''' + qt_sql_sum0_Integer_agg_phase_1_notnull ''' + select count(id), sum0(kint) from fn_test_not_nullable group by id order by id''' + qt_sql_sum0_Integer_agg_phase_2_notnull ''' + select count(distinct id), sum0(kint) from fn_test_not_nullable''' + qt_sql_sum0_Integer_agg_phase_3_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_Integer_agg_phase_4_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kint) from fn_test''' + + qt_sql_sum0_BigInt_gb ''' + select sum0(kbint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_BigInt ''' + select sum0(kbint) from fn_test''' + qt_sql_sum0_BigInt_agg_phase_1 ''' + select count(id), sum0(kbint) from fn_test group by id order by id''' + qt_sql_sum0_BigInt_agg_phase_2 ''' + select count(distinct id), sum0(kbint) from fn_test''' + qt_sql_sum0_BigInt_agg_phase_3 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kbint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_BigInt_agg_phase_4 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kbint) from fn_test''' + qt_sql_sum0_BigInt_gb_notnull ''' + select sum0(kbint) from fn_test_not_nullable group by kbool order by kbool''' + qt_sql_sum0_BigInt_notnull ''' + select sum0(kbint) from fn_test_not_nullable''' + qt_sql_sum0_BigInt_agg_phase_1_notnull ''' + select count(id), sum0(kbint) from fn_test_not_nullable group by id order by id''' + qt_sql_sum0_BigInt_agg_phase_2_notnull ''' + select count(distinct id), sum0(kbint) from fn_test_not_nullable''' + qt_sql_sum0_BigInt_agg_phase_3_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kbint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_BigInt_agg_phase_4_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kbint) from fn_test''' + + //not cast float to double + explain { + sql("select sum0(kfloat) from fn_test;") + contains "partial_sum0(kfloat" + } + + qt_sql_sum0_Double_gb ''' + select sum0(kdbl) from fn_test group by kbool order by kbool''' + qt_sql_sum0_Double ''' + select sum0(kdbl) from fn_test''' + qt_sql_sum0_Double_agg_phase_1 ''' + select count(id), sum0(kdbl) from fn_test group by id order by id''' + qt_sql_sum0_Double_agg_phase_2 ''' + select count(distinct id), sum0(kdbl) from fn_test''' + qt_sql_sum0_Double_agg_phase_3 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kdbl) from fn_test group by kbool order by kbool''' + qt_sql_sum0_Double_agg_phase_4 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kdbl) from fn_test''' + qt_sql_sum0_Double_gb_notnull ''' + select sum0(kdbl) from fn_test_not_nullable group by kbool order by kbool''' + qt_sql_sum0_Double_notnull ''' + select sum0(kdbl) from fn_test_not_nullable''' + qt_sql_sum0_Double_agg_phase_1_notnull ''' + select count(id), sum0(kdbl) from fn_test_not_nullable group by id order by id''' + qt_sql_sum0_Double_agg_phase_2_notnull ''' + select count(distinct id), sum0(kdbl) from fn_test_not_nullable''' + qt_sql_sum0_Double_agg_phase_3_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kdbl) from fn_test group by kbool order by kbool''' + qt_sql_sum0_Double_agg_phase_4_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kdbl) from fn_test''' + + qt_sql_sum0_DecimalV2_gb ''' + select sum0(kdcmls1) from fn_test group by kbool order by kbool''' + qt_sql_sum0_DecimalV2 ''' + select sum0(kdcmls1) from fn_test''' + qt_sql_sum0_DecimalV2_agg_phase_1 ''' + select count(id), sum0(kdcmls1) from fn_test group by id order by id''' + qt_sql_sum0_DecimalV2_agg_phase_2 ''' + select count(distinct id), sum0(kdcmls1) from fn_test''' + qt_sql_sum0_DecimalV2_agg_phase_3 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kdcmls1) from fn_test group by kbool order by kbool''' + qt_sql_sum0_DecimalV2_agg_phase_4 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kdcmls1) from fn_test''' + qt_sql_sum0_DecimalV2_gb_notnull ''' + select sum0(kdcmls1) from fn_test_not_nullable group by kbool order by kbool''' + qt_sql_sum0_DecimalV2_notnull ''' + select sum0(kdcmls1) from fn_test_not_nullable''' + qt_sql_sum0_DecimalV2_agg_phase_1_notnull ''' + select count(id), sum0(kdcmls1) from fn_test_not_nullable group by id order by id''' + qt_sql_sum0_DecimalV2_agg_phase_2_notnull ''' + select count(distinct id), sum0(kdcmls1) from fn_test_not_nullable''' + qt_sql_sum0_DecimalV2_agg_phase_3_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(kdcmls1) from fn_test group by kbool order by kbool''' + qt_sql_sum0_DecimalV2_agg_phase_4_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(kdcmls1) from fn_test''' + + qt_sql_sum0_LargeInt_gb ''' + select sum0(klint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_LargeInt ''' + select sum0(klint) from fn_test''' + qt_sql_sum0_LargeInt_agg_phase_1 ''' + select count(id), sum0(klint) from fn_test group by id order by id''' + qt_sql_sum0_LargeInt_agg_phase_2 ''' + select count(distinct id), sum0(klint) from fn_test''' + qt_sql_sum0_LargeInt_agg_phase_3 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(klint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_LargeInt_agg_phase_4 ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(klint) from fn_test''' + qt_sql_sum0_LargeInt_gb_notnull ''' + select sum0(klint) from fn_test_not_nullable group by kbool order by kbool''' + qt_sql_sum0_LargeInt_notnull ''' + select sum0(klint) from fn_test_not_nullable''' + qt_sql_sum0_LargeInt_agg_phase_1_notnull ''' + select count(id), sum0(klint) from fn_test_not_nullable group by id order by id''' + qt_sql_sum0_LargeInt_agg_phase_2_notnull ''' + select count(distinct id), sum0(klint) from fn_test_not_nullable''' + qt_sql_sum0_LargeInt_agg_phase_3_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id, kint), sum0(klint) from fn_test group by kbool order by kbool''' + qt_sql_sum0_LargeInt_agg_phase_4_notnull ''' + select /*+SET_VAR(disable_nereids_rules='THREE_PHASE_AGGREGATE_WITH_DISTINCT, TWO_PHASE_AGGREGATE_WITH_DISTINCT')*/ count(distinct id), sum0(klint) from fn_test''' + qt_sql_topn_Varchar_Integer_gb ''' select topn(kvchrs1, 3) from fn_test group by kbool order by kbool''' qt_sql_topn_Varchar_Integer '''