LiaCastaneda commented on code in PR #19501:
URL: https://github.com/apache/datafusion/pull/19501#discussion_r2655376608


##########
datafusion/functions-aggregate/src/array_agg.rs:
##########
@@ -518,13 +518,29 @@ impl Accumulator for DistinctArrayAggAccumulator {
         Ok(ScalarValue::List(arr))
     }
 
-    fn size(&self) -> usize {
-        size_of_val(self) + ScalarValue::size_of_hashset(&self.values)
-            - size_of_val(&self.values)
+    fn size(&self, pool: Option<&dyn MemoryPool>) -> usize {
+        let mut total = size_of_val(self)
+            + size_of_val(&self.values)
+            + (size_of::<ScalarValue>() * self.values.capacity())
             + self.datatype.size()
             - size_of_val(&self.datatype)
             - size_of_val(&self.sort_options)
-            + size_of::<Option<SortOptions>>()
+            + size_of::<Option<SortOptions>>();
+
+        for scalar in &self.values {
+            if let Some(array) = scalar.get_array_ref() {
+                total += size_of::<Arc<dyn Array>>();
+                if let Some(pool) = pool {
+                    claim_buffers_recursive(&array.to_data(), pool);

Review Comment:
   Yes, that's why after calling size() we add arrow_pool.used() to account for 
the buffer memory (I forgot to add it). I also considered calling 
arrow_pool.used() directly inside each accumulator's size() function so the 
caller doesn't have to remember to do it. However, that would still cause 
over-accounting in scenarios like `update_memory_reservation()` where we sum 
size() across multiple accumulators since they can share buffers as well:
   
   ```
           let total_size = self.group_values.size()
               + self.group_ordering.size()
               + self.current_group_indices.capacity() * size_of::<usize>()
               + self
                   .accumulators
                   .iter()
                   .map(|x| x.size(Some(&self.arrow_pool)))
                   .sum::<usize>() <--- If each size() returned 
arrow_pool.used() we would still be over counting the pool 
   ```
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to