mustafasrepo commented on code in PR #9469:
URL: https://github.com/apache/arrow-datafusion/pull/9469#discussion_r1516052258


##########
datafusion/physical-plan/src/sorts/partial_sort.rs:
##########
@@ -282,16 +276,31 @@ impl ExecutionPlan for PartialSortExec {
         // Make sure common prefix length is larger than 0
         // Otherwise, we should use SortExec.
         assert!(self.common_prefix_length > 0);
+        let execution_options = &context.session_config().options().execution;
 
-        Ok(Box::pin(PartialSortStream {
-            input,
-            expr: self.expr.clone(),
-            common_prefix_length: self.common_prefix_length,
-            in_mem_batches: vec![],
-            fetch: self.fetch,
-            is_closed: false,
-            baseline_metrics: BaselineMetrics::new(&self.metrics_set, 
partition),
-        }))
+        let mut sorter = crate::sorts::sort::ExternalSorter::new(
+            partition,
+            input.schema(),
+            self.expr.clone(),
+            context.session_config().batch_size(),
+            self.fetch,
+            execution_options.sort_spill_reservation_bytes,
+            execution_options.sort_in_place_threshold_bytes,
+            &self.metrics_set,
+            context.runtime_env(),
+        );
+        let prefix = self.common_prefix_length;
+        Ok(Box::pin(RecordBatchStreamAdapter::new(
+            self.schema(),
+            futures::stream::once(async move {
+                while let Some(batch) = input.next().await {
+                    let batch = batch?;
+                    sorter.insert_batch_with_prefix(batch, prefix).await?;
+                }
+                sorter.sort()

Review Comment:
   > Got it. Thanks! Do you have some suggestions? I think maybe calling 
`sort_in_mem_batches` in the original implementation after 
`insert_batch_with_prefix` each time can solve this, and add the spilling 
function to `sort_in_mem_batches`. 🤔
   
   Not really sure. How to implement it. Unfortunately, I am not super familiar 
with `ExternalSort` code.



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