mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
feat(python): register live LanceDB tables with DataFusion (#5203)
Python DataFusion queries over a provider registered from
`table.to_lance()` read a fixed Lance snapshot. An append from another
connection doesn't show up in later queries unless the application
registers a new provider.
Register a LanceDB Embedded `Table` or `AsyncTable` directly with
DataFusion 55.x using `ctx.register_table("items", table)`. The provider
shares the LanceDB table handle, so each new scan follows its read
consistency interval and checked-out version. The provider supports SQL
reads. Re-register after a schema change.
The binding checks the DataFusion FFI major before reading the
consumer's capsule and keeps scan planning and execution on the LanceDB
Tokio runtime. DataFusion remains an optional Python dependency.
Closes #2707.
Validation on Windows x64 with CPython 3.12 and DataFusion 55.0.0:
- Rebuilt the Python extension with the repository's `ci` profile.
- `pytest python/tests/docs/test_guide_tables.py -q`: 6 passed, 2
skipped. The regression covers a second connection writing into a
registered table, both manual and automatic refresh, version pinning,
async table registration, and incompatible DataFusion versions.
- A separate smoke test confirmed refresh with a positive read
consistency interval.
- Cargo formatting, Python Ruff, and Pyright (Linux target) passed.
Co-authored-by: lipeih <lipeihan@eazytec.com>
This commit is contained in:
@@ -44,6 +44,7 @@ use pyo3::{
|
||||
},
|
||||
};
|
||||
|
||||
mod datafusion;
|
||||
mod scannable;
|
||||
|
||||
/// Keyword arguments shared by `refresh_column` and `refresh_column_async`.
|
||||
@@ -1576,6 +1577,14 @@ impl Table {
|
||||
Python::attach(|py| schema.to_pyarrow(py).map(|obj| obj.unbind()))
|
||||
}
|
||||
|
||||
fn __datafusion_table_provider__<'py>(
|
||||
&self,
|
||||
py: Python<'py>,
|
||||
session: Bound<'py, PyAny>,
|
||||
) -> PyResult<Bound<'py, pyo3::types::PyCapsule>> {
|
||||
datafusion::table_provider(py, self.inner_ref()?, session)
|
||||
}
|
||||
|
||||
#[pyo3(signature = (data, mode, progress=None, write_parallelism=None, allow_external_blob_outside_bases=false, retries=None))]
|
||||
pub fn add<'a>(
|
||||
self_: PyRef<'a, Self>,
|
||||
|
||||
Reference in New Issue
Block a user