This is an automated email from the ASF dual-hosted git repository.

panxiaolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 3cdbb6e6372 [Bug](materialized-view) fix some bugs on create mv with 
percentile_approx (#26528)
3cdbb6e6372 is described below

commit 3cdbb6e637219626793a3ef7fd06468843ad937a
Author: Pxl <[email protected]>
AuthorDate: Wed Nov 8 10:09:37 2023 +0800

    [Bug](materialized-view) fix some bugs on create mv with percentile_approx 
(#26528)
    
    1. percentile_approx have wrong symbol
    2. fnCall.getParams() get obsolete childrens
---
 .../aggregate_function_percentile_approx.cpp       | 11 ++++-
 .../aggregate_function_simple_factory.cpp          |  1 -
 .../doris/analysis/CreateMaterializedViewStmt.java |  4 ++
 .../java/org/apache/doris/catalog/Function.java    |  3 +-
 .../java/org/apache/doris/catalog/FunctionSet.java |  9 ----
 .../test_user_activity/test_user_activity.out      | 12 +++++
 .../test_user_activity/test_user_activity.groovy   | 52 ++++++++++++++++++++++
 .../ut/testProjectionMV1/testProjectionMV1.groovy  |  2 +-
 8 files changed, 80 insertions(+), 14 deletions(-)

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 537022f194c..5ffac66f8f2 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 <bool is_nullable>
 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<AggregateFunctionPercentileApproxMerge<is_nullable>>(
                 remove_nullable(argument_types), result_is_nullable);
-    } else if (argument_types.size() == 2) {
+    }
+    if (argument_types.size() == 2) {
         return creator_without_type::create<
                 AggregateFunctionPercentileApproxTwoParams<is_nullable>>(
                 remove_nullable(argument_types), result_is_nullable);
-    } else if (argument_types.size() == 3) {
+    }
+    if (argument_types.size() == 3) {
         return creator_without_type::create<
                 AggregateFunctionPercentileApproxThreeParams<is_nullable>>(
                 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 08e6e44311f..068e2efaac4 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp
+++ b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp
@@ -100,7 +100,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 c42f3734f3d..b1acc545c5a 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
@@ -518,6 +518,10 @@ public class CreateMaterializedViewStmt extends DdlStmt {
                 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 6638eb6e367..17d47bc4e33 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 @@ package org.apache.doris.catalog;
 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.FeMetaVersion;
 import org.apache.doris.common.UserException;
@@ -853,7 +854,7 @@ public class Function implements Writable {
                 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 9390969d7a5..665e7b75b4b 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
@@ -1318,15 +1318,6 @@ public class FunctionSet<T> {
                 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.<Type>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 00000000000..8f2bd824d04
--- /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 00000000000..2fd50485e19
--- /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;"
+}
diff --git 
a/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy 
b/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy
index 2232e2077b3..6a04b7fcea3 100644
--- a/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy
+++ b/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy
@@ -34,7 +34,6 @@ suite ("testProjectionMV1") {
     sql """insert into emps values("2020-01-01",1,"a",1,1,1);"""
     sql """insert into emps values("2020-01-02",2,"b",2,2,2);"""
 
-    sql """set enable_nereids_planner=false"""
     test {
         sql "create materialized view emps_mv as select deptno, empid from 
emps t order by deptno;"
         exception "errCode = 2,"
@@ -57,6 +56,7 @@ suite ("testProjectionMV1") {
     }
     qt_select_mv "select empid, deptno from emps order by empid;"
 
+    sql """set enable_nereids_planner=false""" // need fix it on nereids
     explain {
         sql("select empid, sum(deptno) from emps group by empid order by 
empid;")
         contains "(emps_mv)"


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

Reply via email to