diff --git a/src/Columns/ColumnAggregateFunction.cpp b/src/Columns/ColumnAggregateFunction.cpp index 51dada0780b..d0a5e120a07 100644 --- a/src/Columns/ColumnAggregateFunction.cpp +++ b/src/Columns/ColumnAggregateFunction.cpp @@ -670,4 +670,32 @@ ColumnAggregateFunction::ColumnAggregateFunction(const ColumnAggregateFunction & { } +MutableColumnPtr ColumnAggregateFunction::cloneResized(size_t size) const +{ + if (size == 0) + return cloneEmpty(); + + size_t from_size = data.size(); + + if (size <= from_size) + { + auto res = createView(); + auto & res_data = res->data; + res_data.assign(data.begin(), data.begin() + size); + return res; + } + else + { + /// Create a new column to return. + MutableColumnPtr cloned_col = cloneEmpty(); + auto * res = typeid_cast(cloned_col.get()); + + res->insertRangeFrom(*this, 0, from_size); + for (size_t i = from_size; i < size; ++i) + res->insertDefault(); + + return cloned_col; + } +} + } diff --git a/src/Columns/ColumnAggregateFunction.h b/src/Columns/ColumnAggregateFunction.h index 13bc40c56b1..cd45cf583a0 100644 --- a/src/Columns/ColumnAggregateFunction.h +++ b/src/Columns/ColumnAggregateFunction.h @@ -215,7 +215,7 @@ public: void getExtremes(Field & min, Field & max) const override; bool structureEquals(const IColumn &) const override; + + MutableColumnPtr cloneResized(size_t size) const override; }; - - } diff --git a/tests/queries/0_stateless/01552_impl_aggfunc_cloneresize.reference b/tests/queries/0_stateless/01552_impl_aggfunc_cloneresize.reference new file mode 100644 index 00000000000..9972842f982 --- /dev/null +++ b/tests/queries/0_stateless/01552_impl_aggfunc_cloneresize.reference @@ -0,0 +1 @@ +1 1 diff --git a/tests/queries/0_stateless/01552_impl_aggfunc_cloneresize.sql b/tests/queries/0_stateless/01552_impl_aggfunc_cloneresize.sql new file mode 100644 index 00000000000..849a4378e45 --- /dev/null +++ b/tests/queries/0_stateless/01552_impl_aggfunc_cloneresize.sql @@ -0,0 +1,57 @@ +drop table if EXISTS test_bm; + +drop table if EXISTS test_bm_join; + +create table test_bm( + dim UInt64, + id UInt64 ) +ENGINE = MergeTree() +ORDER BY( dim, id ) +SETTINGS index_granularity = 8192; + +create table test_bm_join( + dim UInt64, + id UInt64 ) +ENGINE = MergeTree() +ORDER BY(dim,id) +SETTINGS index_granularity = 8192; + +insert into test_bm VALUES (1,1),(2,2),(3,3),(4,4); + +select + dim , + sum(idnum) +from + test_bm_join +right join( + select + dim, + bitmapOrCardinality(ids,ids2) as idnum + from + ( + select + dim, + groupBitmapState(toUInt64(id)) as ids + FROM + test_bm + where + dim >2 + group by + dim ) A all + right join ( + select + dim, + groupBitmapState(toUInt64(id)) as ids2 + FROM + test_bm + where + dim < 2 + group by + dim ) B + using(dim) ) C +using(dim) +group by dim; + +drop table test_bm; + +drop table test_bm_join; diff --git a/tests/queries/0_stateless/arcadia_skip_list.txt b/tests/queries/0_stateless/arcadia_skip_list.txt index a4507555373..116d0beb80b 100644 --- a/tests/queries/0_stateless/arcadia_skip_list.txt +++ b/tests/queries/0_stateless/arcadia_skip_list.txt @@ -183,3 +183,4 @@ 01636_nullable_fuzz2 01639_distributed_sync_insert_zero_rows 01644_distributed_async_insert_fsync_smoke +01552_impl_aggfunc_cloneresize