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))) as res;
The result will be:
+------+
| res |
+------+
| 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))) res;
The result will be:
+------+
| res |
+------+
| 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)) res;
The result will be:
+----------+
| res |
+----------+
| 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())) res;
The result will be:
+----------+
| res |
+----------+
| 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'))) res;
The result will be:
+--------------+
| res |
+--------------+
| 1,2,3,4,5,10 |
+--------------+