andygrove commented on a change in pull request #7958:
URL: https://github.com/apache/arrow/pull/7958#discussion_r470182854
##########
File path: rust/datafusion/src/execution/physical_plan/limit.rs
##########
@@ -81,39 +82,40 @@ struct LimitPartition {
impl Partition for LimitPartition {
fn execute(&self) -> Result<Arc<Mutex<dyn RecordBatchReader + Send +
Sync>>> {
- // collect up to "limit" rows on each partition
- let threads: Vec<JoinHandle<Result<Vec<RecordBatch>>>> = self
+ // apply limit in parallel across all input partitions
+ let local_limit = self
.partitions
.iter()
.map(|p| {
- let p = p.clone();
- let limit = self.limit;
- thread::spawn(move || {
- let it = p.execute()?;
- collect_with_limit(it, limit)
- })
+ Arc::new(LocalLimitExec::new(
+ p.clone(),
+ self.schema.clone(),
+ self.limit,
+ )) as Arc<dyn Partition>
})
.collect();
- // combine the results from each thread, up to the limit
+ // limit needs to collapse inputs down to a single partition
+ let merge = MergeExec::new(self.schema.clone(), local_limit);
+ // MergeExec has a single partition
+ let it = merge.partitions()?[0].execute()?;
Review comment:
I was wondering about this too. I'll add that.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]