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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new cafe6affe58 [fix](agg) wrong result of two or more map_agg functions 
in query (#31954)
cafe6affe58 is described below

commit cafe6affe58fcb8419efe44724dfc5527774773b
Author: Jerry Hu <[email protected]>
AuthorDate: Thu Mar 7 21:38:43 2024 +0800

    [fix](agg) wrong result of two or more map_agg functions in query (#31954)
---
 .../aggregate_functions/aggregate_function_map.h   |  4 +-
 .../data/query_p0/aggregate/map_agg.out            |  3 ++
 .../suites/query_p0/aggregate/map_agg.groovy       | 45 +++++++++++++++++++++-
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_map.h 
b/be/src/vec/aggregate_functions/aggregate_function_map.h
index f22a1e7b50b..2927fbd5bb6 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_map.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_map.h
@@ -289,7 +289,7 @@ public:
         auto& col = assert_cast<const ColumnMap&>(*assert_cast<const 
IColumn*>(column));
         for (size_t i = 0; i != num_rows; ++i) {
             auto map = doris::vectorized::get<Map>(col[i]);
-            this->data(places[i]).add(map[0], map[1]);
+            this->data(places[i] + offset).add(map[0], map[1]);
         }
     }
 
@@ -300,7 +300,7 @@ public:
         for (size_t i = 0; i != num_rows; ++i) {
             if (places[i]) {
                 auto map = doris::vectorized::get<Map>(col[i]);
-                this->data(places[i]).add(map[0], map[1]);
+                this->data(places[i] + offset).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 1b349f50a8e..c7db1dcaeae 100644
--- a/regression-test/data/query_p0/aggregate/map_agg.out
+++ b/regression-test/data/query_p0/aggregate/map_agg.out
@@ -40,3 +40,6 @@ V5_3
 002    88.0    90.0    75.5    \N
 003    70.0    85.0    90.0    82.0
 
+-- !multi --
+1      2
+
diff --git a/regression-test/suites/query_p0/aggregate/map_agg.groovy 
b/regression-test/suites/query_p0/aggregate/map_agg.groovy
index 81075f18b1f..e3b307d9231 100644
--- a/regression-test/suites/query_p0/aggregate/map_agg.groovy
+++ b/regression-test/suites/query_p0/aggregate/map_agg.groovy
@@ -63,7 +63,7 @@ suite("map_agg") {
           ) ENGINE=OLAP
           DUPLICATE KEY(`id`)
           COMMENT 'OLAP'
-          DISTRIBUTED BY HASH(`id`) BUCKETS 2
+          DISTRIBUTED BY HASH(`id`) BUCKETS 10
           PROPERTIES (
           "replication_allocation" = "tag.location.default: 1",
           "storage_format" = "V2",
@@ -280,9 +280,52 @@ suite("map_agg") {
         ) a order by userid;
     """
 
+    sql """
+        create table test_map_agg_multi (
+            data_time bigint,
+            mil int,
+            vin string,
+            car_type string,
+            month string,
+            day string
+        ) engine=olap
+        distributed by hash(data_time) buckets 10
+        properties("replication_num" = "1");
+    """
+    sql """
+        insert into test_map_agg_multi values (1, 1, 'abc', 'bc', '01', '01'), 
(2, 2, 'abc', 'bc', '01', '01');
+    """
+
+    qt_multi """
+        select
+            m1['1']
+            , m2['2']
+        from (
+            select
+                vin
+                , car_type
+                , map_agg(ts, mile) m1
+                , map_agg(mile, ts) m2
+            from (
+                 select
+                    vin
+                    , car_type
+                    , data_time as ts
+                    , mil as mile, month
+                    , day from test_map_agg_multi
+            )a
+            group by
+               car_type
+               , vin
+               , month
+               , day
+        ) t order by 1, 2;
+    """
+    
     sql "DROP TABLE IF EXISTS `test_map_agg`"
     sql "DROP TABLE IF EXISTS `test_map_agg_nullable`"
     sql "DROP TABLE IF EXISTS `test_map_agg_numeric_key`"
     sql "DROP TABLE IF EXISTS `test_map_agg_decimal`"
     sql "DROP TABLE IF EXISTS `test_map_agg_score`"
+    sql "DROP TABLE IF EXISTS test_map_agg_multi;"
  }


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

Reply via email to