Bitmap functions
Bitmaps can be constructed in two ways. The first way is constructed by aggregation function groupBitmap with -State, the other way is to constructed a bitmap from an Array object.
bitmapAnd
Introduced in: v20.1
Computes the logical conjunction (AND) of two bitmaps.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns a bitmap containing bits present in both input bitmaps AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapAndCardinality
Introduced in: v20.1
Returns the cardinality of the logical conjunction (AND) of two bitmaps.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns the number of set bits in the intersection of the two bitmaps UInt64
Examples
Usage example
bitmapAndnot
Introduced in: v20.1
Computes the logical conjunction of two bitmaps and negates the result (AND-NOT).
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns a bitmap containing set bits present in the first bitmap but not in the second AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapAndnotCardinality
Introduced in: v20.1
Returns the cardinality of the AND-NOT operation of two bitmaps.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns the number of set bits in the result of bitmap1 AND-NOT bitmap2 UInt64
Examples
Usage example
bitmapBuild
Introduced in: v20.1
Builds a bitmap from an unsigned integer array. It is the opposite of function bitmapToArray.
Syntax
Arguments
array— Unsigned integer array.Array(UInt*)
Returned value
Returns a bitmap from the provided array AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapCardinality
Introduced in: v20.1
Returns the number of bits set (the cardinality) in the bitmap.
Syntax
Arguments
bitmap— Bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns the number of bits set in the bitmap UInt64
Examples
Usage example
bitmapContains
Introduced in: v20.1
Checks if the bitmap contains a specific element.
Syntax
Arguments
bitmap— Bitmap object.AggregateFunction(groupBitmap, T). -value— Element to check for. (U)Int8/16/32/64
Returned value
Returns 1 if the bitmap contains the specified value, otherwise 0 UInt8
Examples
Usage example
bitmapHasAll
Introduced in: v20.1
Checks if the first bitmap contains all set bits of the second bitmap.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns 1 if all set bits of the second bitmap are present in the first bitmap, otherwise 0 UInt8
Examples
Usage example
bitmapHasAny
Introduced in: v20.1
Checks if the first bitmap contains any set bits of the second bitmap.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns 1 if any bits of the second bitmap are present in the first bitmap, otherwise 0 UInt8
Examples
Usage example
bitmapMax
Introduced in: v20.1
Returns the position of the greatest bit set in a bitmap, or 0 if the bitmap is empty.
Syntax
Arguments
bitmap— Bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns the position of the greatest bit set in the bitmap, otherwise 0 UInt64
Examples
Usage example
bitmapMin
Introduced in: v20.1
Returns the position of the smallest bit set in a bitmap. If all bits are unset, or UINT32_MAX (UINT64_MAX if the bitmap contains more than 2^64 bits).
Syntax
Arguments
bitmap— Bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns the position of the smallest bit set in the bitmap, or UINT32_MAX/UINT64_MAX UInt64
Examples
Usage example
bitmapOr
Introduced in: v20.1
Computes the logical disjunction (OR) of two bitmaps.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns a bitmap containing set bits present in either input bitmap AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapOrCardinality
Introduced in: v20.1
Returns the cardinality of the logical disjunction (OR) of two bitmaps.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns the number of set bits in the union of the two bitmaps UInt64
Examples
Usage example
bitmapSubsetInRange
Introduced in: v20.1
Returns a subset of the bitmap, containing only the set bits in the specified range [start, end). Uses 1-based indexing.
Syntax
Arguments
bitmap— Bitmap to extract the subset from.AggregateFunction(groupBitmap, T). -start— Start of the range (inclusive).UInt*-end— End of the range (exclusive).UInt*
Returned value
Returns a bitmap containing only the set bits in the specified range AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapSubsetLimit
Introduced in: v20.1
Returns a subset of a bitmap from position range_start with at most cardinality_limit set bits. Uses 1-based indexing.
Syntax
Arguments
bitmap— Bitmap object.AggregateFunction(groupBitmap, T). -range_start— Start of the range (inclusive).UInt32-cardinality_limit— Maximum cardinality of the subset.UInt32
Returned value
Returns a bitmap containing at most cardinality_limit set bits, starting from range_start AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapToArray
Introduced in: v20.1
Converts a bitmap to an array of unsigned integers. It is the opposite of function bitmapBuild.
Syntax
Arguments
bitmap— Bitmap to convert.AggregateFunction(groupBitmap, T).
Returned value
Returns an array of unsigned integers contained in the bitmap Array(UInt*)
Examples
Usage example
bitmapTransform
Introduced in: v20.1
Changes up to N bits in a bitmap by swapping specific bit values in from_array with corresponding ones in to_array.
Syntax
Arguments
bitmap— Bitmap object.AggregateFunction(groupBitmap, T). -from_array— Array of original set bits to be replaced.Array(T). -to_array— Array of new set bits to replace with.Array(T).
Returned value
Returns a bitmap with elements transformed according to the given mapping AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapXor
Introduced in: v20.1
Computes the symmetric difference (XOR) of two bitmaps.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns a bitmap containing set bits present in either input bitmap, but not in both AggregateFunction(groupBitmap, T)
Examples
Usage example
bitmapXorCardinality
Introduced in: v20.1
Returns the cardinality of the XOR (symmetric difference) of two bitmaps.
Syntax
Arguments
bitmap1— First bitmap object.AggregateFunction(groupBitmap, T). -bitmap2— Second bitmap object.AggregateFunction(groupBitmap, T).
Returned value
Returns the number of set bits in the symmetric difference of the two bitmaps UInt64
Examples
Usage example
subBitmap
Introduced in: v21.9
Returns a subset of the bitmap, starting from position offset. The maximum cardinality of the returned bitmap is cardinality_limit.
Syntax
Arguments
bitmap— Bitmap object.AggregateFunction(groupBitmap, T). -offset— Number of set bits to skip from the beginning (zero-based).UInt32-cardinality_limit— Maximum number of set bits to include in the subset.UInt32
Returned value
Returns a bitmap containing at most limit set bits, starting after skipping offset set bits in ascending order AggregateFunction(groupBitmap, T)
Examples
Usage example