비트맵은 두 가지 방법으로 만들 수 있습니다. 첫 번째는 집계 함수 groupBitmap에 -State를 사용해 만드는 방법이고, 다른 하나는 배열 객체에서 비트맵을 만드는 방법입니다.
bitmapAnd
Introduced in: v20.1.0
두 비트맵의 논리곱(AND)을 계산합니다.
구문
bitmapAnd(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T).
반환 값
두 입력 비트맵에 공통으로 존재하는 비트를 포함한 비트맵을 반환합니다 AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT bitmapToArray(bitmapAnd(bitmapBuild([1, 2, 3]), bitmapBuild([3, 4, 5]))) AS res;┌─res─┐
│ [3] │
└─────┘bitmapAndCardinality
도입 버전: v20.1.0
두 비트맵의 논리곱(AND)에 대한 카디널리티를 반환합니다.
구문
bitmapAndCardinality(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체.AggregateFunction(groupBitmap, T).
반환 값
두 비트맵의 교집합에 있는 1로 설정된 비트 수를 반환합니다 UInt64
예시
사용 예시
SELECT bitmapAndCardinality(bitmapBuild([1,2,3]), bitmapBuild([3,4,5])) AS res;┌─res─┐
│ 1 │
└─────┘bitmapAndnot
도입 버전: v20.1.0
두 비트맵에 대해 집합 차 A AND-NOT B를 계산합니다.
구문
bitmapAndnot(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T).
반환 값
첫 번째 비트맵에는 있고 두 번째 비트맵에는 없는 1로 설정된 비트가 포함된 비트맵을 반환합니다 AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT bitmapToArray(bitmapAndnot(bitmapBuild([1, 2, 3]), bitmapBuild([3, 4, 5]))) AS res;┌─res───┐
│ [1,2] │
└───────┘bitmapAndnotCardinality
도입 버전: v20.1.0
두 비트맵에 대해 AND-NOT 연산의 카디널리티를 반환합니다.
구문
bitmapAndnotCardinality(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T).
반환 값
bitmap1 AND-NOT bitmap2 결과에서 1로 설정된 비트 수를 반환합니다. UInt64
예시
사용 예시
SELECT bitmapAndnotCardinality(bitmapBuild([1,2,3]), bitmapBuild([3,4,5])) AS res;┌─res─┐
│ 2 │
└─────┘bitmapBuild
도입 버전: v20.1.0
정수 배열에서 비트맵을 생성합니다. 지원되는 원소 타입은 8, 16, 32 또는 64비트의 부호 있는 정수와 부호 없는 정수입니다. 함수 bitmapToArray의 반대 기능입니다.
구문
bitmapBuild(array)인수
array— 정수 배열.Array((U)Int*)
반환 값
지정된 배열에서 생성된 비트맵을 반환합니다. AggregateFunction(groupBitmap, T)
예시
사용 예시
-- A bitmap is a binary value, so it is shown with `hex`.
SELECT hex(bitmapBuild([1, 2, 3, 4, 5])) AS res, toTypeName(bitmapBuild([1, 2, 3, 4, 5])) AS type;┌─res────────────┬─type──────────────────────────────────┐
│ 00050102030405 │ AggregateFunction(groupBitmap, UInt8) │
└────────────────┴───────────────────────────────────────┘부호 있는 비트맵
-- A bitmap is a binary value, so it is shown with `hex`.
SELECT hex(bitmapBuild([-128, -1]::Array(Int8))) AS res, toTypeName(bitmapBuild([-128, -1]::Array(Int8))) AS type;┌─res──────┬─type─────────────────────────────────┐
│ 000280FF │ AggregateFunction(groupBitmap, Int8) │
└──────────┴──────────────────────────────────────┘bitmapCardinality
도입 버전: v20.1.0
비트맵에서 1로 설정된 비트 수(카디널리티)를 반환합니다.
구문
bitmapCardinality(bitmap)인수
bitmap— 비트맵 객체.AggregateFunction(groupBitmap, T).
반환 값
비트맵에 설정된 비트 수를 반환합니다. UInt64
예시
사용 예시
SELECT bitmapCardinality(bitmapBuild([1, 3, 3, 5, 7, 7])) AS res┌─res─┐
│ 4 │
└─────┘bitmapContains
도입 버전: v20.1.0
비트맵에 특정 원소가 포함되어 있는지 확인합니다. 값은 비트맵 원소 타입의 부호 없는 정수로 비교됩니다. 부호 있는 비트맵에서 음수 원소는 그에 대응하는 부호 없는 값과 일치합니다(예: Int8 값 -1은 255와 일치함).
구문
bitmapContains(bitmap, value)인수
bitmap— 비트맵 객체.AggregateFunction(groupBitmap, T). -value— 확인할 원소. (U)Int8/16/32/64
반환 값
비트맵에 지정된 값이 포함되어 있으면 1, 그렇지 않으면 0을 반환합니다. UInt8
예시
사용 예시
SELECT bitmapContains(bitmapBuild([1, 2, 3]), 2) AS res;┌─res─┐
│ 1 │
└─────┘부호 있는 비트맵
SELECT bitmapContains(bitmapBuild([-1]::Array(Int8)), 255) AS res;┌─res─┐
│ 1 │
└─────┘bitmapHasAll
도입 버전: v20.1.0
첫 번째 비트맵에 두 번째 비트맵에서 1로 설정된 비트가 모두 포함되어 있는지 확인합니다.
구문
bitmapHasAll(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체.AggregateFunction(groupBitmap, T).
반환 값
두 번째 비트맵에서 설정된 모든 비트가 첫 번째 비트맵에도 있으면 1을, 그렇지 않으면 0을 반환합니다 UInt8
예시
사용 예시
SELECT bitmapHasAll(bitmapBuild([1, 2, 3]), bitmapBuild([2, 3])) AS res;┌─res─┐
│ 1 │
└─────┘bitmapHasAny
도입 버전: v20.1.0
첫 번째 비트맵에 두 번째 비트맵에서 1로 설정된 비트가 하나라도 있는지 확인합니다.
구문
bitmapHasAny(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T).
반환 값
두 번째 비트맵의 비트 중 하나라도 첫 번째 비트맵에 포함되어 있으면 1을, 그렇지 않으면 0을 반환합니다. UInt8
예시
사용 예시
SELECT bitmapHasAny(bitmapBuild([1, 2, 3]), bitmapBuild([3, 4, 5])) AS res;┌─res─┐
│ 1 │
└─────┘bitmapMax
도입 버전: v20.1.0
비트맵 원소 타입의 부호 없는 정수로 해석했을 때 비트맵에서 가장 큰 원소를 반환합니다. 부호 있는 비트맵의 음수 값은 해당하는 부호 없는 값으로 처리합니다(예: Int8 값 -1은 255입니다). 비트맵이 비어 있으면 0을 반환합니다.
구문
bitmapMax(bitmap)인수
bitmap— 비트맵 객체.AggregateFunction(groupBitmap, T).
반환 값
비트맵 원소 타입의 부호 없는 값으로 가장 큰 원소를 반환하며, 비트맵이 비어 있으면 0을 반환합니다. UInt64
예시
사용 예시
SELECT bitmapMax(bitmapBuild([1, 2, 3, 4, 5])) AS res;┌─res─┐
│ 5 │
└─────┘부호 있는 비트맵
SELECT bitmapMax(bitmapBuild([-128, -1]::Array(Int8))) AS res;┌─res─┐
│ 255 │
└─────┘bitmapMin
도입 버전: v20.1.0
비트맵에서 가장 작은 원소를 비트맵 원소 타입의 부호 없는 정수로 해석해 반환합니다. 부호 있는 비트맵에서는 음수 값을 해당하는 부호 없는 값으로 처리합니다(예: Int8 값 -128은 128입니다). 비트맵이 비어 있으면 UINT32_MAX를 반환합니다(비트맵 원소 타입이 32비트보다 크면 UINT64_MAX).
구문
bitmapMin(bitmap)인수
bitmap— 비트맵 객체.AggregateFunction(groupBitmap, T).
반환 값
비트맵 원소 타입의 최솟값을 부호 없는 값으로 반환합니다. 비트맵이 비어 있으면 UINT32_MAX/UINT64_MAX를 반환합니다. UInt64
예시
사용 예시
SELECT bitmapMin(bitmapBuild([3, 5, 2, 6])) AS res;┌─res─┐
│ 2 │
└─────┘부호 있는 비트맵
SELECT bitmapMin(bitmapBuild([-128, -1]::Array(Int8))) AS res;┌─res─┐
│ 128 │
└─────┘bitmapOr
도입 버전: v20.1.0
두 비트맵의 논리합(OR)을 계산합니다.
구문
bitmapOr(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T).
반환 값
입력 비트맵 중 하나에라도 존재하는 1로 설정된 비트를 포함한 비트맵을 반환합니다. AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT bitmapToArray(bitmapOr(bitmapBuild([1, 2, 3]), bitmapBuild([3, 4, 5]))) AS res;┌─res─────────┐
│ [1,2,3,4,5] │
└─────────────┘bitmapOrCardinality
도입 버전: v20.1.0
두 비트맵의 논리합(OR) 결과의 카디널리티를 반환합니다.
구문
bitmapOrCardinality(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T).
반환 값
두 비트맵의 합집합에서 1로 설정된 비트 수를 반환합니다. UInt64
예시
사용 예시
SELECT bitmapOrCardinality(bitmapBuild([1,2,3]), bitmapBuild([3,4,5])) AS res;┌─res─┐
│ 5 │
└─────┘bitmapSubsetInRange
도입 버전: v20.1.0
값 범위 [start, end)에 포함된 원소를 포함하는 비트맵의 부분 집합을 반환합니다. 원소 값은 비트맵 원소 타입의 부호 없는 정수로 비교됩니다.
구문
bitmapSubsetInRange(bitmap, start, end)인수
bitmap— 부분 집합을 추출할 비트맵입니다.AggregateFunction(groupBitmap, T). -start— 범위의 시작(포함)입니다.UInt*-end— 범위의 끝(미포함)입니다.UInt*
반환 값
지정된 값 범위의 원소만 포함하는 비트맵을 반환합니다 AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT bitmapToArray(bitmapSubsetInRange(bitmapBuild([1, 2, 3, 4, 5]), 2, 5)) AS res;┌─res─────┐
│ [2,3,4] │
└─────────┘bitmapSubsetLimit
도입 버전: v20.1.0
값이 range_start 이상인 원소 중 부호 없는 순서로 가장 작은 값부터 선택하여, 최대 cardinality_limit개의 원소로 구성된 부분 집합을 반환합니다.
구문
bitmapSubsetLimit(bitmap, range_start, cardinality_limit)인수
bitmap— 비트맵 객체.AggregateFunction(groupBitmap, T). -range_start— 범위의 시작(포함).UInt32-cardinality_limit— 부분 집합의 최대 카디널리티.UInt32
반환 값
부호 없는 값이 range_start 이상인 원소를 최대 cardinality_limit개 포함하는 비트맵을 반환합니다. AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT arraySort(bitmapToArray(bitmapSubsetLimit(bitmapBuild([1, 5, 3, 2, 8]), 3, 2))) AS res;┌─res───┐
│ [3,5] │
└───────┘bitmapToArray
도입 버전: v20.1.0
비트맵을 해당 원소의 배열로 변환합니다. 배열 원소 타입은 비트맵 원소 타입 T(부호 있는 정수 또는 부호 없는 정수)와 일치합니다. 함수 bitmapBuild와 반대되는 기능입니다.
구문
bitmapToArray(bitmap)인수
bitmap— 변환할 비트맵입니다.AggregateFunction(groupBitmap, T).
반환 값
비트맵에 포함된 원소의 배열을 반환합니다. Array(T)
예시
사용 예시
SELECT bitmapToArray(bitmapBuild([1, 2, 3, 4, 5])) AS res;┌─res─────────┐
│ [1,2,3,4,5] │
└─────────────┘부호 있는 비트맵
SELECT arraySort(bitmapToArray(bitmapBuild([-128, -1]::Array(Int8)))) AS res;┌─res───────┐
│ [-128,-1] │
└───────────┘bitmapTransform
도입 버전: v20.1.0
from_array에서 to_array로의 매핑에 따라 비트맵의 원소를 대체합니다.
값은 비트맵 원소 타입의 부호 없는 정수로 해석됩니다(bitmapContains와 동일한 도메인).
부호 있는 비트맵에서는 음수 원소가 해당 부호 없는 원소와 일치합니다(예: Int8 값 -1은 255와 일치합니다).
to_array의 값이 비트맵 원소 타입에 맞지 않으면 BAD_ARGUMENTS가 발생합니다. from_array의 값이
맞지 않으면 해당 값을 찾을 수 없으므로 대응하는 대체가 적용되지 않습니다.
구문
bitmapTransform(bitmap, from_array, to_array)인수
bitmap— 비트맵 객체.AggregateFunction(groupBitmap, T). -from_array— 대체할 기존의 1로 설정된 비트 배열.Array(T). -to_array— 대체에 사용할 새로 1로 설정된 비트 배열.Array(T).
반환 값
지정된 매핑에 따라 원소가 변환된 비트맵을 반환합니다. AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT bitmapToArray(bitmapTransform(bitmapBuild([1, 2, 3, 4, 5]), [2, 4], [20, 40])) AS res;┌─res───────────┐
│ [1,3,5,20,40] │
└───────────────┘부호 있는 비트맵
SELECT arraySort(bitmapToArray(bitmapTransform(bitmapBuild([-1, 0]::Array(Int8)), [255], [10]))) AS res;┌─res────┐
│ [0,10] │
└────────┘bitmapXor
도입 버전: v20.1.0
두 비트맵의 대칭 차집합(XOR)을 계산합니다.
구문
bitmapXor(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체입니다.AggregateFunction(groupBitmap, T).
반환 값
입력 비트맵 중 한쪽에만 있고 양쪽 모두에 있지는 않은 1로 설정된 비트를 포함하는 비트맵을 반환합니다 AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT bitmapToArray(bitmapXor(bitmapBuild([1, 2, 3]), bitmapBuild([3, 4, 5]))) AS res;┌─res───────┐
│ [1,2,4,5] │
└───────────┘bitmapXorCardinality
도입 버전: v20.1.0
두 비트맵의 XOR(대칭 차집합)에 대한 카디널리티를 반환합니다.
구문
bitmapXorCardinality(bitmap1, bitmap2)인수
bitmap1— 첫 번째 비트맵 객체.AggregateFunction(groupBitmap, T). -bitmap2— 두 번째 비트맵 객체.AggregateFunction(groupBitmap, T).
반환 값
두 비트맵의 대칭 차집합에서 1로 설정된 비트 수를 반환합니다 UInt64
예시
사용 예시
SELECT bitmapXorCardinality(bitmapBuild([1,2,3]), bitmapBuild([3,4,5])) AS res;┌─res─┐
│ 4 │
└─────┘subBitmap
도입 버전: v21.9.0
부호 없는 값의 오름차순으로 offset개의 원소를 건너뛴 후 비트맵의 부분 집합을 반환합니다. 반환되는 비트맵의 최대 카디널리티는 cardinality_limit입니다.
구문
subBitmap(bitmap, offset, cardinality_limit)인수
bitmap— 비트맵 객체.AggregateFunction(groupBitmap, T). -offset— 처음부터 건너뛸 1로 설정된 비트 수(0부터 시작).UInt32-cardinality_limit— 부분 집합에 포함할 1로 설정된 비트의 최대 개수.UInt32
반환 값
부호 없는 값의 오름차순에서 offset개의 원소를 건너뛴 후 최대 cardinality_limit개의 원소를 포함하는 비트맵을 반환합니다 AggregateFunction(groupBitmap, T)
예시
사용 예시
SELECT bitmapToArray(subBitmap(bitmapBuild([1, 2, 3, 4, 5]), 2, 2)) AS res;┌─res───┐
│ [3,4] │
└───────┘