From 1c0d104b482e01e9a99d6c1a92cf4f1c34cec51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Wed, 17 Apr 2024 01:31:40 +0100 Subject: [PATCH] Fix argMin/argMax combinator state --- ...gregateFunctionCombinatorsArgMinArgMax.cpp | 4 ++-- .../03127_argMin_combinator_state.reference | 12 ++++++++++ .../03127_argMin_combinator_state.sql | 22 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/03127_argMin_combinator_state.reference create mode 100644 tests/queries/0_stateless/03127_argMin_combinator_state.sql 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