| 952 | table_->decideHashMode(0, true); |
| 953 | } |
| 954 | return pool_.currentBytes() > maxBytes; |
| 955 | } |
| 956 | |
| 957 | uint64_t GroupingSet::allocatedBytes() const { |
| 958 | if (table_) { |
| 959 | return table_->allocatedBytes(); |
| 960 | } |
| 961 | |
| 962 | return stringAllocator_.retainedSize() + rows_.allocatedBytes(); |
| 963 | } |
| 964 | |
| 965 | const HashLookup& GroupingSet::hashLookup() const { |
| 966 | return *lookup_; |
| 967 | } |
| 968 | |
| 969 | void GroupingSet::ensureInputFits(const RowVectorPtr& input) { |
| 970 | // Spilling is considered if this is a partial(prefer) or a final or single |
| 971 | // aggregation and spillPath is set. |
| 972 | if ((isPartial_ && preferPartialSpill_ == false) || spillConfig_ == nullptr) { |
| 973 | return; |
| 974 | } |
| 975 | |
| 976 | const auto numDistinct = table_->numDistinct(); |
| 977 | if (numDistinct == 0) { |
| 978 | // Table is empty. Nothing to spill. |
| 979 | return; |
| 980 | } |
| 981 | |
| 982 | auto* rows = table_->rows(); |
| 983 | auto [freeRows, outOfLineFreeBytes] = rows->freeSpace(); |
| 984 | const auto outOfLineBytes = |
| 985 | rows->stringAllocator().retainedSize() - outOfLineFreeBytes; |
| 986 | const auto outOfLineBytesPerRow = outOfLineBytes / numDistinct; |
| 987 | const int64_t flatBytes = input->usedSize(); |
| 988 | |
| 989 | // Test-only spill path. |
| 990 | if (spillConfig_->testSpillPct > 0 && |
| 991 | (folly::hasher<uint64_t>()(++spillTestCounter_)) % 100 <= |
| 992 | spillConfig_->testSpillPct) { |
| 993 | spill(); |
| 994 | return; |
| 995 | } |
| 996 | |
| 997 | const auto currentUsage = pool_.currentBytes(); |
| 998 | if (spillMemoryThreshold_ != 0 && currentUsage > spillMemoryThreshold_) { |
| 999 | spill(); |
| 1000 | return; |
| 1001 | } |
| 1002 | |
| 1003 | const auto minReservationBytes = |
| 1004 | currentUsage * spillConfig_->minSpillableReservationPct / 100; |
| 1005 | const auto availableReservationBytes = pool_.availableReservation(); |
| 1006 | const auto tableIncrementBytes = table_->hashTableSizeIncrease(input->size()); |
| 1007 | const auto incrementBytes = |
| 1008 | rows->sizeIncrement(input->size(), outOfLineBytes ? flatBytes * 2 : 0) + |
| 1009 | tableIncrementBytes; |
| 1010 | |
| 1011 | // First to check if we have sufficient minimal memory reservation. |
nothing calls this directly
no test coverage detected