yjshen commented on code in PR #7400:
URL: https://github.com/apache/arrow-datafusion/pull/7400#discussion_r1326320895


##########
datafusion/core/src/physical_plan/aggregates/row_hash.rs:
##########
@@ -56,6 +65,28 @@ pub(crate) enum ExecutionState {
 use super::order::GroupOrdering;
 use super::AggregateExec;
 
+/// This encapsulates the spilling state
+struct SpillState {
+    /// If data has previously been spilled, the locations of the
+    /// spill files (in Arrow IPC format)
+    spills: Vec<NamedTempFile>,

Review Comment:
   It's merged now.



##########
datafusion/core/src/physical_plan/aggregates/row_hash.rs:
##########
@@ -318,9 +433,12 @@ impl Stream for GroupedHashAggregateStream {
                             assert!(!self.input_done);
 
                             if let Some(to_emit) = 
self.group_ordering.emit_to() {
-                                let batch = extract_ok!(self.emit(to_emit));
+                                let batch = extract_ok!(self.emit(to_emit, 
false));
                                 self.exec_state = 
ExecutionState::ProducingOutput(batch);
                             }
+
+                            extract_ok!(self.emit_early_if_necessary());

Review Comment:
   There are some common `if` conditions in `spill_previous_if_necessary` and 
`emit_early_if_necessary`, I'm wondering if extracting these conditions to this 
outer scope will make the logic here easier to follow:
   
   ```rs
   if matches!(self.group_ordering, GroupOrdering::None) {
      let memory_full = self.update_memory_reservation().is_err();
      if (memory_full) {
         if (matches!(self.mode, Partial)) {
             emit_early()
         } else {
             spill()
         }
      }
   } else {
    // TODO support spilling for group_ordering
   }
   
   ```



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

Reply via email to