Skip to content

[Question] Converting TableSource to custom TableProvider #2644

@nevi-me

Description

@nevi-me

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions