mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-11 18:14:03 +00:00
AggregateFunctionSumMap: compact keys with zero value
This allows `sumMap(k, v)` to compact all keys for which the values are all zero.
This commit is contained in:
parent
65982a1642
commit
fa098b469c
@ -198,7 +198,27 @@ public:
|
|||||||
|
|
||||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||||
{
|
{
|
||||||
const auto & merged_maps = this->data(place).merged_maps;
|
// Final step does compaction of keys that have zero values, this mutates the state
|
||||||
|
auto & merged_maps = this->data(const_cast<AggregateDataPtr>(place)).merged_maps;
|
||||||
|
for (auto it = merged_maps.cbegin(); it != merged_maps.cend();)
|
||||||
|
{
|
||||||
|
// Key is not compacted if it has at least one non-zero value
|
||||||
|
bool erase = true;
|
||||||
|
for (size_t col = 0; col < values_types.size(); ++col)
|
||||||
|
{
|
||||||
|
if (it->second[col] != values_types[col]->getDefault())
|
||||||
|
{
|
||||||
|
erase = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (erase)
|
||||||
|
it = merged_maps.erase(it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = merged_maps.size();
|
size_t size = merged_maps.size();
|
||||||
|
|
||||||
auto & to_cols = static_cast<ColumnTuple &>(to).getColumns();
|
auto & to_cols = static_cast<ColumnTuple &>(to).getColumns();
|
||||||
|
Loading…
Reference in New Issue
Block a user