2010YOUY01 commented on code in PR #14823:
URL: https://github.com/apache/datafusion/pull/14823#discussion_r1966660694


##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -446,21 +511,9 @@ impl ExternalSorter {
                 None => {
                     let sorted_size = 
get_reserved_byte_for_record_batch(&batch);
                     if self.reservation.try_grow(sorted_size).is_err() {
-                        // Directly write in_mem_batches as well as all the 
remaining batches in
-                        // sorted_stream to disk. Further batches fetched from 
`sorted_stream` will
-                        // be handled by the `Some(writer)` matching arm.
-                        let spill_file =
-                            
self.runtime.disk_manager.create_tmp_file("Sorting")?;
-                        let mut writer = IPCWriter::new(spill_file.path(), 
&self.schema)?;
-                        // Flush everything in memory to the spill file
-                        for batch in self.in_mem_batches.drain(..) {
-                            writer.write(&batch)?;
-                        }
-                        // as well as the newly sorted batch
-                        writer.write(&batch)?;
-                        spill_writer = Some(writer);
+                        self.in_mem_batches.push(batch);
+                        self.spill().await?;

Review Comment:
   `in_mem_batches` is a `Vec<RecordBatch>`, so it doesn't have any internal 
mechanism to update reservation. Also, the new `batch` is already in memory, so 
there is no difference to spill together or not. I added a comment for this.
   Besides, I think manually keep the buffered batch in sync with reservation 
is quite tricky, it makes the implementation hard to reason and perhaps cause 
bugs, hopefully we can find a RAII way to improve it in the future.



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to