Skip to main content

BITMAP_XOR_COUNT

Description​

Computes the symmetric difference (XOR operation) of two or more Bitmap sets and returns the count of elements in the result set.

Syntax​

BITMAP_XOR_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 Bitmap resulting from the XOR operation of multiple Bitmaps.
Returns 0 if any of the input Bitmap parameters is NULL.

Examples​

To compute the count of elements in the symmetric difference of two Bitmaps:

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

The result will be:

+------+
| res |
+------+
| 4 |
+------+

To compute the count of elements in the symmetric difference of two identical Bitmaps:

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

The result will be:

+------+
| res |
+------+
| 0 |
+------+

To compute the count of elements in the symmetric difference of two different Bitmaps:

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

The result will be:

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

To compute the count of elements in the symmetric difference of three Bitmaps:

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

The result will be:

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

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

select bitmap_xor_count(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), bitmap_empty());

The result will be:

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

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

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

The result will be:

+------+
| res |
+------+
| 0 |
+------+