Work with bitmap data structures for efficient set operations.
groupBitmap
function with the -State
suffix to aggregate values into a bitmap.
array
- Unsigned integer array.bitmapBuild
constructs a bitmap from the array of IDs [1, 2, 3, 4, 5]
. The resulting bitmap is of type AggregateFunction(groupBitmap, UInt8)
.
bitmap
- A bitmap object.bitmapToArray
converts a bitmap containing the taco IDs 1, 3, 5, 7, and 9 back into an array of integers.
bitmap
(Bitmap object): The input bitmap.range_start
(UInt32
): The start of the range (inclusive).range_end
(UInt32
): The end of the range (exclusive).bitmapSubsetInRange
extracts a subset of the bitmap containing only the values between 3 (inclusive) and 8 (exclusive), which represents taco IDs 3 through 7.
range_start
and at most cardinality_limit
elements.
Syntax:
bitmap
(Bitmap
) - The input bitmap.range_start
(UInt32
) - The start of the range (inclusive).cardinality_limit
(UInt32
) - The maximum cardinality of the subset.cardinality_limit
elements, starting from range_start
.
Example:
bitmapSubsetLimit
returns a subset of the bitmap starting from value 5, with a maximum of 3 elements. The result is then converted to an array for display.
offset
. The maximum cardinality of the returned bitmap is cardinality_limit
.
Syntax:
bitmap
(Bitmap
) - The input bitmap.offset
(UInt32
) - The position of the first element of the subset.cardinality_limit
(UInt32
) - The maximum number of elements in the subset.subBitmap
returns a subset of the bitmap starting from the 4th element (offset 3) and including up to 4 elements. The result is then converted to an array for display.
bitmap
(Bitmap
): The input bitmap.needle
(UInt32
): The element to search for in the bitmap.1
if the bitmap contains the needle element. [UInt8
]0
if the bitmap does not contain the needle element. [UInt8
]bitmapContains
checks if each taco’s toppings bitmap contains the topping with ID 3 (assuming 3 represents salsa). The result is 1 if salsa is present and 0 if it’s not.
bitmap1
(Bitmap
): The first bitmap objectbitmap2
(Bitmap
): The second bitmap object1
if the bitmaps intersect (have at least one element in common)0
if the bitmaps do not intersectbitmap2
contains exactly one element, consider using bitmapContains
instead as it is more efficient for that case.1
if the first bitmap contains all elements of the second bitmap, otherwise 0
. If the second bitmap is empty, returns 1
.
Syntax:
bitmap1
(Bitmap): The first bitmap object to check.bitmap2
(Bitmap): The second bitmap object to check against.bitmap1
contains all elements in bitmap2
bitmap2
is emptybitmapHasAll
returns 1
because [1,2,3,4,5] contains all elements of [3,4,5].bitmapHasAll
returns 0
because [1,2,3] does not contain all elements of [3,4,5].bitmap
(Bitmap
): A bitmap object.UInt64
]
Example:
bitmapCardinality
counts the number of elements in the bitmap created from the array [1, 2, 3, 4, 5].
UINT32_MAX
if the bitmap is empty.
Syntax:
bitmap
(Bitmap
): Bitmap object.UINT32_MAX
(4294967295) if the bitmap is empty. [UInt32
]
Example:
UINT32_MAX
(4294967295).bitmap
(Bitmap
): Bitmap object.0
if empty. [UInt32
]
Example:
bitmapMax
finds the largest taco ID (5) from a bitmap of taco IDs.
bitmap
(Bitmap): The input bitmap to transform.from_array
(Array(UInt32)
): Array of bit values to replace.to_array
(Array(UInt32)
): Array of new bit values to set.Bitmap
]
from_array
and to_array
must have the same length.from_array[i]
, it is replaced with to_array[i]
.from_array
and to_array
.AND
(intersection) of two bitmaps.
Syntax:
bitmap1
(Bitmap
): The first bitmap objectbitmap2
(Bitmap
): The second bitmap objectBitmap
]
Example:
OR
(disjunction) of two bitmaps.
Syntax:
bitmap1
(Bitmap): The first bitmap object.bitmap2
(Bitmap): The second bitmap object.bitmapOr
combines two bitmaps representing odd and even taco IDs, resulting in a bitmap containing all IDs from 1 to 10. The bitmapToArray
function is used to convert the result back to an array for display.
XOR
operation on two bitmaps.
Syntax:
bitmap1
(Bitmap
): The first bitmap object.bitmap2
(Bitmap
): The second bitmap object.Bitmap
]
Example:
AND
of the first bitmap with the negation of the second bitmap.
Syntax:
bitmap1
(Bitmap
): The first bitmap operand.bitmap2
(Bitmap
): The second bitmap operand to be negated.bitmap1 AND (NOT bitmap2)
. [Bitmap
]
Example:
bitmapAndnot
performs the following operation:
AND
(conjunction) of two bitmaps.
Syntax:
bitmap1
(Bitmap
): The first bitmap objectbitmap2
(Bitmap
): The second bitmap objectUInt64
]
Example:
bitmapAndCardinality
calculates how many taco toppings are common between two sets of toppings represented as bitmaps. The result 3 indicates that there are 3 toppings (3, 4, and 5) present in both bitmaps.
OR
(disjunction) of two bitmaps.
Syntax:
bitmap1
(Bitmap
): First bitmap objectbitmap2
(Bitmap
): Second bitmap objectUInt64
]
Example:
bitmapOrCardinality
calculates how many unique elements are available when combining two sets. The first bitmap represents [1, 2, 3] and the second represents [3, 4, 5]. The OR operation results in [1, 2, 3, 4, 5], and the cardinality (count of unique elements) is 5.
XOR
(exclusive or) of two bitmaps.
Syntax:
bitmap1
(Bitmap
): The first bitmap objectbitmap2
(Bitmap
): The second bitmap objectXOR
of the two input bitmaps. [UInt64
]
Example:
XOR
of the two bitmaps is [1,2,6,7]
, which has a cardinality of 4.
This function efficiently computes the cardinality of the XOR
without materializing the full result bitmap, which can be useful for large bitmaps.
AND-NOT
operation of two bitmaps.
Syntax:
bitmap1
(Bitmap
): The first bitmap object.bitmap2
(Bitmap
): The second bitmap object.bitmap1
that are not in bitmap2
. [UInt64
]
Example:
bitmapAndnotCardinality
calculates the number of elements in bitmap1
that are not in bitmap2
. The result is 2, corresponding to the elements [1, 2] which are in bitmap1
but not in bitmap2
.