ClickHouse/src/Processors/QueryPlan
Azat Khuzhin dea1706d4e
Fix GROUP BY AggregateFunction (#37093)
* Fix GROUP BY AggregateFunction

finalizeChunk() was unconditionally converting AggregateFunction to the
underlying type, however this should be done only if the aggregate was
applied.

So pass names of aggregates as an argument to the finalizeChunk()

Fuzzer report [1]:

    Logical error: 'Bad cast from type DB::ColumnArray to DB::ColumnAggregateFunction'. Received signal 6 Received signal Aborted (6)

For the following query:

    SELECT
        arraySort(groupArrayArray(grp_simple)),
        grp_aggreg,
        arraySort(groupArrayArray(grp_simple)),
        b,
        arraySort(groupArrayArray(grp_simple)) AS grs
    FROM data_02294
    GROUP BY
        a,
        grp_aggreg,
        b
    SETTINGS optimize_aggregation_in_order = 1

  [1]: https://s3.amazonaws.com/clickhouse-test-reports/37050/323ae98202d80fc4b311be1e7308ef2ac39e6063/fuzzer_astfuzzerdebug,actions//fuzzer.log

v2: fix conflicts in src/Interpreters/InterpreterSelectQuery.cpp
v3: Fix header for GROUP BY AggregateFunction WITH TOTALS
v4: Add sanity check into finalizeBlock()
v5: Use typeid_cast<&> to get more sensible error in case of bad cast (as suggested by @nickitat)
v6: Fix positions passed to finalizeChunk()
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>

* Core/ColumnNumbers.h: remove unused <string>

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>

* Optimize finalizeChunk()/finalizeBlock()

v2: s/ByPosition/Mask/ s/by_position/mask/
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2022-05-18 23:37:43 +02:00
..
Optimizations Activate clang-tidy warning "readability-container-contains" 2022-04-18 23:53:11 +02:00
AggregatingStep.cpp Fix new occurrences of new clang-tidy warnings 2022-05-16 11:31:36 +02:00
AggregatingStep.h Simplify code a little bit. 2022-05-10 16:12:03 +00:00
ArrayJoinStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
ArrayJoinStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
BuildQueryPipelineSettings.cpp Hook progress callbacks with subqueries too 2021-12-22 23:13:45 +01:00
BuildQueryPipelineSettings.h Hook progress callbacks with subqueries too 2021-12-22 23:13:45 +01:00
CreatingSetsStep.cpp clang-tidy check performance-move-const-arg fix 2022-03-02 18:15:27 +00:00
CreatingSetsStep.h Remove DataStreams folder. 2021-10-15 23:18:20 +03:00
CubeStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
CubeStep.h Remove DataStreams folder. 2021-10-15 23:18:20 +03:00
DistinctStep.cpp Activate clang-tidy warning "readability-container-contains" 2022-04-18 23:53:11 +02:00
DistinctStep.h Remove DataStreams folder. 2021-10-15 23:18:20 +03:00
DistributedCreateLocalPlan.cpp Made parallel_reading_from_replicas work with localhost replica (#36281) 2022-04-22 15:52:38 +02:00
DistributedCreateLocalPlan.h Made parallel_reading_from_replicas work with localhost replica (#36281) 2022-04-22 15:52:38 +02:00
ExpressionStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
ExpressionStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
ExtremesStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
ExtremesStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
FillingStep.cpp Merge branch 'master' into interpolate-feature 2022-04-05 14:39:07 -04:00
FillingStep.h optimization, INTERPOLATE without expr. list, any column is allowed except WITH FILL 2022-03-24 15:29:29 -04:00
FilterStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
FilterStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
IntersectOrExceptStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
IntersectOrExceptStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
IQueryPlanStep.cpp
IQueryPlanStep.h fix typo 2022-04-27 12:24:49 +00:00
ISourceStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
ISourceStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
ITransformingStep.cpp Improve the pipeline description for JOIN (#35612) 2022-04-04 13:56:41 +02:00
ITransformingStep.h Improve the pipeline description for JOIN (#35612) 2022-04-04 13:56:41 +02:00
JoinStep.cpp update QueryPipelineBuilder::joinPipelines 2022-04-27 10:24:19 +08:00
JoinStep.h update test case tests/queries/0_stateless/02236_explain_pipeline_join.sql 2022-04-27 10:08:22 +08:00
LimitByStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
LimitByStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
LimitStep.cpp Fix LimitStep header after limit push down optimization. 2021-10-22 16:19:49 +03:00
LimitStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
MergingAggregatedStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
MergingAggregatedStep.h Remove DataStreams folder. 2021-10-15 23:18:20 +03:00
OffsetStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
OffsetStep.h Remove DataStreams folder. 2021-10-15 23:18:20 +03:00
QueryIdHolder.cpp Fix potential leak of query_id_holder 2021-10-11 15:56:00 +08:00
QueryIdHolder.h Fix potential leak of query_id_holder 2021-10-11 15:56:00 +08:00
QueryPlan.cpp Refactor many exception messages 2022-04-24 19:44:00 +08:00
QueryPlan.h clang-tidy check performance-noexcept-move-constructor fix 2022-03-02 18:15:27 +00:00
ReadFromMergeTree.cpp Fixed tests 2022-05-11 21:59:51 +02:00
ReadFromMergeTree.h remove description for ReadFromMergeTree from pipeline, adjust tests for plan 2022-03-24 11:31:52 +00:00
ReadFromPreparedSource.cpp Move some files. 2021-10-16 17:03:50 +03:00
ReadFromPreparedSource.h Move some files. 2021-10-16 17:03:50 +03:00
ReadFromRemote.cpp Made parallel_reading_from_replicas work with localhost replica (#36281) 2022-04-22 15:52:38 +02:00
ReadFromRemote.h Parallel reading from replicas (#29279) 2021-12-09 13:39:28 +03:00
ReadNothingStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
ReadNothingStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
RollupStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
RollupStep.h Remove DataStreams folder. 2021-10-15 23:18:20 +03:00
SettingQuotaAndLimitsStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
SettingQuotaAndLimitsStep.h Remove DataStreams folder. 2021-10-15 23:18:20 +03:00
SortingStep.cpp Fixed tests 2022-05-11 21:59:51 +02:00
SortingStep.h Fixed style 2022-05-11 21:59:51 +02:00
TotalsHavingStep.cpp Fix GROUP BY AggregateFunction (#37093) 2022-05-18 23:37:43 +02:00
TotalsHavingStep.h Fix GROUP BY AggregateFunction (#37093) 2022-05-18 23:37:43 +02:00
UnionStep.cpp Move some files. 2021-10-16 17:03:50 +03:00
UnionStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00
WindowStep.cpp Make SortDescription::column_name always non-empty (#35805) 2022-04-04 14:17:15 +02:00
WindowStep.h Rename QueryPipeline to QueryPipelineBuilder. 2021-09-14 19:28:41 +03:00