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

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new e64f2997e9f [fix](function) fix core when input not null array in 
foreach functio… (#37798)
e64f2997e9f is described below

commit e64f2997e9f94ce16cde32f746be1e2e54ff7df8
Author: Mryange <[email protected]>
AuthorDate: Tue Jul 16 10:57:11 2024 +0800

    [fix](function) fix core when input not null array in foreach functio… 
(#37798)
    
    ## Proposed changes
    https://github.com/apache/doris/pull/37349
    error code
    ```C++
    return 
creator_without_type::create<AggregateFunctionForEach>(transform_arguments, 
true,
                                                                          
nested_function);
    ```
    "transform_arguments is an internal type of array. All internal types of
    the array are null, so an array that is not null was mistakenly treated
    as a null array."
    
    ## Proposed changes
    
    Issue Number: close #xxx
    
    <!--Describe your changes.-->
---
 .../aggregate_function_foreach.cpp                 |   3 +-
 .../data/function_p0/test_agg_foreach_notnull.out  |  49 ++++++++
 .../function_p0/test_agg_foreach_notnull.groovy    | 129 +++++++++++++++++++++
 3 files changed, 179 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_foreach.cpp 
b/be/src/vec/aggregate_functions/aggregate_function_foreach.cpp
index e64e5900d01..a0fb5c94f43 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_foreach.cpp
+++ b/be/src/vec/aggregate_functions/aggregate_function_foreach.cpp
@@ -53,8 +53,7 @@ void 
register_aggregate_function_combinator_foreach(AggregateFunctionSimpleFacto
                     "name {} , args {}",
                     nested_function_name, types_name(types));
         }
-        return 
creator_without_type::create<AggregateFunctionForEach>(transform_arguments, 
true,
-                                                                      
nested_function);
+        return creator_without_type::create<AggregateFunctionForEach>(types, 
true, nested_function);
     };
     factory.register_foreach_function_combinator(
             creator, AggregateFunctionForEach::AGG_FOREACH_SUFFIX, true);
