-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
When registering a custom TableProvider, the provider gets converted to a dyn TableSource during logical planning. When executing the plan, the source is cast back to a provider using source_to_provider.
/// Attempt to downcast a TableSource to DefaultTableSource and access the
/// TableProvider. This will only work with a TableSource created by DataFusion.
pub fn source_as_provider(
source: &Arc<dyn TableSource>,
) -> datafusion_common::Result<Arc<dyn TableProvider>> {
match source
.as_ref()
.as_any()
.downcast_ref::<DefaultTableSource>()
{
Some(source) => Ok(source.table_provider.clone()),
_ => Err(DataFusionError::Internal(
"TableSource was not DefaultTableSource".to_string(),
)),
}
}When executing the physical plan, the custom TableProvider was previously used to scan() and return data. So the above function doesn't work as it only works with a DefaultTableSource.
It's unclear how I can avoid this by replacing with a custom call that'd return my custom table provider. How can I achieve this?
For context, I have the repo https://github.com/nevi-me/datafusion-rdbms-ext which has a PostgresTableProvider. It used to work before the recent changes to add a TableSource, but now I'm stuck and I can't figure out an upgrade path.
CC @andygrove re the TableSource change.
I'm looking in some repos that use DataFusion, but haven't found something yet.