zenoyang commented on code in PR #19973:
URL: https://github.com/apache/doris/pull/19973#discussion_r1205120276


##########
be/src/util/bitmap_value.h:
##########
@@ -1311,6 +1382,53 @@ class BitmapValue {
             case BITMAP:
                 _prepare_bitmap_for_write();
                 *_bitmap |= *rhs._bitmap;
+                break;
+            case SET: {
+                _prepare_bitmap_for_write();
+                *_bitmap = *rhs._bitmap;
+
+                for (auto v : _set) {
+                    _bitmap->add(v);
+                }
+                _type = SET;

Review Comment:
   Should it be `_type = BITMAP` here?



##########
be/src/util/bitmap_value.h:
##########
@@ -1331,37 +1450,103 @@ class BitmapValue {
             case BITMAP:
                 bitmaps.push_back(value->_bitmap.get());
                 break;
+            case SET:
+                sets.push_back(&value->_set);
+                break;
             }
         }
 
         if (!bitmaps.empty()) {
             _prepare_bitmap_for_write();
+            *_bitmap = detail::Roaring64Map::fastunion(bitmaps.size(), 
bitmaps.data());
             switch (_type) {
             case EMPTY:
-                *_bitmap = detail::Roaring64Map::fastunion(bitmaps.size(), 
bitmaps.data());
-                _type = BITMAP;
                 break;
             case SINGLE:
-                *_bitmap = detail::Roaring64Map::fastunion(bitmaps.size(), 
bitmaps.data());
                 _bitmap->add(_sv);
-                _type = BITMAP;
                 break;
             case BITMAP:
-                *_bitmap |= detail::Roaring64Map::fastunion(bitmaps.size(), 
bitmaps.data());
+                break;
+            case SET: {
+                for (auto v : _set) {
+                    _bitmap->add(v);
+                }
+                _set.clear();
                 break;
             }
+            }
+            _type = BITMAP;
+        }
+
+        if (!sets.empty()) {
+            for (auto& set : sets) {
+                for (auto v : *set) {
+                    _set.insert(v);
+                }
+            }
+            switch (_type) {
+            case EMPTY:
+                _type = SET;
+                break;
+            case SINGLE: {
+                _set.insert(_sv);
+                _type = SET;
+                _convert_to_bitmap_if_need();
+                break;
+            }
+            case BITMAP:
+                _prepare_bitmap_for_write();
+                for (auto v : _set) {
+                    _bitmap->add(v);
+                }
+                _type = BITMAP;
+                break;
+            case SET: {
+                _convert_to_bitmap_if_need();
+                break;
+            }
+            }
         }
 
         if (_type == EMPTY && single_values.size() == 1) {
             _sv = single_values[0];
             _type = SINGLE;
         } else if (!single_values.empty()) {
-            _prepare_bitmap_for_write();
-            _bitmap->addMany(single_values.size(), single_values.data());
-            if (_type == SINGLE) {
-                _bitmap->add(_sv);
+            switch (_type) {
+            case EMPTY:
+            case SINGLE:
+                if (config::enable_set_in_bitmap_value) {
+                    _set.insert(single_values.cbegin(), single_values.cend());
+                    if (_type == SINGLE) {
+                        _set.insert(_sv);
+                    }
+                    if (_set.size() == 1) {
+                        _type = SINGLE;
+                        _sv = *_set.begin();
+                        _set.clear();
+                    } else {
+                        _type = SET;
+                        _convert_to_bitmap_if_need();
+                    }
+                } else {
+                    _prepare_bitmap_for_write();
+                    _bitmap->addMany(single_values.size(), 
single_values.data());
+                    if (_type == SINGLE) {
+                        _bitmap->add(_sv);
+                    }
+                    _type = SET;

Review Comment:
   Should it be `_type = BITMAP` here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to