mohitgurav20 commented on code in PR #27196:
URL: https://github.com/apache/datafusion/pull/27196#discussion_r4732218614


##########
datafusion/physical-plan/src/aggregates/order/partial.rs:
##########
@@ -346,4 +345,41 @@ mod tests {
 
         Ok(())
     }
+
+    #[test]
+    fn heap_size_counts_retained_sort_key_capacity() -> Result<()> {
+        // An in-progress sort key with spare capacity and a heap-owning 
scalar.
+        let mut group_key = Vec::with_capacity(4);
+        let key = String::from("retained sort key");
+        let key_capacity = key.capacity();
+        group_key.push(ScalarValue::Utf8(Some(key)));
+        let group_key_capacity = group_key.capacity();
+        assert!(group_key_capacity > group_key.len());
+
+        let mut grouping_indices = Vec::with_capacity(8);
+        grouping_indices.push(0);
+        let grouping_indices_capacity = grouping_indices.capacity();
+
+        let mut partial = GroupClusteringPartial::try_new(grouping_indices)?;
+        partial.state = State::InProgress {
+            current_run_start: 0,
+            group_key,
+            current: 0,
+        };
+
+        // Every scalar slot, including the spare ones, is charged; the
+        // scalar's own heap payload is charged on top of its slot.
+        let expected = grouping_indices_capacity * size_of::<usize>()
+            + group_key_capacity * size_of::<ScalarValue>()
+            + key_capacity;
+        assert_eq!(partial.heap_size(), expected);
+
+        // Accounting only the live element would miss the spare slots.

Review Comment:
   Dropped the live_only check as suggested—agreed the exact equality check 
already covers both directions.



-- 
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