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:
lipeh1
2026-11-30 20:18:12 +08:00
committed by GitHub
co-authored by lipeih
parent 2e09dc1144
commit 84e0f53836
11 changed files with 366 additions and 33 deletions
+21
View File
@@ -453,6 +453,27 @@ code that used the former LanceDB Enterprise-only argument order.
::: lancedb.RTEWriteSpec
### Registering a table with DataFusion
With DataFusion Python 55.x installed, register a LanceDB Embedded `Table` or
`AsyncTable` directly with a DataFusion `SessionContext` for SQL reads.
Each new query follows the LanceDB handle's version and
`read_consistency_interval`. The registration uses the table's schema when
registered. Deregister and re-register it after changing its schema.
```python
from datetime import timedelta
import lancedb
from datafusion import SessionContext
db = lancedb.connect("./data", read_consistency_interval=timedelta(0))
table = db.open_table("items")
ctx = SessionContext()
ctx.register_table("items", table)
rows = ctx.sql("SELECT * FROM items").to_arrow_table()
```
## Functions and Jobs
Use `progress=True` when waiting for Function registration in a notebook or