2020-04-03 13:23:32 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/functions/bitmap-functions
2023-04-19 17:05:55 +00:00
sidebar_position: 25
2022-04-09 13:29:05 +00:00
sidebar_label: Bitmap
2020-04-03 13:23:32 +00:00
---
2022-06-02 10:55:18 +00:00
# Bitmap Functions
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
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.
2019-05-12 14:47:31 +00:00
2022-06-02 10:55:18 +00:00
## bitmapBuild
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Builds a bitmap from an unsigned integer array.
**Syntax**
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
bitmapBuild(array)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `array` – Unsigned integer array.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapBuild([1, 2, 3, 4, 5]) AS res, toTypeName(res);
2019-06-14 10:29:16 +00:00
```
2020-03-20 10:10:48 +00:00
``` text
2019-06-14 10:29:16 +00:00
┌─res─┬─toTypeName(bitmapBuild([1, 2, 3, 4, 5]))─────┐
2021-04-01 20:33:54 +00:00
│ │ AggregateFunction(groupBitmap, UInt8) │
2019-06-14 10:29:16 +00:00
└─────┴──────────────────────────────────────────────┘
2019-05-12 14:47:31 +00:00
```
2022-06-02 10:55:18 +00:00
## bitmapToArray
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Converts bitmap to an integer array.
**Syntax**
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
bitmapToArray(bitmap)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapBuild([1, 2, 3, 4, 5])) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─────────┐
│ [1,2,3,4,5] │
└─────────────┘
```
2022-06-02 10:55:18 +00:00
## bitmapSubsetInRange
2019-07-30 10:54:50 +00:00
2023-04-20 10:18:46 +00:00
Returns the subset of a bitmap with bits within a value interval.
**Syntax**
2019-07-30 10:54:50 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-08-05 02:27:12 +00:00
bitmapSubsetInRange(bitmap, range_start, range_end)
2019-07-30 10:54:50 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-07-30 10:54:50 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – [Bitmap object ](#bitmap_functions-bitmapbuild ).
2024-05-24 03:54:16 +00:00
- `range_start` – Start of the range (inclusive). [UInt32 ](../data-types/int-uint.md ).
- `range_end` – End of the range (exclusive). [UInt32 ](../data-types/int-uint.md ).
2019-07-30 10:54:50 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapSubsetInRange(bitmapBuild([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,100,200,500]), toUInt32(30), toUInt32(200))) AS res;
2019-07-30 10:54:50 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-07-30 10:54:50 +00:00
┌─res───────────────┐
│ [30,31,32,33,100] │
└───────────────────┘
```
2022-06-02 10:55:18 +00:00
## bitmapSubsetLimit
2019-09-17 06:34:08 +00:00
2023-04-20 10:18:46 +00:00
Returns a subset of a bitmap with smallest bit value `range_start` and at most `cardinality_limit` elements.
2019-09-17 06:34:08 +00:00
2019-10-28 19:03:25 +00:00
**Syntax**
2020-03-20 10:10:48 +00:00
``` sql
2019-10-28 19:03:25 +00:00
bitmapSubsetLimit(bitmap, range_start, cardinality_limit)
2019-09-17 06:34:08 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-09-17 06:34:08 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – [Bitmap object ](#bitmap_functions-bitmapbuild ).
2024-05-24 03:54:16 +00:00
- `range_start` – Start of the range (inclusive). [UInt32 ](../data-types/int-uint.md ).
- `cardinality_limit` – Maximum cardinality of the subset. [UInt32 ](../data-types/int-uint.md ).
2019-09-17 06:34:08 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapSubsetLimit(bitmapBuild([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,100,200,500]), toUInt32(30), toUInt32(200))) AS res;
2019-09-17 06:34:08 +00:00
```
2019-10-28 19:03:25 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-09-17 06:34:08 +00:00
┌─res───────────────────────┐
│ [30,31,32,33,100,200,500] │
└───────────────────────────┘
```
2022-06-02 10:55:18 +00:00
## subBitmap
2021-08-05 16:44:07 +00:00
2023-04-20 10:18:46 +00:00
Returns a subset of the bitmap, starting from position `offset` . The maximum cardinality of the returned bitmap is `cardinality_limit` .
2021-08-05 16:44:07 +00:00
**Syntax**
``` sql
2021-08-07 09:42:09 +00:00
subBitmap(bitmap, offset, cardinality_limit)
2021-08-05 16:44:07 +00:00
```
**Arguments**
2024-05-23 13:48:20 +00:00
- `bitmap` – The bitmap. [Bitmap object ](#bitmap_functions-bitmapbuild ).
2024-05-24 03:54:16 +00:00
- `offset` – The position of the first element of the subset. [UInt32 ](../data-types/int-uint.md ).
- `cardinality_limit` – The maximum number of elements in the subset. [UInt32 ](../data-types/int-uint.md ).
2021-08-05 16:44:07 +00:00
**Example**
``` sql
2021-08-07 09:42:09 +00:00
SELECT bitmapToArray(subBitmap(bitmapBuild([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,100,200,500]), toUInt32(10), toUInt32(10))) AS res;
2021-08-05 16:44:07 +00:00
```
Result:
``` text
┌─res─────────────────────────────┐
│ [10,11,12,13,14,15,16,17,18,19] │
└─────────────────────────────────┘
```
2022-06-02 10:55:18 +00:00
## bitmapContains
2019-06-19 13:14:05 +00:00
Checks whether the bitmap contains an element.
2020-03-20 10:10:48 +00:00
``` sql
2023-04-20 10:18:46 +00:00
bitmapContains(bitmap, needle)
2019-06-19 13:14:05 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-06-19 13:14:05 +00:00
2023-04-20 10:18:46 +00:00
- `bitmap` – [Bitmap object ](#bitmap_functions-bitmapbuild ).
2024-05-24 03:54:16 +00:00
- `needle` – Searched bit value. [UInt32 ](../data-types/int-uint.md ).
2019-06-19 13:14:05 +00:00
2019-07-30 06:47:38 +00:00
**Returned values**
2019-06-19 13:14:05 +00:00
2024-05-23 13:48:20 +00:00
- 0 — If `bitmap` does not contain `needle` . [UInt8 ](../data-types/int-uint.md ).
- 1 — If `bitmap` contains `needle` . [UInt8 ](../data-types/int-uint.md ).
2019-06-19 13:14:05 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapContains(bitmapBuild([1,5,7,9]), toUInt32(9)) AS res;
2019-06-19 13:14:05 +00:00
```
2020-03-20 10:10:48 +00:00
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-06-19 13:14:05 +00:00
┌─res─┐
│ 1 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapHasAny
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Checks whether two bitmaps intersect.
If `bitmap2` contains exactly one element, consider using [bitmapContains ](#bitmap_functions-bitmapcontains ) instead as it works more efficiently.
**Syntax**
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-06-14 10:29:16 +00:00
bitmapHasAny(bitmap1, bitmap2)
2019-05-12 14:47:31 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
- `bitmap1` – Bitmap object 1.
- `bitmap2` – Bitmap object 2.
2019-06-14 10:29:16 +00:00
**Return values**
2023-04-20 10:18:46 +00:00
- `1` , if `bitmap1` and `bitmap2` have at least one shared element.
2023-04-19 15:55:29 +00:00
- `0` , otherwise.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapHasAny(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
│ 1 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapHasAll
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Returns 1 if the first bitmap contains all elements of the second bitmap, otherwise 0.
If the second bitmap is empty, returns 1.
Also see `hasAll(array, array)` .
**Syntax**
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2023-04-20 10:18:46 +00:00
bitmapHasAll(bitmap1, bitmap2)
2019-05-12 14:47:31 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
- `bitmap1` – Bitmap object 1.
- `bitmap2` – Bitmap object 2.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapHasAll(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
│ 0 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapCardinality
2019-11-02 10:10:48 +00:00
2023-05-04 16:35:18 +00:00
Returns the cardinality of a bitmap.
2023-04-20 10:18:46 +00:00
**Syntax**
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-11-02 10:10:48 +00:00
bitmapCardinality(bitmap)
2019-05-12 14:47:31 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapCardinality(bitmapBuild([1, 2, 3, 4, 5])) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
2019-11-02 10:10:48 +00:00
│ 5 │
2019-05-12 14:47:31 +00:00
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapMin
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Computes the smallest bit set in a bitmap, or UINT32_MAX if the bitmap is empty.
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
**Syntax**
```sql
bitmapMin(bitmap)
```
2019-05-12 14:47:31 +00:00
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapMin(bitmapBuild([1, 2, 3, 4, 5])) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2021-03-13 18:18:45 +00:00
``` text
┌─res─┐
│ 1 │
└─────┘
```
2019-05-12 14:47:31 +00:00
2022-06-02 10:55:18 +00:00
## bitmapMax
2019-11-02 10:10:48 +00:00
2023-04-20 10:18:46 +00:00
Computes the greatest bit set in a bitmap, or 0 if the bitmap is empty.
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
**Syntax**
```sql
bitmapMax(bitmap)
```
2019-05-12 14:47:31 +00:00
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapMax(bitmapBuild([1, 2, 3, 4, 5])) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2021-03-13 18:18:45 +00:00
``` text
┌─res─┐
│ 5 │
└─────┘
```
2019-05-12 14:47:31 +00:00
2022-06-02 10:55:18 +00:00
## bitmapTransform
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Replaces at most N bits in a bitmap. The old and new value of the i-th replaced bit is given by `from_array[i]` and `to_array[i]` .
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
The result depends on the array ordering if `from_array` and `to_array` .
**Syntax**
``` sql
bitmapTransform(bitmap, from_array, to_array)
```
2019-05-12 14:47:31 +00:00
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2023-04-20 10:18:46 +00:00
- `from_array` – UInt32 array. For idx in range \[0, from_array.size()), if bitmap contains from_array\[idx\], then replace it with to_array\[idx\].
- `to_array` – UInt32 array with the same size as `from_array` .
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapTransform(bitmapBuild([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), cast([5,999,2] as Array(UInt32)), cast([2,888,20] as Array(UInt32)))) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2021-03-13 18:18:45 +00:00
``` text
┌─res───────────────────┐
│ [1,3,4,6,7,8,9,10,20] │
└───────────────────────┘
```
2019-05-12 14:47:31 +00:00
2022-06-02 10:55:18 +00:00
## bitmapAnd
2019-05-12 14:47:31 +00:00
2024-02-13 01:10:41 +00:00
Computes the logical conjunction of two bitmaps.
2023-04-20 10:18:46 +00:00
**Syntax**
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-11-02 10:10:48 +00:00
bitmapAnd(bitmap,bitmap)
2019-05-12 14:47:31 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapAnd(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res;
2019-05-12 14:47:31 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
2019-11-02 10:10:48 +00:00
│ [3] │
2019-05-12 14:47:31 +00:00
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapOr
2019-09-18 08:30:18 +00:00
2023-04-20 10:18:46 +00:00
Computes the logical disjunction of two bitmaps.
**Syntax**
2019-09-18 08:30:18 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-11-02 10:10:48 +00:00
bitmapOr(bitmap,bitmap)
2019-09-18 08:30:18 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-09-18 08:30:18 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-09-18 08:30:18 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapOr(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res;
2019-09-18 08:30:18 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-11-02 10:10:48 +00:00
┌─res─────────┐
│ [1,2,3,4,5] │
└─────────────┘
2019-09-18 08:30:18 +00:00
```
2019-11-02 10:10:48 +00:00
2022-06-02 10:55:18 +00:00
## bitmapXor
2019-11-02 10:10:48 +00:00
2023-04-20 10:18:46 +00:00
Xor-s two bitmaps.
**Syntax**
2019-11-02 10:10:48 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-11-02 10:10:48 +00:00
bitmapXor(bitmap,bitmap)
2019-09-18 08:30:18 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-09-18 08:30:18 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-09-18 08:30:18 +00:00
2019-11-02 10:10:48 +00:00
**Example**
2019-09-18 08:30:18 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapXor(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res;
2019-09-18 08:30:18 +00:00
```
2019-11-02 10:10:48 +00:00
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-11-02 10:10:48 +00:00
┌─res───────┐
│ [1,2,4,5] │
└───────────┘
```
2022-06-02 10:55:18 +00:00
## bitmapAndnot
2019-11-02 10:10:48 +00:00
2023-04-20 10:18:46 +00:00
Computes the logical conjunction of two bitmaps and negates the result.
**Syntax**
2019-11-02 10:10:48 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-11-02 10:10:48 +00:00
bitmapAndnot(bitmap,bitmap)
2019-09-18 08:30:18 +00:00
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-09-18 08:30:18 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-09-18 08:30:18 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2021-03-13 18:18:45 +00:00
SELECT bitmapToArray(bitmapAndnot(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res;
2019-09-18 08:30:18 +00:00
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-11-02 10:10:48 +00:00
┌─res───┐
│ [1,2] │
└───────┘
2019-09-18 08:30:18 +00:00
```
2022-06-02 10:55:18 +00:00
## bitmapAndCardinality
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Returns the cardinality of the logical conjunction of two bitmaps.
**Syntax**
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
bitmapAndCardinality(bitmap,bitmap)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
SELECT bitmapAndCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
│ 1 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapOrCardinality
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Returns the cardinality of the logical disjunction of two bitmaps.
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
bitmapOrCardinality(bitmap,bitmap)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
SELECT bitmapOrCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
│ 5 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapXorCardinality
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Returns the cardinality of the XOR of two bitmaps.
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
bitmapXorCardinality(bitmap,bitmap)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
SELECT bitmapXorCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
│ 4 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## bitmapAndnotCardinality
2019-05-12 14:47:31 +00:00
2023-04-20 10:18:46 +00:00
Returns the cardinality of the AND-NOT operation of two bitmaps.
2019-05-12 14:47:31 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
bitmapAndnotCardinality(bitmap,bitmap)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2019-05-12 14:47:31 +00:00
2023-04-19 15:55:29 +00:00
- `bitmap` – Bitmap object.
2019-05-12 14:47:31 +00:00
**Example**
2020-03-20 10:10:48 +00:00
``` sql
2019-05-12 14:47:31 +00:00
SELECT bitmapAndnotCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
```
2023-04-20 10:18:46 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2019-05-12 14:47:31 +00:00
┌─res─┐
│ 2 │
└─────┘
```