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 run the execution to completion, and then discard everything but the
first error if any
##########
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 run the execution to completion, and then discard everything but
the first error if any
--
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]