fix segfault with -StateResample combinators

This commit is contained in:
Anton Popov 2020-07-02 19:13:42 +03:00
parent 82061da77c
commit a5cbeda1e3
3 changed files with 30 additions and 2 deletions

View File

@ -28,6 +28,7 @@
#include <common/demangle.h> #include <common/demangle.h>
#include <AggregateFunctions/AggregateFunctionArray.h> #include <AggregateFunctions/AggregateFunctionArray.h>
#include <AggregateFunctions/AggregateFunctionState.h> #include <AggregateFunctions/AggregateFunctionState.h>
#include <AggregateFunctions/AggregateFunctionResample.h>
#include <Disks/StoragePolicy.h> #include <Disks/StoragePolicy.h>
@ -1180,10 +1181,15 @@ Block Aggregator::prepareBlockAndFill(
if (aggregate_functions[i]->isState()) if (aggregate_functions[i]->isState())
{ {
/// The ColumnAggregateFunction column captures the shared ownership of the arena with aggregate function states. /// The ColumnAggregateFunction column captures the shared ownership of the arena with aggregate function states.
ColumnAggregateFunction & column_aggregate_func = assert_cast<ColumnAggregateFunction &>(*final_aggregate_columns[i]); 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<ColumnArray *>(final_aggregate_columns[i].get()))
column_aggregate_func = &assert_cast<ColumnAggregateFunction &>(column_array->getData());
else
column_aggregate_func = &assert_cast<ColumnAggregateFunction &>(*final_aggregate_columns[i]);
for (auto & pool : data_variants.aggregates_pools) for (auto & pool : data_variants.aggregates_pools)
column_aggregate_func.addArena(pool); column_aggregate_func->addArena(pool);
} }
} }
} }

View File

@ -0,0 +1,8 @@
[900,910,920,930,940,950,960,970,980,990,1000,1010,1020,1030,1040,1050,1060,1070,1080,1090]
[900,910,920,930,940,950,960,970,980,990,1000,1010,1020,1030,1040,1050,1060,1070,1080,1090]
[360,243,306,372,252,315,384,261,324,396,270,333,408,279,342,420,288,351,432,297]
[300,364,246,309,376,255,318,388,264,327,400,273,336,412,282,345,424,291,354,436]
[240,303,368,249,312,380,258,321,392,267,330,404,276,339,416,285,348,428,294,357]
[[0,20,40],[1,21,41],[2,22,42],[3,23,43],[4,24,44],[5,25,45],[6,26,46],[7,27,47],[8,28,48],[9,29,49],[10,30],[11,31],[12,32],[13,33],[14,34],[15,35],[16,36],[17,37],[18,38],[19,39]]
[[0,20,40],[1,21,41],[2,22,42],[3,23,43],[4,24,44],[5,25,45],[6,26,46],[7,27,47],[8,28,48],[9,29,49],[10,30],[11,31],[12,32],[13,33],[14,34],[15,35],[16,36],[17,37],[18,38],[19,39]]
[1800,1820,1840,1860,1880,1900,1920,1940,1960,1980,2000,2020,2040,2060,2080,2100,2120,2140,2160,2180]

View File

@ -0,0 +1,14 @@
select sumResample(0, 20, 1)(number, number % 20) from numbers(200);
select arrayMap(x -> finalizeAggregation(x), state) from (select sumStateResample(0, 20, 1)(number, number % 20) as state from numbers(200));
select arrayMap(x -> finalizeAggregation(x), state) from
(
select sumStateResample(0,20,1)(number, number%20) as state from numbers(200) group by number % 3
);
select groupArrayResample(0, 20, 1)(number, number % 20) from numbers(50);
select arrayMap(x -> finalizeAggregation(x), state) from (select groupArrayStateResample(0, 20, 1)(number, number % 20) state from numbers(50));
select arrayMap(x -> finalizeAggregation(x), state) from
(
select sumStateResample(0, 20, 1)(number, number % 20) as state from remote('127.0.0.{1,2}', numbers(200))
);