diff --git a/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.cpp b/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.cpp index 537022f194ccef..5ffac66f8f2daa 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.cpp @@ -26,14 +26,21 @@ template AggregateFunctionPtr create_aggregate_function_percentile_approx(const std::string& name, const DataTypes& argument_types, const bool result_is_nullable) { + const DataTypePtr& argument_type = remove_nullable(argument_types[0]); + WhichDataType which(argument_type); + if (which.idx != TypeIndex::Float64) { + return nullptr; + } if (argument_types.size() == 1) { return creator_without_type::create>( remove_nullable(argument_types), result_is_nullable); - } else if (argument_types.size() == 2) { + } + if (argument_types.size() == 2) { return creator_without_type::create< AggregateFunctionPercentileApproxTwoParams>( remove_nullable(argument_types), result_is_nullable); - } else if (argument_types.size() == 3) { + } + if (argument_types.size() == 3) { return creator_without_type::create< AggregateFunctionPercentileApproxThreeParams>( remove_nullable(argument_types), result_is_nullable); 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 91113b1f52e41f..87c38c719a1d51 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp @@ -102,7 +102,6 @@ AggregateFunctionSimpleFactory& AggregateFunctionSimpleFactory::instance() { register_aggregate_function_replace_reader_load(instance); register_aggregate_function_window_lead_lag_first_last(instance); register_aggregate_function_HLL_union_agg(instance); - register_aggregate_function_percentile_approx(instance); }); return instance; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java index 2f7a23ed674c64..eafc24c4fdaf76 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java @@ -515,6 +515,10 @@ private MVColumnItem buildMVColumnItem(Analyzer analyzer, FunctionCallExpr funct break; default: mvAggregateType = AggregateType.GENERIC_AGGREGATION; + if (functionCallExpr.getParams().isDistinct() || functionCallExpr.getParams().isStar()) { + throw new AnalysisException( + "The Materialized-View's generic aggregation not support star or distinct"); + } defineExpr = Function.convertToStateCombinator(functionCallExpr); type = defineExpr.type; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java index 4664b996467746..87c5277987b91f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java @@ -20,6 +20,7 @@ import org.apache.doris.analysis.Expr; import org.apache.doris.analysis.FunctionCallExpr; import org.apache.doris.analysis.FunctionName; +import org.apache.doris.analysis.FunctionParams; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.UserException; import org.apache.doris.common.io.IOUtils; @@ -848,7 +849,7 @@ public static FunctionCallExpr convertToStateCombinator(FunctionCallExpr fnCall) aggFunction.hasVarArgs(), aggFunction.isUserVisible()); fn.setNullableMode(NullableMode.ALWAYS_NOT_NULLABLE); fn.setBinaryType(TFunctionBinaryType.AGG_STATE); - return new FunctionCallExpr(fn, fnCall.getParams()); + return new FunctionCallExpr(fn, new FunctionParams(fnCall.getChildren())); } public static FunctionCallExpr convertToMergeCombinator(FunctionCallExpr fnCall) { 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 310c2f85c550a3..1b5f51ad1b720d 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 @@ -1321,15 +1321,6 @@ private void initAggregateBuiltins() { true, false, true, true)); //vec percentile and percentile_approx - addBuiltin(AggregateFunction.createBuiltin("percentile", - Lists.newArrayList(Type.BIGINT, Type.DOUBLE), Type.DOUBLE, Type.VARCHAR, - "", - "", - "", - "", - "", - false, true, false, true)); - addBuiltin(AggregateFunction.createBuiltin("percentile_approx", Lists.newArrayList(Type.DOUBLE, Type.DOUBLE), Type.DOUBLE, Type.VARCHAR, "", diff --git a/regression-test/data/mv_p0/test_user_activity/test_user_activity.out b/regression-test/data/mv_p0/test_user_activity/test_user_activity.out new file mode 100644 index 00000000000000..8f2bd824d04d20 --- /dev/null +++ b/regression-test/data/mv_p0/test_user_activity/test_user_activity.out @@ -0,0 +1,12 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_base -- +2023-01-02 450.0 600.0 + +-- !select_star -- +1 2023-01-02 300 +2 2023-01-02 600 +2 2023-01-02 600 + +-- !select_group_mv -- +2023-01-02 600.0 600.0 + diff --git a/regression-test/suites/mv_p0/test_user_activity/test_user_activity.groovy b/regression-test/suites/mv_p0/test_user_activity/test_user_activity.groovy new file mode 100644 index 00000000000000..2fd50485e196db --- /dev/null +++ b/regression-test/suites/mv_p0/test_user_activity/test_user_activity.groovy @@ -0,0 +1,52 @@ +// 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. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +suite ("test_user_activity") { + + sql """ DROP TABLE IF EXISTS d_table; """ + + sql """ + CREATE TABLE u_axx ( + r_xx INT, + n_dx DATE, + n_duration INT + ) + DISTRIBUTED BY HASH(r_xx) + PROPERTIES ( + "replication_num" = "1" + ); + """ + + sql """INSERT INTO u_axx VALUES (1, "2023-01-02", 300);""" + sql """INSERT INTO u_axx VALUES (2, "2023-01-02", 600);""" + + qt_select_base " select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx; " + + createMV ("create materialized view session_distribution_2 as select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;") + + sql """INSERT INTO u_axx VALUES (2, "2023-01-02", 600);""" + + qt_select_star "select * from u_axx order by 1;" + + explain { + sql("select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;") + contains "(session_distribution_2)" + } + qt_select_group_mv "select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;" +}