Files
greptimedb/tests/cases/standalone/common/aggregate/hll.result
discord9 7252ceb4bb feat(flow): add generic delta merge for incremental aggregates (#8938)
* feat(function): add internal delta merge aggregates

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

* test(function): cover delta merge aggregates in SQL

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

* feat(function): add Welford delta merge aggregate

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

---------

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-09-01 12:27:54 +00:00

119 lines
2.5 KiB
Plaintext

CREATE TABLE test_hll (
`id` INT PRIMARY KEY,
`value` STRING,
`ts` timestamp time index default now()
);
Affected Rows: 0
INSERT INTO test_hll (`id`, `value`) VALUES
(1, "a"),
(2, "b"),
(5, "e"),
(6, "f"),
(7, "g"),
(8, "h"),
(9, "i"),
(10, "j"),
(11, "i"),
(12, "j"),
(13, "i"),
(14, "n"),
(15, "o");
Affected Rows: 13
select hll_count(hll(`value`)) from test_hll;
+--------------------------------+
| hll_count(hll(test_hll.value)) |
+--------------------------------+
| 10 |
+--------------------------------+
INSERT INTO test_hll (`id`, `value`) VALUES
(16, "b"),
(17, "i"),
(18, "j"),
(19, "s"),
(20, "t");
Affected Rows: 5
select hll_count(hll(`value`)) from test_hll;
+--------------------------------+
| hll_count(hll(test_hll.value)) |
+--------------------------------+
| 12 |
+--------------------------------+
create table test_hll_merge (
`id` INT PRIMARY KEY,
`state` BINARY,
`ts` timestamp time index default now()
);
Affected Rows: 0
insert into test_hll_merge (`id`, `state`)
select 1, hll(`value`) from test_hll;
Affected Rows: 1
insert into test_hll_merge (`id`, `state`)
select 2, hll(`value`) from test_hll;
Affected Rows: 1
select hll_count(hll_merge(`state`)) from test_hll_merge;
+--------------------------------------------+
| hll_count(hll_merge(test_hll_merge.state)) |
+--------------------------------------------+
| 12 |
+--------------------------------------------+
CREATE TABLE test_hll_delta_merge (
`id` INT PRIMARY KEY,
`delta` BINARY,
`persisted` BINARY,
`ts` timestamp time index default now()
);
Affected Rows: 0
INSERT INTO test_hll_delta_merge (`id`, `delta`, `persisted`)
SELECT 1, hll(`value`), NULL FROM test_hll WHERE `id` <= 15;
Affected Rows: 1
INSERT INTO test_hll_delta_merge (`id`, `delta`, `persisted`)
SELECT 2, NULL, hll(`value`) FROM test_hll WHERE `id` > 15;
Affected Rows: 1
SELECT
hll_count(__hll_delta_merge(`delta`, `persisted`)) AS merged_count,
(SELECT hll_count(hll(`value`)) FROM test_hll) AS direct_count
FROM test_hll_delta_merge;
+--------------+--------------+
| merged_count | direct_count |
+--------------+--------------+
| 12 | 12 |
+--------------+--------------+
drop table test_hll;
Affected Rows: 0
drop table test_hll_merge;
Affected Rows: 0
drop table test_hll_delta_merge;
Affected Rows: 0