diff --git a/src/AggregateFunctions/Combinators/AggregateFunctionCombinatorsArgMinArgMax.cpp b/src/AggregateFunctions/Combinators/AggregateFunctionCombinatorsArgMinArgMax.cpp index 71c2bab6f6b..a1716f18725 100644 --- a/src/AggregateFunctions/Combinators/AggregateFunctionCombinatorsArgMinArgMax.cpp +++ b/src/AggregateFunctions/Combinators/AggregateFunctionCombinatorsArgMinArgMax.cpp @@ -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(); } diff --git a/tests/queries/0_stateless/03127_argMin_combinator_state.reference b/tests/queries/0_stateless/03127_argMin_combinator_state.reference new file mode 100644 index 00000000000..33482fd5fbf --- /dev/null +++ b/tests/queries/0_stateless/03127_argMin_combinator_state.reference @@ -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 diff --git a/tests/queries/0_stateless/03127_argMin_combinator_state.sql b/tests/queries/0_stateless/03127_argMin_combinator_state.sql new file mode 100644 index 00000000000..2eb209ed510 --- /dev/null +++ b/tests/queries/0_stateless/03127_argMin_combinator_state.sql @@ -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; \ No newline at end of file diff --git a/tests/queries/0_stateless/03128_argMin_combinator_projection.reference b/tests/queries/0_stateless/03128_argMin_combinator_projection.reference new file mode 100644 index 00000000000..ec9160308f2 --- /dev/null +++ b/tests/queries/0_stateless/03128_argMin_combinator_projection.reference @@ -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 diff --git a/tests/queries/0_stateless/03128_argMin_combinator_projection.sql b/tests/queries/0_stateless/03128_argMin_combinator_projection.sql new file mode 100644 index 00000000000..f0a7f025c95 --- /dev/null +++ b/tests/queries/0_stateless/03128_argMin_combinator_projection.sql @@ -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; \ No newline at end of file