Skip to main content

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​

ParameterDescription
<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 |
+---------------------------------------------------------------------------------------------------------------------------+