Help wanted!
The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.
ビットマップ関数
And、or、xor、notなどの数式の計算を使用しながら、新しいビットマップまたは基数を返すことです。
ビットマップオブジェクトの構築方法には2種類あります。 一つは-Stateを持つ集計関数groupBitmapによって構築され、もう一つはArray Objectによって構築されます。 でも変換するビットマップオブジェクト配列のオブジェクトです。
RoaringBitmapは、ビットマップオブジェクトの実際の格納中にデータ構造にラップされます。 基数が32以下の場合、Set objetが使用されます。 基数が32より大きい場合は、RoaringBitmapオブジェクトを使用します。 そのため、低基数セットの保存が高速になります。
RoaringBitmapの詳細については、以下を参照してください: クロアリング.
bitmapBuild
符号なし整数配列からビットマップを作成します。
bitmapBuild(array)
パラメータ
array
– unsigned integer array.
例
SELECT bitmapBuild([1, 2, 3, 4, 5]) AS res, toTypeName(res)
┌─res─┬─toTypeName(bitmapBuild([1, 2, 3, 4, 5]))─────┐
│ │ AggregateFunction(groupBitmap, UInt8) │
└─────┴──────────────────────────────────────────────┘
bitmapToArray
ビットマップを整数配列に変換します。
bitmapToArray(bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapToArray(bitmapBuild([1, 2, 3, 4, 5])) AS res
┌─res─────────┐
│ [1,2,3,4,5] │
└─────────────┘
bitmapSubsetInRange
指定された範囲のサブセットを返します(range_endは含まれません)。
bitmapSubsetInRange(bitmap, range_start, range_end)
パラメータ
bitmap
– ビットマップ.range_start
– range start point. Type: UInt32.range_end
– range end point(excluded). Type: UInt32.
例
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
┌─res───────────────┐
│ [30,31,32,33,100] │
└───────────────────┘
bitmapSubsetLimit
ビットマップのサブセットを作成します。 range_start
と cardinality_limit
.
構文
bitmapSubsetLimit(bitmap, range_start, cardinality_limit)
パラメータ
bitmap
– ビットマップ.range_start
– The subset starting point. Type: UInt32.cardinality_limit
– The subset cardinality upper limit. Type: UInt32.
戻り値
サブセット。
タイプ: Bitmap object
.
例
クエリ:
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
結果:
┌─res───────────────────────┐
│ [30,31,32,33,100,200,500] │
└───────────────────────────┘
bitmapContains
かどうかをチェックしますビットマップを含む要素になります。
bitmapContains(haystack, needle)
パラメータ
戻り値
- 0 — If
haystack
含まないneedle
. - 1 — If
haystack
含むneedle
.
タイプ: UInt8
.
例
SELECT bitmapContains(bitmapBuild([1,5,7,9]), toUInt32(9)) AS res
┌─res─┐
│ 1 │
└─────┘
bitmapHasAny
るかどうかを判二つのビットマップしていることで交差点にある。
bitmapHasAny(bitmap1, bitmap2)
あなたがそれを確信している場合 bitmap2
厳密に一つの要素が含まれています。 bitmapContains 機能。 これは、より効率的に動作します。
パラメータ
bitmap*
– bitmap object.
戻り値
1
,ifbitmap1
とbitmap2
少なくとも一つの同様の要素があります。0
そうでなければ
例
SELECT bitmapHasAny(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res
┌─res─┐
│ 1 │
└─────┘
bitmapHasAll
類似する hasAll(array, array)
返り値が1の場合は最初のビットマップを含むすべての要素は、0です。
二番目の引数が空のビットマップの場合は、1を返します。
bitmapHasAll(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapHasAll(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res
┌─res─┐
│ 0 │
└─────┘
bitmapCardinality
UInt64型のビットマップ基数を再実行します。
bitmapCardinality(bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapCardinality(bitmapBuild([1, 2, 3, 4, 5])) AS res
┌─res─┐
│ 5 │
└─────┘
bitmapMin
セット内のUInt64型の最小値を再実行し、セットが空の場合はUINT32_MAX。
bitmapMin(bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapMin(bitmapBuild([1, 2, 3, 4, 5])) AS res
┌─res─┐
│ 1 │
└─────┘
bitmapMax
セット内のUInt64型の最大値を再試行し、セットが空の場合は0を再試行します。
bitmapMax(bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapMax(bitmapBuild([1, 2, 3, 4, 5])) AS res
┌─res─┐
│ 5 │
└─────┘
bitmapTransform
ビットマップ内の値の配列を別の値の配列に変換すると、結果は新しいビットマップになります。
bitmapTransform(bitmap, from_array, to_array)
パラメータ
bitmap
– bitmap object.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]. Note that the result depends on array ordering if there are common elements between from_array and to_array.to_array
– UInt32 array, its size shall be the same to from_array.
例
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
┌─res───────────────────┐
│ [1,3,4,6,7,8,9,10,20] │
└───────────────────────┘
bitmapAnd
二つのビットマップと計算、結果は新しいビットマップです。
bitmapAnd(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapToArray(bitmapAnd(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res
┌─res─┐
│ [3] │
└─────┘
bitmapOr
結果は新しいビットマップです。
bitmapOr(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapToArray(bitmapOr(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res
┌─res─────────┐
│ [1,2,3,4,5] │
└─────────────┘
bitmapXor
二つのビットマップxorの計算は、結果は新しいビットマップです。
bitmapXor(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapToArray(bitmapXor(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res
┌─res───────┐
│ [1,2,4,5] │
└───────────┘
bitmapAndnot
二つのビットマップandnot計算、結果は新しいビットマップです。
bitmapAndnot(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapToArray(bitmapAndnot(bitmapBuild([1,2,3]),bitmapBuild([3,4,5]))) AS res
┌─res───┐
│ [1,2] │
└───────┘
bitmapAndCardinality
Uint64型の基数を返します。
bitmapAndCardinality(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapAndCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
┌─res─┐
│ 1 │
└─────┘
bitmapOrCardinality
Uint64型の基数を返します。
bitmapOrCardinality(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapOrCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
┌─res─┐
│ 5 │
└─────┘
bitmapXorCardinality
Uint64型の基数を返します。
bitmapXorCardinality(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapXorCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
┌─res─┐
│ 4 │
└─────┘
bitmapAndnotCardinality
Uint64型の基数を返します。
bitmapAndnotCardinality(bitmap,bitmap)
パラメータ
bitmap
– bitmap object.
例
SELECT bitmapAndnotCardinality(bitmapBuild([1,2,3]),bitmapBuild([3,4,5])) AS res;
┌─res─┐
│ 2 │
└─────┘