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

Add foreign table providers #921

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Conversation

timsaucer
Copy link
Contributor

@timsaucer timsaucer commented Oct 14, 2024

Which issue does this PR close?

Closes #823
Closes #941

Rationale for this change

This feature enables DataFusion python to interoperate with foreign table providers that implement TableProvider and expose it via PyCapsule

What changes are included in this PR?

Adds a feature to register a table provider in the session context.

Are there any user-facing changes?

Addition only, no existing APIs modified.

pub fn register_table_provider(
&mut self,
name: &str,
provider: Bound<'_, PyAny>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to understand, taking delta-rs as an example.

The provider would be an instance of a deltatable object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is what you would need to implement in delta-rs as a python method on RawDeltaTable

    fn __datafusion_table_provider__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyCapsule>> {
        let name = CString::new("datafusion_table_provider").unwrap();
        let provider = FFI_TableProvider::new(Arc::new(self._table.clone()));
        PyCapsule::new_bound(py, provider, Some(name.clone()))
    }

Does that answer the question?

provider: Bound<'_, PyAny>,
py: Python,
) -> PyResult<()> {
if provider.hasattr("__datafusion_table_provider__")? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise when it doesn't have this attribute, it might give the wrong impression for users that they registered it but nothing happened

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Added.

@timsaucer
Copy link
Contributor Author

Now that 43.0.0 has merged into main, I've rebased and I'll work next on adding example and unit tests.

@timsaucer timsaucer marked this pull request as ready for review November 11, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for a custom table provider Expose API to register a foreign TableProvider
2 participants