Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions velox/functions/prestosql/aggregates/MapAccumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once

#include <folly/container/F14Map.h>
#include <folly/container/Reserve.h>
#include "velox/common/memory/HashStringAllocator.h"
#include "velox/exec/AddressableNonNullValueList.h"
#include "velox/exec/Strings.h"
Expand Down Expand Up @@ -66,6 +67,10 @@ struct MapAccumulator {
}
}

void reserveAdditional(size_t n) {
folly::grow_capacity_by(keys, n);
}

/// Returns number of key-value pairs.
size_t size() const {
return keys.size();
Expand Down Expand Up @@ -140,6 +145,10 @@ struct StringViewMapAccumulator {
}
}

void reserveAdditional(size_t n) {
base.reserveAdditional(n);
}

size_t size() const {
return base.size();
}
Expand Down Expand Up @@ -191,6 +200,10 @@ struct ComplexTypeMapAccumulator {
base.values.appendValue(decodedValues, index, &allocator);
}

void reserveAdditional(size_t n) {
base.reserveAdditional(n);
}

size_t size() const {
return base.size();
}
Expand Down Expand Up @@ -303,6 +316,10 @@ struct CustomComparisonMapAccumulator {
return base.insert(decodedKeys, decodedValues, index, allocator);
}

void reserveAdditional(size_t n) {
base.reserveAdditional(n);
}

/// Returns number of key-value pairs.
size_t size() const {
return base.size();
Expand Down
2 changes: 2 additions & 0 deletions velox/functions/prestosql/aggregates/MapAggregateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class MapAggregateBase : public exec::Aggregate {
auto size = mapVector->sizeAt(decodedRow);
auto tracker = trackRowSize(group);
checkNullKeys(decodedKeys_, offset, size);
accumulator->reserveAdditional(size);
for (auto i = offset; i < offset + size; ++i) {
accumulator->insert(decodedKeys_, decodedValues_, i, *allocator_);
}
Expand Down Expand Up @@ -178,6 +179,7 @@ class MapAggregateBase : public exec::Aggregate {
auto offset = mapVector->offsetAt(decodedRow);
auto size = mapVector->sizeAt(decodedRow);
checkNullKeys(decodedKeys_, offset, size);
accumulator->reserveAdditional(size);
for (auto i = offset; i < offset + size; ++i) {
accumulator->insert(decodedKeys_, decodedValues_, i, *allocator_);
}
Expand Down
Loading