BITMAP_OR_CARDINALITY

Description

The BITMAP_OR_CARDINALITY function calculates the cardinality of the logical "or" (disjunction) operation of two bitmaps, which means it returns the number of unique elements after merging the two bitmaps. This function is very useful for determining the total number of different elements after merging two sets, especially when dealing with large datasets, as bitmaps provide an efficient way of data processing.

Syntax

BITMAP_OR_CARDINALITY(bitmap1, bitmap2)

Parameter Description

  • bitmap1: The first bitmap object.
  • bitmap2: The second bitmap object.

Return Value

Returns the cardinality after performing a logical "OR" operation on the two bitmaps, i.e., the number of unique elements in the merged result.

Example

The following example demonstrates how to use the BITMAP_OR_CARDINALITY function to calculate the cardinality after merging two bitmaps:

SELECT bitmap_or_cardinality(bitmapBuild([1,2,3]), bitmapBuild([2,3,4])) AS result;

Assuming the first bitmap contains the elements [1, 2, 3] and the second bitmap contains the elements [2, 3, 4]. The logical "OR" operation on these two bitmaps will merge these elements, removing duplicates, resulting in [1, 2, 3, 4]. The BITMAP_OR_CARDINALITY function calculates the number of unique elements in this resulting bitmap, returning a result of 4.