You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/07/01 07:30:21 UTC

[doris] branch master updated: [BUG] fix bitmap function bug (#10502)

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

yiguolei 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 ca0906626f [BUG] fix bitmap function bug (#10502)
ca0906626f is described below

commit ca0906626fe4c52b94a7a3e64e6260392830e767
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Fri Jul 1 15:30:16 2022 +0800

    [BUG] fix bitmap function bug (#10502)
    
    * fix bitmap function bug
    
    * add regression test
---
 .../aggregate_function_bitmap.h                    | 24 +++++++-
 .../data/correctness/test_bitmap_count.out         | 13 +++++
 .../suites/correctness/test_bitmap_count.groovy    | 66 ++++++++++++++++++++++
 3 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_bitmap.h b/be/src/vec/aggregate_functions/aggregate_function_bitmap.h
index f4a237dbb9..7c7cd96074 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_bitmap.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_bitmap.h
@@ -36,9 +36,23 @@ struct AggregateFunctionBitmapUnionOp {
         res.add(data);
     }
 
-    static void add(BitmapValue& res, const BitmapValue& data, bool& is_first) { res |= data; }
+    static void add(BitmapValue& res, const BitmapValue& data, bool& is_first) {
+        if (UNLIKELY(is_first)) {
+            res = data;
+            is_first = false;
+        } else {
+            res |= data;
+        }
+    }
 
-    static void merge(BitmapValue& res, const BitmapValue& data, bool& is_first) { res |= data; }
+    static void merge(BitmapValue& res, const BitmapValue& data, bool& is_first) {
+        if (UNLIKELY(is_first)) {
+            res = data;
+            is_first = false;
+        } else {
+            res |= data;
+        }
+    }
 };
 
 struct AggregateFunctionBitmapIntersectOp {
@@ -79,6 +93,8 @@ struct AggregateFunctionBitmapData {
 
     void read(BufferReadable& buf) { DataTypeBitMap::deserialize_as_stream(value, buf); }
 
+    void reset() { is_first = true; }
+
     BitmapValue& get() { return value; }
 };
 
@@ -125,6 +141,8 @@ public:
         column.get_data().push_back(
                 const_cast<AggregateFunctionBitmapData<Op>&>(this->data(place)).get());
     }
+
+    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
 };
 
 template <bool nullable, typename ColVecType>
@@ -179,6 +197,8 @@ public:
         auto& column = static_cast<ColVecResult&>(to);
         column.get_data().push_back(value_data.cardinality());
     }
+
+    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
 };
 
 AggregateFunctionPtr create_aggregate_function_bitmap_union(const std::string& name,
diff --git a/regression-test/data/correctness/test_bitmap_count.out b/regression-test/data/correctness/test_bitmap_count.out
new file mode 100644
index 0000000000..82c24f7d26
--- /dev/null
+++ b/regression-test/data/correctness/test_bitmap_count.out
@@ -0,0 +1,13 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !select_default --
+aa	bb	2019-04-26	1	time_zone1	pid1	gid1	2
+aa	bb	2019-04-26	1	time_zone1	pid1	gid2	3
+aa	bb	2019-04-26	2	time_zone1	pid1	gid1	2
+aa	bb	2019-04-26	2	time_zone1	pid1	gid2	3
+
+-- !select_default --
+aa	bb	2019-04-26	1	time_zone1	pid1	gid1	2
+aa	bb	2019-04-26	1	time_zone1	pid1	gid2	3
+aa	bb	2019-04-26	2	time_zone1	pid1	gid1	2
+aa	bb	2019-04-26	2	time_zone1	pid1	gid2	3
+
diff --git a/regression-test/suites/correctness/test_bitmap_count.groovy b/regression-test/suites/correctness/test_bitmap_count.groovy
new file mode 100644
index 0000000000..694023a0b6
--- /dev/null
+++ b/regression-test/suites/correctness/test_bitmap_count.groovy
@@ -0,0 +1,66 @@
+// 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_bitmap_count") {
+     def tableName = "table_bitmap_count"
+
+     sql """ DROP TABLE IF EXISTS ${tableName} """
+     sql """
+        CREATE TABLE ${tableName}  (
+        `a` datetime NOT NULL,
+        `b` date NOT NULL,
+        `c` int(11) NOT NULL,
+        `d` varchar(50) NOT NULL ,
+        `e` varchar(50) NOT NULL,
+        `code1` varchar(50) NOT NULL ,
+        `code2` varchar(50) NOT NULL ,
+        `code3` int(11) NOT NULL DEFAULT "0",
+        `code4` int(11) NOT NULL DEFAULT "0" ,
+        `code5` varchar(255) NOT NULL DEFAULT "-",
+        `code6` varchar(255) NOT NULL DEFAULT "-" ,
+        `bitmap7` bitmap BITMAP_UNION NOT NULL
+        ) ENGINE=OLAP
+        AGGREGATE KEY(`a`, `b`, `c`, `d`, `e`, `code1`, `code2`, `code3`, `code4`, `code5`, `code6`)
+        DISTRIBUTED BY HASH(`code1`, `code2`) BUCKETS 4
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2"
+        );
+     """
+
+     sql "insert into ${tableName} values ('2019-04-26 00:00:00', '2019-04-26', 1, 'Feb', 'time_zone1','aa','bb',2,3,'gid1','pid1',to_bitmap(10));"
+     sql "insert into ${tableName} values ('2019-04-26 00:00:00', '2019-04-26', 1, 'Feb', 'time_zone1','aa','bb',2,3,'gid1','pid1',to_bitmap(20));"
+     sql "insert into ${tableName} values ('2019-04-26 00:00:00', '2019-04-26', 2, 'Feb', 'time_zone1','aa','bb',2,3,'gid1','pid1',to_bitmap(20));"
+     sql "insert into ${tableName} values ('2019-04-26 00:00:00', '2019-04-26', 1, 'Feb', 'time_zone1','aa','bb',2,3,'gid2','pid1',to_bitmap(10));" 
+     sql "insert into ${tableName} values ('2019-04-26 00:00:00', '2019-04-26', 1, 'Feb', 'time_zone1','aa','bb',2,3,'gid2','pid1',to_bitmap(20));"
+     sql "insert into ${tableName} values ('2019-04-26 00:00:00', '2019-04-26', 1, 'Feb', 'time_zone1','aa','bb',2,3,'gid2','pid1',to_bitmap(30));"
+     sql "insert into ${tableName} values ('2019-04-26 00:00:00', '2019-04-26', 2, 'Feb', 'time_zone1','aa','bb',2,3,'gid2','pid1',to_bitmap(20));"
+
+     qt_select_default """ 
+      select  code1 ,code2 ,`b`,c, e,code6,code5,BITMAP_UNION_COUNT(bitmap_intersect(bitmap7)) over(PARTITION by code5 order by c) bitmap7
+        from ${tableName} WHERE code1 ='aa' and b='2019-04-26' 
+        group by 1,2,3,4,5,6,7
+        order by 1,2,3,4,5,6,7;
+    """
+    qt_select_default """ 
+      select  code1 ,code2 ,`b`,c, e,code6,code5,BITMAP_UNION_COUNT(bitmap_union(bitmap7)) over(PARTITION by code5 order by c) bitmap7
+        from ${tableName} WHERE code1 ='aa' and b='2019-04-26' 
+        group by 1,2,3,4,5,6,7
+        order by 1,2,3,4,5,6,7;
+    """
+ }
\ No newline at end of file


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