yyy1000 commented on code in PR #9469:
URL: https://github.com/apache/arrow-datafusion/pull/9469#discussion_r1516348574
##########
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:
Yeah, thanks for your info.
I think in this PR, PartialSort can also reduce memory usage. It also emits
data chunk by chunk but return a merge stream at last. Let's see what others
view this.
--
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]