BITMAP_XOR
Descriptionβ
Computes the symmetric difference (XOR operation) of two or more input Bitmaps and returns a new Bitmap.
Syntaxβ
BITMAP_XOR(<bitmap1>, <bitmap2>, ..., <bitmapN>)
Parametersβ
Parameter | Description |
---|---|
<bitmap1> | The first Bitmap |
<bitmap2> | The second Bitmap |
... | ... |
<bitmapN> | The N-th Bitmap |
Return Valueβ
A Bitmap representing the symmetric difference of multiple Bitmaps.
Examplesβ
To compute the symmetric difference of two Bitmaps:
select bitmap_count(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'))) cnt;
The result will be:
+------+
| cnt |
+------+
| 2 |
+------+
To convert the symmetric difference of two Bitmaps to a string:
select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4')));
The result will be:
+----------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'))) |
+----------------------------------------------------------------------------------------+
| 1,4 |
+----------------------------------------------------------------------------------------+
To compute the symmetric difference of three Bitmaps:
select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5')));
The result will be:
+---------------------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'))) |
+---------------------------------------------------------------------------------------------------------------------+
| 1,3,5 |
+---------------------------------------------------------------------------------------------------------------------+
To compute the symmetric difference of multiple Bitmaps, including an empty Bitmap:
select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), bitmap_empty()));
The result will be:
+-------------------------------------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), bitmap_empty())) |
+-------------------------------------------------------------------------------------------------------------------------------------+
| 1,3,5 |
+-------------------------------------------------------------------------------------------------------------------------------------+
To compute the symmetric difference of multiple Bitmaps, including a NULL
value:
select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), NULL));
The result will be:
+---------------------------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), NULL)) |
+---------------------------------------------------------------------------------------------------------------------------+
| NULL |
+---------------------------------------------------------------------------------------------------------------------------+