diff --git a/be/src/util/bitmap_value.h b/be/src/util/bitmap_value.h index 0545369aa10003..18f9fb33034677 100644 --- a/be/src/util/bitmap_value.h +++ b/be/src/util/bitmap_value.h @@ -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; diff --git a/be/test/util/bitmap_value_test.cpp b/be/test/util/bitmap_value_test.cpp index ca1a92f7e99a7c..8ba688958c1063 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 #include #include -#include #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 +}