Skip to content

Commit 1edcd20

Browse files
committed
add downcast_delegate
1 parent 08da279 commit 1edcd20

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

datafusion/datasource/src/source.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ use datafusion_physical_plan::filter_pushdown::{
123123
/// └─────────────────────┘
124124
/// ```
125125
pub trait DataSource: Any + Send + Sync + Debug {
126+
/// Optionally delegates downcast identity to an inner [`DataSource`].
127+
///
128+
/// Wrapper types (e.g. a partitioning adapter that wraps a [`FileScanConfig`])
129+
/// can implement this to make `is` and `downcast_ref` transparently see
130+
/// through to the inner source, exactly as [`ExecutionPlan::downcast_delegate`]
131+
/// does for execution plans.
132+
///
133+
/// Implementations should return the inner source, not `self`.
134+
fn downcast_delegate(&self) -> Option<&dyn DataSource> {
135+
None
136+
}
137+
126138
/// Open the specified output partition and return its stream of
127139
/// [`RecordBatch`]es.
128140
///
@@ -292,11 +304,17 @@ impl OpenArgs {
292304

293305
impl dyn DataSource {
294306
pub fn is<T: DataSource>(&self) -> bool {
295-
(self as &dyn Any).is::<T>()
307+
match self.downcast_delegate() {
308+
Some(delegate) => delegate.is::<T>(),
309+
None => (self as &dyn Any).is::<T>(),
310+
}
296311
}
297312

298313
pub fn downcast_ref<T: DataSource>(&self) -> Option<&T> {
299-
(self as &dyn Any).downcast_ref()
314+
match self.downcast_delegate() {
315+
Some(delegate) => delegate.downcast_ref::<T>(),
316+
None => (self as &dyn Any).downcast_ref(),
317+
}
300318
}
301319
}
302320

0 commit comments

Comments
 (0)