You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/04/24 19:03:35 UTC

[GitHub] [arrow-datafusion] tustvold commented on a diff in pull request #6109: Parallelise collect_partitioned

tustvold commented on code in PR #6109:
URL: https://github.com/apache/arrow-datafusion/pull/6109#discussion_r1175678075


##########
datafusion/core/src/physical_plan/mod.rs:
##########
@@ -443,11 +443,21 @@ pub async fn collect_partitioned(
     context: Arc<TaskContext>,
 ) -> Result<Vec<Vec<RecordBatch>>> {
     let streams = execute_stream_partitioned(plan, context)?;
-    let mut batches = Vec::with_capacity(streams.len());
-    for stream in streams {
-        batches.push(common::collect(stream).await?);
-    }
-    Ok(batches)
+
+    // Execute the plan and collect the results into batches.
+    let handles = streams
+        .into_iter()
+        .enumerate()
+        .map(|(idx, stream)| async move {
+            let handle = tokio::task::spawn(stream.try_collect());
+            AbortOnDropSingle::new(handle).await.map_err(|e| {
+                DataFusionError::Execution(format!(
+                    "collect_partitioned partition {idx} panicked: {e}"
+                ))
+            })?
+        });
+
+    futures::future::try_join_all(handles).await

Review Comment:
   Using try_join_all will abort on first error as opposed to `join_all` which would collect them all and then discard all but the first



-- 
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-unsubscribe@arrow.apache.org

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