BITMAP_OR
Descriptionβ
Computes the union of two or more Bitmaps and returns a new Bitmap.
Syntaxβ
BITMAP_OR(<bitmap1>, <bitmap2>, ..., <bitmapN>)
Parametersβ
Parameter | Description |
---|---|
<bitmap1> | The first Bitmap |
<bitmap2> | The second Bitmap |
... | ... |
<bitmapN> | The N-th Bitmap |
Return Valueβ
A Bitmap that represents the union of multiple Bitmaps.
Examplesβ
To compute the union of two identical Bitmaps:
select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(1))) cnt;
The result will be:
+------+
| cnt |
+------+
| 1 |
+------+
To convert the union of two identical Bitmaps to a string:
select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(1)));
The result will be:
+---------------------------------------------------------+
| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(1))) |
+---------------------------------------------------------+
| 1 |
+---------------------------------------------------------+
To compute the union of two different Bitmaps:
select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(2))) cnt;
The result will be:
+------+
| cnt |
+------+
| 2 |
+------+
To convert the union of two different Bitmaps to a string:
select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2)));
The result will be:
+---------------------------------------------------------+
| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) |
+---------------------------------------------------------+
| 1,2 |
+---------------------------------------------------------+
To compute the union of multiple Bitmaps, including a NULL
value:
select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL));
The result will be:
+--------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)) |
+--------------------------------------------------------------------------------------------+
| 0,1,2,10 |
+--------------------------------------------------------------------------------------------+
To compute the union of multiple Bitmaps, including an empty Bitmap:
select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty()));
The result will be:
+------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())) |
+------------------------------------------------------------------------------------------------------+
| 0,1,2,10 |
+------------------------------------------------------------------------------------------------------+
To compute the union of Bitmaps created from strings and individual values:
select bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')));
The result will be:
+--------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) |
+--------------------------------------------------------------------------------------------------------+
| 1,2,3,4,5,10 |
+--------------------------------------------------------------------------------------------------------+