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 8cf6c6a2b5d [fix](agg function) incorrect result of map agg(#39743) 
(#39854)
8cf6c6a2b5d is described below

commit 8cf6c6a2b5d5176365b593b9b0b645950bc3f2ad
Author: Jerry Hu <mrh...@gmail.com>
AuthorDate: Sat Aug 24 09:19:52 2024 +0800

    [fix](agg function) incorrect result of map agg(#39743) (#39854)
    
    ## Proposed changes
    
    pick #39743
---
 .../aggregate_functions/aggregate_function_map.h   | 11 +++-----
 .../data/query_p0/aggregate/map_agg.out            |  5 ++++
 .../suites/query_p0/aggregate/map_agg.groovy       | 31 ++++++++++++++++++++++
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_map.h 
b/be/src/vec/aggregate_functions/aggregate_function_map.h
index 0f1a298aed1..befe0df1625 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_map.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_map.h
@@ -18,7 +18,6 @@
 #pragma once
 
 #include <parallel_hashmap/phmap.h>
-#include <string.h>
 
 #include "vec/aggregate_functions/aggregate_function.h"
 #include "vec/aggregate_functions/aggregate_function_simple_factory.h"
@@ -92,7 +91,7 @@ struct AggregateFunctionMapAggData {
             }
 
             if (UNLIKELY(_map.find(key) != _map.end())) {
-                return;
+                continue;
             }
 
             key.data = _arena.insert(key.data, key.size);
@@ -159,9 +158,7 @@ struct AggregateFunctionMapAggData {
         StringRef key;
         for (size_t i = 0; i < size; i++) {
             read_binary(key, buf);
-            if (_map.find(key) != _map.cend()) {
-                continue;
-            }
+            DCHECK(_map.find(key) == _map.cend());
             key.data = _arena.insert(key.data, key.size);
             assert_cast<KeyColumnType&>(*_key_column).insert_data(key.data, 
key.size);
         }
@@ -261,7 +258,7 @@ public:
 
     void deserialize_from_column(AggregateDataPtr places, const IColumn& 
column, Arena* arena,
                                  size_t num_rows) const override {
-        auto& col = assert_cast<const ColumnMap&>(column);
+        const auto& col = assert_cast<const ColumnMap&>(column);
         auto* data = &(this->data(places));
         for (size_t i = 0; i != num_rows; ++i) {
             auto map = doris::vectorized::get<Map>(col[i]);
@@ -292,7 +289,7 @@ public:
                                                  Arena* arena) const override {
         DCHECK(end <= column.size() && begin <= end)
                 << ", begin:" << begin << ", end:" << end << ", 
column.size():" << column.size();
-        auto& col = assert_cast<const ColumnMap&>(column);
+        const auto& col = assert_cast<const ColumnMap&>(column);
         for (size_t i = begin; i <= end; ++i) {
             auto map = doris::vectorized::get<Map>(col[i]);
             this->data(place).add(map[0], map[1]);
diff --git a/regression-test/data/query_p0/aggregate/map_agg.out 
b/regression-test/data/query_p0/aggregate/map_agg.out
index c7db1dcaeae..186e888b57f 100644
--- a/regression-test/data/query_p0/aggregate/map_agg.out
+++ b/regression-test/data/query_p0/aggregate/map_agg.out
@@ -43,3 +43,8 @@ V5_3
 -- !multi --
 1      2
 
+-- !test_dumplicate --
+1      \N
+2      bddd
+3      \N
+
diff --git a/regression-test/suites/query_p0/aggregate/map_agg.groovy 
b/regression-test/suites/query_p0/aggregate/map_agg.groovy
index 351c077df10..385a40b065f 100644
--- a/regression-test/suites/query_p0/aggregate/map_agg.groovy
+++ b/regression-test/suites/query_p0/aggregate/map_agg.groovy
@@ -322,4 +322,35 @@ suite("map_agg") {
                , day
         ) t order by 1, 2;
     """
+
+    sql "DROP TABLE IF EXISTS `test_map_agg_2`;"
+    sql """
+        CREATE TABLE `test_map_agg_2` (
+        `k1` int NULL,
+        `k2` int NULL,
+        `v1` text NULL,
+        `v2` text NULL
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`k1`, `k2`)
+        DISTRIBUTED BY HASH(`k1`) BUCKETS 4
+        PROPERTIES ( 'replication_num' = '1');
+    """
+
+    sql """
+        insert into `test_map_agg_2` values
+            (    3 ,    1 , 'k'    , 'j'    ),
+            (    3 ,    2 , 'a'    , 'a3'   ),
+            (    5 ,    2 , 'a'    , 'a5'   ),
+            (    1 ,    1 , 'ee'   , 'nn'   ),
+            (    1 ,    1 , 'a'    , 'b'    ),
+            (    1 ,    2 , 'a'    , 'b'    ),
+            (    1 ,    3 , 'c'    , 'c'    ),
+            (    2 ,    1 , 'e'    , 'f'    ),
+            (    2 ,    2 , 'a'    , 'a2'   ),
+            (    4 ,    2 , 'b'    , 'bddd' ),
+            (    4 ,    2 , 'a'    , 'a4'   );
+    """
+
+    sql "set experimental_ignore_storage_data_distribution = 0;"
+    qt_test_dumplicate "select k2, m['b'] from (select k2, map_agg(v1, v2) m 
from `test_map_agg_2` group  by k2) a order by k2;"
  }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to