Merge pull request #18818 from templarzq/master

Implement ColumnAggregateFunction cloneResized method
This commit is contained in:
alexey-milovidov 2021-01-15 13:21:21 +03:00 committed by GitHub
commit e914ef619f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 2 deletions

View File

@ -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<ColumnAggregateFunction *>(cloned_col.get());
res->insertRangeFrom(*this, 0, from_size);
for (size_t i = from_size; i < size; ++i)
res->insertDefault();
return cloned_col;
}
}
}

View File

@ -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;
};
}

View File

@ -0,0 +1 @@
1 1

View File

@ -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;

View File

@ -183,3 +183,4 @@
01636_nullable_fuzz2
01639_distributed_sync_insert_zero_rows
01644_distributed_async_insert_fsync_smoke
01552_impl_aggfunc_cloneresize