Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions be/src/util/bitmap_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@ class BitmapValue {
_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;
Expand Down
27 changes: 24 additions & 3 deletions be/test/util/bitmap_value_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
}
}