You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/07/09 15:02:19 UTC
(datafusion) 01/01: Fix memory size accounting for grouped `median` and `avg` (#23357)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-23357-059be71a50f805a7ed9bc4b08236210ddaa69f43
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit 73d5d7803ba1bbea757fe6591371655d0d73875b
Author: linfeng <33...@users.noreply.github.com>
AuthorDate: Thu Jul 9 23:01:53 2026 +0800
Fix memory size accounting for grouped `median` and `avg` (#23357)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
`AvgGroupsAccumulator` stores sums in `Vec<T::Native>`, and
`MedianGroupsAccumulator` stores grouped values in
`Vec<Vec<T::Native>>`, but their `size()` implementations used
`size_of::<T>()` when accounting for those allocations.
This underreports memory usage for those grouped aggregate buffers.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
- Use `size_of::<T::Native>()` for grouped `avg` sum storage.
- Use `size_of::<T::Native>()` for grouped `median` value storage.
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Existing aggregate tests pass.
## Are there any user-facing changes?
No. This only affects internal memory accounting.
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
---------
Co-authored-by: Oleks V <co...@users.noreply.github.com>
---
datafusion/functions-aggregate/src/average.rs | 9 ++++++++-
datafusion/functions-aggregate/src/median.rs | 7 ++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/datafusion/functions-aggregate/src/average.rs b/datafusion/functions-aggregate/src/average.rs
index 06c7694634..278a861de2 100644
--- a/datafusion/functions-aggregate/src/average.rs
+++ b/datafusion/functions-aggregate/src/average.rs
@@ -970,6 +970,13 @@ where
}
fn size(&self) -> usize {
- self.counts.capacity() * size_of::<u64>() + self.sums.capacity() * size_of::<T>()
+ // Heap buffers
+ self.counts.capacity() * size_of::<u64>()
+ + self.sums.capacity() * size_of::<T::Native>()
+ // Vec struct overhead (ptr, len, cap) for each field
+ + size_of::<Vec<u64>>()
+ + size_of::<Vec<T::Native>>()
+ // Null tracking buffers
+ + self.null_state.size()
}
}
diff --git a/datafusion/functions-aggregate/src/median.rs b/datafusion/functions-aggregate/src/median.rs
index 4a0da10f51..9a6ef3e7e5 100644
--- a/datafusion/functions-aggregate/src/median.rs
+++ b/datafusion/functions-aggregate/src/median.rs
@@ -543,10 +543,11 @@ impl<T: ArrowNumericType + Send> GroupsAccumulator for MedianGroupsAccumulator<T
fn size(&self) -> usize {
self.group_values
.iter()
- .map(|values| values.capacity() * size_of::<T>())
+ .map(|values| values.capacity() * size_of::<T::Native>())
.sum::<usize>()
- // account for size of self.grou_values too
- + self.group_values.capacity() * size_of::<Vec<T>>()
+ // account for size of self.group_values too
+ + self.group_values.capacity() * size_of::<Vec<T::Native>>()
+ + size_of::<Vec<Vec<T::Native>>>()
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org