diff --git a/regression-test/data/function_p0/test_agg_foreach_notnull.out 
b/regression-test/data/function_p0/test_agg_foreach_notnull.out
new file mode 100644
index 00000000000..c7d50a501cb
--- /dev/null
+++ b/regression-test/data/function_p0/test_agg_foreach_notnull.out
@@ -0,0 +1,49 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql --
+[1, 2, 3]      [1, 2, 3]       [100, 2, 3]     [100, 2, 3]     
[40.333333333333336, 2, 3]      [85.95867768595042, 2, 3]
+
+-- !sql --
+[121, 4, 3]    [42.89781139198388, 0, 0]       [52.53887449625594, 0, null]    
[1840.222222222222, 0, 0]       [2760.333333333333, 0, null]
+
+-- !sql --
+[1840.2222222222222, 0, 0]     [2760.3333333333335, 0, null]   [1, 0, 0]
+
+-- !sql --
+["{"20":1,"100":1,"1":1}", "{"2":2}", "{"3":1}"]       
["{"20":1,"100":1,"1":1}", "{"2":2}", "{"3":1}"]        [[100, 20, 1], [2], 
[3]]        [[100, 20, 1], [2], [3]]
+
+-- !sql --
+[3, 2, 1]      
["[{"cbe":{"100":1,"1":1,"20":1},"notnull":3,"null":1,"all":4}]", 
"[{"cbe":{"2":2},"notnull":2,"null":0,"all":2}]", 
"[{"cbe":{"3":1},"notnull":1,"null":0,"all":1}]"]   [3, 1, 1]
+
+-- !sql --
+["{"num_buckets":3,"buckets":[{"lower":"1","upper":"1","ndv":1,"count":1,"pre_sum":0},{"lower":"20","upper":"20","ndv":1,"count":1,"pre_sum":1},{"lower":"100","upper":"100","ndv":1,"count":1,"pre_sum":2}]}",
 
"{"num_buckets":1,"buckets":[{"lower":"2","upper":"2","ndv":1,"count":2,"pre_sum":0}]}",
 
"{"num_buckets":1,"buckets":[{"lower":"3","upper":"3","ndv":1,"count":1,"pre_sum":0}]}"]
+
+-- !sql --
+[100, 2, 3]
+
+-- !sql --
+[[1], [2, 2, 2], [3]]
+
+-- !sql --
+[null, null, null]
+
+-- !sql --
+[0, 2, 3]      [117, 2, 3]     [113, 0, 3]
+
+-- !sql --
+["ab,cd,efg", "123,c", "114514"]       ["ababcdabefg", "123123c", "114514"]
+
+-- !sql --
+[[1], [1], [1]]        [[1, 1], [1, 1], [1, 1]]        [[1, 1, 1], [1, 1, 1], 
[1, 1, 1]]       [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
+
+-- !sql --
+["ab", "123", "114514"]        [1, 2, 3]
+
+-- !sql --
+[[100, 20, 1], [2], [3]]       [["efg", "cd", "ab"], ["c", "123"], ["114514"]] 
[[1], [2], [3]]
+
+-- !sql --
+[[1, 20, 100], [2, 2], [3]]    [["ab", "cd", "efg"], ["123", "c"], ["114514"]] 
[[1], [2, 2], [3]]
+
+-- !sql --
+[{1:1, 20:20, 100:100}, {2:2}, {3:3}]  [{1:"ab", 20:"cd", 100:"efg"}, 
{2:"123"}, {3:"114514"}] [{"ab":"ab", "cd":"cd", "efg":"efg"}, {"123":"123", 
"c":"c"}, {"114514":"114514"}]
+
diff --git a/regression-test/suites/function_p0/test_agg_foreach_notnull.groovy 
b/regression-test/suites/function_p0/test_agg_foreach_notnull.groovy
new file mode 100644
index 00000000000..91f4ea902dd
--- /dev/null
+++ b/regression-test/suites/function_p0/test_agg_foreach_notnull.groovy
@@ -0,0 +1,129 @@
+// 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.
+
+suite("test_agg_foreach_not_null") {
+   // for nereids_planner
+   // now support  min min_by maxmax_by avg avg_weighted sum stddev 
stddev_samp_foreach variance var_samp
+   // covar covar_samp corr
+   // topn topn_array topn_weighted
+   // count  count_by_enum approx_count_distinct
+   // PERCENTILE PERCENTILE_ARRAY PERCENTILE_APPROX
+   // histogram
+   // GROUP_BIT_AND GROUP_BIT_OR GROUP_BIT_XOR
+   // any_value
+   // array_agg map_agg
+   // collect_set collect_list
+   // retention
+   // not support
+   // GROUP_BITMAP_XOR BITMAP_UNION HLL_UNION_AGG GROUPING GROUPING_ID 
BITMAP_AGG SEQUENCE-MATCH SEQUENCE-COUNT
+
+
+    sql """ set enable_nereids_planner=true;"""
+    sql """ set enable_fallback_to_original_planner=false;"""
+   
+    sql """
+        drop table if exists foreach_table_not_null;
+    """
+
+    sql """
+       CREATE TABLE IF NOT EXISTS foreach_table_not_null (
+              `id` INT(11) not null COMMENT "",
+              `a` array<INT> not null   COMMENT "",
+              `b` array<array<INT>>  not null  COMMENT "",
+              `s` array<String>  not null   COMMENT ""
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY HASH(`id`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "storage_format" = "V2"
+    );
+    """
+    sql """
+    insert into foreach_table_not_null values
+    (1,[1,2,3],[[1],[1,2,3],[2]],["ab","123","114514"]),
+    (2,[20],[[2]],["cd"]),
+    (3,[100],[[1]],["efg"]) , 
+    (4,[null,2],[[2],null],[null,'c']);
+   """
+
+   // this case also test combinator should be case-insensitive
+   qt_sql """
+       select min_ForEach(a), 
min_by_foreach(a,a),max_foreach(a),max_by_foreach(a,a) , 
avg_foreach(a),avg_weighted_foreach(a,a) from foreach_table_not_null ;
+   """
+
+   qt_sql """
+   select  sum_foreach(a)  , stddev_foreach(a) ,stddev_samp_foreach(a)  , 
variance_foreach(a) , var_samp_foreach(a) from foreach_table_not_null ;
+   """
+
+   qt_sql """
+   select covar_foreach(a,a)  , covar_samp_foreach(a,a) , corr_foreach(a,a) 
from foreach_table_not_null ; 
+   """
+    qt_sql """
+   select topn_foreach(a,a) ,topn_foreach(a,a,a)  , topn_array_foreach(a,a) 
,topn_array_foreach(a,a,a)from foreach_table_not_null ;
+   """
+
+
+   qt_sql """
+   select count_foreach(a)  , count_by_enum_foreach(a)  , 
approx_count_distinct_foreach(a) from foreach_table_not_null;
+   """
+
+   qt_sql """
+   select histogram_foreach(a) from foreach_table_not_null;
+   """
+   
+   qt_sql """
+      select PERCENTILE_foreach(a,a)  from foreach_table_not_null;
+   """
+  
+   qt_sql """
+      select PERCENTILE_ARRAY_foreach(a,b) from foreach_table_not_null where 
id = 1;
+   """
+
+   qt_sql """
+
+   select PERCENTILE_APPROX_foreach(a,a) from foreach_table_not_null;
+   """
+
+   qt_sql """
+   select GROUP_BIT_AND_foreach(a), GROUP_BIT_OR_foreach(a), 
GROUP_BIT_XOR_foreach(a)  from foreach_table_not_null;
+   """
+
+   qt_sql """
+   select GROUP_CONCAT_foreach(s), GROUP_CONCAT_foreach(s,s) from 
foreach_table_not_null;
+   """
+   
+   qt_sql """
+   select retention_foreach(a), retention_foreach(a,a 
),retention_foreach(a,a,a) , retention_foreach(a,a,a ,a) from 
foreach_table_not_null;
+   """
+   
+   qt_sql """
+   select any_value_foreach(s), any_value_foreach(a) from 
foreach_table_not_null;
+   """
+
+   qt_sql """
+   select collect_set_foreach(a), collect_set_foreach(s) , 
collect_set_foreach(a,a) from foreach_table_not_null;
+   """
+
+   qt_sql """
+   select collect_list_foreach(a), collect_list_foreach(s) , 
collect_list_foreach(a,a) from foreach_table_not_null;
+   """
+
+   qt_sql """
+   select map_agg_foreach(a,a), map_agg_foreach(a,s) , map_agg_foreach(s,s) 
from foreach_table_not_null;
+   """
+}


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

Reply via email to