创建表:
CREATE TABLE simpleAggregateFunction_test (
id String,
col1 SimpleAggregateFunction(sum, UInt64),
col2 SimpleAggregateFunction(groupUniqArrayArray, Array(Tuple(UInt32,String)))
) ENGINE = AggregatingMergeTree
order by (id);
插入数据:
INSERT INTO simpleAggregateFunction_test select ‘111’,toUInt64(100), [(1,‘xxx1’)];
INSERT INTO simpleAggregateFunction_test select ‘111’,toUInt64(200), [(2,‘xxx2’)];
INSERT INTO simpleAggregateFunction_test select ‘111’,toUInt64(50), [(2,‘xxx2’)];
INSERT INTO simpleAggregateFunction_test select ‘111’,toUInt64(50), [(3,‘xxx2’)];
查询
optimize table simpleAggregateFunction_test final;
select * ,arraySum(item -> item.1,col2) as rs from simpleAggregateFunction_test;
结果:
id |col1|col2 |rs|
—±—±---------------------------------±-+
111|400 |[(3,‘xxx2’),(2,‘xxx2’),(1,‘xxx1’)]| 6|