Skip to main content

BITMAP_OR_COUNT

Description​

Computes the union of two or more input Bitmaps and returns the count of elements in the union.

Syntax​

BITMAP_OR_COUNT(<bitmap1>, <bitmap2>, ..., <bitmapN>)

Parameters​

ParameterDescription
<bitmap1>The first Bitmap
<bitmap2>The second Bitmap
......
<bitmapN>The N-th Bitmap

Return Value​

The count of elements in the union of multiple Bitmaps.

Examples​

To compute the count of elements in the union of a non-empty Bitmap and an empty Bitmap:

select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_empty()) res;

The result will be:

+------+
| res |
+------+
| 3 |
+------+

To compute the count of elements in the union of two identical Bitmaps:

select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) res;

The result will be:

+------+
| res |
+------+
| 3 |
+------+

To compute the count of elements in the union of two different Bitmaps:

select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) res;

The result will be:

+------+
| res |
+------+
| 5 |
+------+

To compute the count of elements in the union of multiple Bitmaps, including an empty Bitmap:

select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), bitmap_empty()) res;

The result will be:

+------+
| res |
+------+
| 6 |
+------+

To compute the count of elements in the union of multiple Bitmaps, including a NULL value:

select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), NULL) res;

The result will be:

+------+
| res |
+------+
| 6 |
+------+