Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Add documentation about stream cancellation #8747

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions datafusion/core/src/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ impl DataFrame {

/// Executes this DataFrame and returns a stream over a single partition
///
/// # Example
/// ```
/// # use datafusion::prelude::*;
/// # use datafusion::error::Result;
Expand All @@ -813,6 +814,11 @@ impl DataFrame {
/// # Ok(())
/// # }
/// ```
///
/// # Aborting Execution
///
/// Dropping the stream will abort the execution of the query, and free up
/// any allocated resources
pub async fn execute_stream(self) -> Result<SendableRecordBatchStream> {
let task_ctx = Arc::new(self.task_ctx());
let plan = self.create_physical_plan().await?;
Expand Down Expand Up @@ -841,6 +847,7 @@ impl DataFrame {

/// Executes this DataFrame and returns one stream per partition.
///
/// # Example
/// ```
/// # use datafusion::prelude::*;
/// # use datafusion::error::Result;
Expand All @@ -852,6 +859,10 @@ impl DataFrame {
/// # Ok(())
/// # }
/// ```
/// # Aborting Execution
///
/// Dropping the stream will abort the execution of the query, and free up
/// any allocated resources
pub async fn execute_stream_partitioned(
self,
) -> Result<Vec<SendableRecordBatchStream>> {
Expand Down
33 changes: 31 additions & 2 deletions datafusion/physical-plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,24 @@ pub trait ExecutionPlan: Debug + DisplayAs + Send + Sync {
/// [`TryStreamExt`]: futures::stream::TryStreamExt
/// [`RecordBatchStreamAdapter`]: crate::stream::RecordBatchStreamAdapter
///
/// # Cancellation / Aborting Execution
///
/// The [`Stream`] that is returned must ensure that any allocated resources
/// are freed when the stream itself is dropped. This is particularly
/// important for [`spawn`]ed tasks or threads. Unless care is taken to
/// "abort" such tasks, they may continue to consume resources even after
/// the plan is dropped, generating intermediate results that are never
/// used.
///
/// See [`AbortOnDropSingle`], [`AbortOnDropMany`] and
/// [`RecordBatchReceiverStreamBuilder`] for structures to help ensure all
/// background tasks are cancelled.
///
/// [`spawn`]: tokio::task::spawn
/// [`AbortOnDropSingle`]: crate::common::AbortOnDropSingle
/// [`AbortOnDropMany`]: crate::common::AbortOnDropMany
/// [`RecordBatchReceiverStreamBuilder`]: crate::stream::RecordBatchReceiverStreamBuilder
///
/// # Implementation Examples
///
/// While `async` `Stream`s have a non trivial learning curve, the
Expand Down Expand Up @@ -491,7 +509,12 @@ pub async fn collect(
common::collect(stream).await
}

/// Execute the [ExecutionPlan] and return a single stream of results
/// Execute the [ExecutionPlan] and return a single stream of results.
///
/// # Aborting Execution
///
/// Dropping the stream will abort the execution of the query, and free up
/// any allocated resources
pub fn execute_stream(
plan: Arc<dyn ExecutionPlan>,
context: Arc<TaskContext>,
Expand Down Expand Up @@ -549,7 +572,13 @@ pub async fn collect_partitioned(
Ok(batches)
}

/// Execute the [ExecutionPlan] and return a vec with one stream per output partition
/// Execute the [ExecutionPlan] and return a vec with one stream per output
/// partition
///
/// # Aborting Execution
///
/// Dropping the stream will abort the execution of the query, and free up
/// any allocated resources
pub fn execute_stream_partitioned(
plan: Arc<dyn ExecutionPlan>,
context: Arc<TaskContext>,
Expand Down