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


##########
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:
   Our original aim in the `PartialSortExec` was to produce streaming results 
when existing ordering and required ordering has a common prefix ordering. If 
that is the case, `PartialSortExec` can produce result chunk by chunk (e.g not 
as a single bulk). In this code snippet data is fed to chunk by chunk. However, 
`.sort` is called once, at the end after `while` loop ends. For this reason, 
data is produced still produced as a single bulk.
   
   I think this is the reason why existing test fails in this implementation



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