【发布时间】:2021-07-13 07:24:47
【问题描述】:
我想在 clickhouse 中维护一个表,它使用位图“AND”逻辑来合并具有相同 tag_id 行的位图。
由于位图在 clickhouse 中定义为 AggregateFunction(groupBitmap, UInt*) 并且 groupBitmapAnd 将位图作为其参数,因此我创建了一个如下表:
CREATE TABLE test.bitmap_column_expr_test2
(
`tag_id` String,
`z` AggregateFunction(groupBitmapAnd, AggregateFunction(groupBitmap, UInt32))
)
ENGINE = AggregatingMergeTree()
ORDER BY tag_id
SETTINGS index_granularity = 8192
就我而言,我想插入如下数据:
INSERT INTO test.bitmap_column_expr_test2 VALUES ('tag1', groupBitmapAndState(bitmapBuild(cast([1,2,3,4] as Array(UInt32)))));
INSERT INTO test.bitmap_column_expr_test2 VALUES ('tag1', groupBitmapAndState(bitmapBuild(cast([1] as Array(UInt32)))));
INSERT INTO test.bitmap_column_expr_test2 VALUES ('tag1', groupBitmapAndState(bitmapBuild(cast([1,3,4] as Array(UInt32)))));
我希望通过以下方式获得位图和结果:
SELECT bitmapToArray(groupBitmapAndMergeState(z)) FROM test.bitmap_column_expr_test2;
但是,我的 ddl 被 clickhouse 重写为:
CREATE TABLE test.bitmap_column_expr_test2
(
`tag_id` String,
`z` AggregateFunction(groupBitmap, AggregateFunction(groupBitmap, UInt32))
)
ENGINE = AggregatingMergeTree()
ORDER BY tag_id
丢失了列z的原始定义
此外,插入最终会出现异常:
DB::Exception: Aggregate function groupBitmapAndState(bitmapBuild(CAST([1, 2, 3, 4], 'Array(UInt32)'))) is found in wrong place in query: While processing groupBitmapAndState(bitmapBuild(CAST([1, 2, 3, 4], 'Array(UInt32)'))) (version 20.11.4.13 (official build))
我不确定在 AggregatingMergeTree 中通过“AND”逻辑合并的行中获取位图是否正确。
【问题讨论】:
标签: clickhouse