ClickHouse/docs/zh/sql-reference/aggregate-functions/reference/groupbitmapand.md
2022-08-26 15:07:59 -04:00

1.6 KiB
Raw Blame History

slug sidebar_position
/zh/sql-reference/aggregate-functions/reference/groupbitmapand 129

groupBitmapAnd

计算位图列的 AND ,返回 UInt64 类型的基数,如果添加后缀 State ,则返回 位图对象

语法

groupBitmapAnd(expr)

参数

expr 结果为 AggregateFunction(groupBitmap, UInt*) 类型的表达式。

返回值

UInt64 类型的值。

示例

DROP TABLE IF EXISTS bitmap_column_expr_test2;
CREATE TABLE bitmap_column_expr_test2
(
    tag_id String,
    z AggregateFunction(groupBitmap, UInt32)
)
ENGINE = MergeTree
ORDER BY tag_id;

INSERT INTO bitmap_column_expr_test2 VALUES ('tag1', bitmapBuild(cast([1,2,3,4,5,6,7,8,9,10] as Array(UInt32))));
INSERT INTO bitmap_column_expr_test2 VALUES ('tag2', bitmapBuild(cast([6,7,8,9,10,11,12,13,14,15] as Array(UInt32))));
INSERT INTO bitmap_column_expr_test2 VALUES ('tag3', bitmapBuild(cast([2,4,6,8,10,12] as Array(UInt32))));

SELECT groupBitmapAnd(z) FROM bitmap_column_expr_test2 WHERE like(tag_id, 'tag%');
┌─groupBitmapAnd(z)─┐
               3   
└───────────────────┘

SELECT arraySort(bitmapToArray(groupBitmapAndState(z))) FROM bitmap_column_expr_test2 WHERE like(tag_id, 'tag%');
┌─arraySort(bitmapToArray(groupBitmapAndState(z)))─┐
 [6,8,10]                                         
└──────────────────────────────────────────────────┘