Merge pull request #62770 from ClickHouse/backport/24.3/62708

Backport #62708 to 24.3: Fix argMin/argMax combinator state
This commit is contained in:
robot-ch-test-poll2 2024-04-18 22:45:05 +04:00 committed by GitHub
commit dadaa13de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 129 additions and 2 deletions

View File

@ -68,9 +68,9 @@ public:
String getName() const override
{
if constexpr (isMin)
return "ArgMin";
return nested_function->getName() + "ArgMin";
else
return "ArgMax";
return nested_function->getName() + "ArgMax";
}
bool isState() const override { return nested_function->isState(); }

View File

@ -0,0 +1,12 @@
AggregateFunction(sumArgMin, UInt64, UInt64)
54
0 45
1 46
2 47
3 48
4 49
5 50
6 51
7 52
8 53
9 54

View File

@ -0,0 +1,22 @@
SELECT toTypeName(sumArgMinState(number, number)) FROM numbers(1);
SELECT sumArgMinState(number, number) AS a FROM numbers(3) FORMAT Null;
DROP TABLE IF EXISTS argmax_comb;
CREATE TABLE argmax_comb(
id UInt64,
state AggregateFunction(avgArgMax, Float64, UInt64)
)
ENGINE=MergeTree() ORDER BY tuple();
INSERT INTO argmax_comb
SELECT
CAST(number % 10, 'UInt64') AS id,
avgArgMaxState(CAST(number, 'Float64'), id)
FROM numbers(100)
GROUP BY id;
SELECT avgArgMaxMerge(state) FROM argmax_comb;
SELECT
id,
avgArgMaxMerge(state)
FROM argmax_comb
GROUP BY id
ORDER BY id ASC;

View File

@ -0,0 +1,20 @@
0 2024-01-01 00:00:00 2024-03-31 00:00:00
1 2024-01-02 00:00:00 2024-04-01 00:00:00
2 2024-01-03 00:00:00 2024-04-02 00:00:00
3 2024-01-04 00:00:00 2024-04-03 00:00:00
4 2024-01-05 00:00:00 2024-04-04 00:00:00
5 2024-01-06 00:00:00 2024-04-05 00:00:00
6 2024-01-07 00:00:00 2024-04-06 00:00:00
7 2024-01-08 00:00:00 2024-04-07 00:00:00
8 2024-01-09 00:00:00 2024-04-08 00:00:00
9 2024-01-10 00:00:00 2024-04-09 00:00:00
0 2024-01-01 00:00:00 2024-03-31 00:00:00
1 2024-01-02 00:00:00 2024-04-01 00:00:00
2 2024-01-03 00:00:00 2024-04-02 00:00:00
3 2024-01-04 00:00:00 2024-04-03 00:00:00
4 2024-01-05 00:00:00 2024-04-04 00:00:00
5 2024-01-06 00:00:00 2024-04-05 00:00:00
6 2024-01-07 00:00:00 2024-04-06 00:00:00
7 2024-01-08 00:00:00 2024-04-07 00:00:00
8 2024-01-09 00:00:00 2024-04-08 00:00:00
9 2024-01-10 00:00:00 2024-04-09 00:00:00

View File

@ -0,0 +1,73 @@
DROP TABLE IF EXISTS combinator_argMin_table_r1 SYNC;
DROP TABLE IF EXISTS combinator_argMin_table_r2 SYNC;
CREATE TABLE combinator_argMin_table_r1
(
`id` Int32,
`value` Int32,
`agg_time` DateTime,
PROJECTION first_items
(
SELECT
id,
minArgMin(agg_time, value),
maxArgMax(agg_time, value)
GROUP BY id
)
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/test_03128/combinator_argMin_table', 'r1')
ORDER BY (id);
INSERT INTO combinator_argMin_table_r1
SELECT
number % 10 as id,
number as value,
'01-01-2024 00:00:00' + INTERVAL number DAY
FROM
numbers(100);
INSERT INTO combinator_argMin_table_r1
SELECT
number % 10 as id,
number * 10 as value,
'01-01-2024 00:00:00' + INTERVAL number DAY
FROM
numbers(100);
SELECT
id,
minArgMin(agg_time, value),
maxArgMax(agg_time, value)
FROM combinator_argMin_table_r1
GROUP BY id
ORDER BY id
SETTINGS force_optimize_projection=1;
-- We check replication by creating another replica
CREATE TABLE combinator_argMin_table_r2
(
`id` Int32,
`value` Int32,
`agg_time` DateTime,
PROJECTION first_items
(
SELECT
id,
minArgMin(agg_time, value),
maxArgMax(agg_time, value)
GROUP BY id
)
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/test_03128/combinator_argMin_table', 'r2')
ORDER BY (id);
SYSTEM SYNC REPLICA combinator_argMin_table_r2;
SELECT
id,
minArgMin(agg_time, value),
maxArgMax(agg_time, value)
FROM combinator_argMin_table_r2
GROUP BY id
ORDER BY id
SETTINGS force_optimize_projection=1;