From e2e92afd981b0c3af79fd7d9f70e653dd86f2065 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Mon, 6 Jul 2020 02:17:46 +0300 Subject: [PATCH] fix segfault with -StateResample combinators --- src/Interpreters/Aggregator.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Interpreters/Aggregator.cpp b/src/Interpreters/Aggregator.cpp index 1b8439fc704..39fcb382e57 100644 --- a/src/Interpreters/Aggregator.cpp +++ b/src/Interpreters/Aggregator.cpp @@ -1181,15 +1181,17 @@ Block Aggregator::prepareBlockAndFill( if (aggregate_functions[i]->isState()) { /// The ColumnAggregateFunction column captures the shared ownership of the arena with aggregate function states. - ColumnAggregateFunction * column_aggregate_func = nullptr; - /// Aggregate state can be wrapped into array if aggregate function ends with -Resample combinator. - if (auto * column_array = typeid_cast(final_aggregate_columns[i].get())) - column_aggregate_func = &assert_cast(column_array->getData()); - else - column_aggregate_func = &assert_cast(*final_aggregate_columns[i]); + if (auto * column_aggregate_func = typeid_cast(final_aggregate_columns[i].get())) + for (auto & pool : data_variants.aggregates_pools) + column_aggregate_func->addArena(pool); - for (auto & pool : data_variants.aggregates_pools) - column_aggregate_func->addArena(pool); + /// Aggregate state can be wrapped into array if aggregate function ends with -Resample combinator. + final_aggregate_columns[i]->forEachSubcolumn([&data_variants](auto & subcolumn) + { + if (auto * column_aggregate_func = typeid_cast(subcolumn.get())) + for (auto & pool : data_variants.aggregates_pools) + column_aggregate_func->addArena(pool); + }); } } }