Skip to content
Merged
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
28 changes: 28 additions & 0 deletions datafusion/datasource/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ pub trait DataSource: Send + Sync + Debug {
) -> Result<SortOrderPushdownResult<Arc<dyn DataSource>>> {
Ok(SortOrderPushdownResult::Unsupported)
}

/// Injects arbitrary run-time state into this DataSource, returning a new instance
/// that incorporates that state *if* it is relevant to the concrete DataSource implementation.
///
/// This is a generic entry point: the `state` can be any type wrapped in
/// `Arc<dyn Any + Send + Sync>`. A data source that cares about the state should
/// down-cast it to the concrete type it expects and, if successful, return a
/// modified copy of itself that captures the provided value. If the state is
/// not applicable, the default behaviour is to return `None` so that parent
/// nodes can continue propagating the attempt further down the plan tree.
fn with_new_state(
&self,
_state: Arc<dyn Any + Send + Sync>,
) -> Option<Arc<dyn DataSource>> {
None
}
}

/// [`ExecutionPlan`] that reads one or more files
Expand Down Expand Up @@ -393,6 +409,18 @@ impl ExecutionPlan for DataSourceExec {
Ok(Arc::new(new_exec) as Arc<dyn ExecutionPlan>)
})
}

fn with_new_state(
&self,
state: Arc<dyn Any + Send + Sync>,
) -> Option<Arc<dyn ExecutionPlan>> {
self.data_source
.with_new_state(state)
.map(|new_data_source| {
Arc::new(self.clone().with_data_source(new_data_source))
as Arc<dyn ExecutionPlan>
})
}
}

impl DataSourceExec {
Expand Down