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

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


The following commit(s) were added to refs/heads/master by this push:
     new 60f93b2  Fix bitmap type (#3749)
60f93b2 is described below

commit 60f93b2142c4f6b2aafa3738bfd5f650b32e2457
Author: HangyuanLiu <[email protected]>
AuthorDate: Wed Jun 3 10:07:58 2020 +0800

    Fix bitmap type (#3749)
---
 be/src/util/bitmap_value.h         |  4 ++++
 be/test/util/bitmap_value_test.cpp | 27 ++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/be/src/util/bitmap_value.h b/be/src/util/bitmap_value.h
index 0545369..18f9fb3 100644
--- a/be/src/util/bitmap_value.h
+++ b/be/src/util/bitmap_value.h
@@ -993,6 +993,10 @@ public:
                 _type = SINGLE;
                 break;
             case SINGLE:
+                //there is no need to convert the type if two variables are 
equal
+                if (_sv == value) {
+                    break;
+                }
                 _bitmap.add(_sv);
                 _bitmap.add(value);
                 _type = BITMAP;
diff --git a/be/test/util/bitmap_value_test.cpp 
b/be/test/util/bitmap_value_test.cpp
index ca1a92f..8ba6889 100644
--- a/be/test/util/bitmap_value_test.cpp
+++ b/be/test/util/bitmap_value_test.cpp
@@ -14,14 +14,14 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-#include "util/bitmap_value.h"
 
 #include <cstdint>
 #include <gtest/gtest.h>
 #include <string>
-#include <vector>
 
 #include "util/coding.h"
+#define private public
+#include "util/bitmap_value.h"
 
 namespace doris {
 
@@ -304,9 +304,30 @@ TEST(BitmapValueTest, bitmap_to_string) {
     empty.add(2);
     ASSERT_STREQ("1,2", empty.to_string().c_str());
 }
+
+TEST(BitmapValueTest, bitmap_single_convert) {
+    BitmapValue bitmap;
+    ASSERT_STREQ("", bitmap.to_string().c_str());
+    bitmap.add(1);
+    ASSERT_STREQ("1", bitmap.to_string().c_str());
+    bitmap.add(1);
+    ASSERT_STREQ("1", bitmap.to_string().c_str());
+    ASSERT_EQ(BitmapValue::SINGLE, bitmap._type);
+    
+    BitmapValue bitmap_u;
+    bitmap_u.add(1);
+    bitmap |= bitmap_u;
+    ASSERT_EQ(BitmapValue::SINGLE, bitmap._type);
+
+    bitmap_u.add(2);
+    ASSERT_EQ(BitmapValue::BITMAP, bitmap_u._type);
+
+    bitmap |= bitmap_u;
+    ASSERT_EQ(BitmapValue::BITMAP, bitmap._type);
+}
 } // namespace doris
 
 int main(int argc, char** argv) {
     ::testing::InitGoogleTest(&argc, argv);
     return RUN_ALL_TESTS();
-}
\ No newline at end of file
+}


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

Reply via email to