File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ """Demonstrate how missing __datafusion_table_provider__ breaks table UDTFs.
2+
3+ Run with ``python examples/table_capsule_failure.py``.
4+
5+ This example mirrors how advanced integrations unwrap ``Table`` instances via the
6+ ``__datafusion_table_provider__`` PyCapsule. The refactor that removed this method
7+ means user-defined table functions returning ``Table`` now raise ``NotImplementedError``.
8+ """
9+
10+ from __future__ import annotations
11+
12+ from datafusion import SessionContext , Table , udtf
13+
14+
15+ def main () -> None :
16+ """Register a Python table UDTF that returns a ``Table`` and trigger it."""
17+
18+ ctx = SessionContext ()
19+
20+ @udtf ("capsule_dependent" )
21+ def capsule_dependent_udtf () -> Table :
22+ """Return a ``Table`` so DataFusion unwraps it via the FFI capsule."""
23+
24+ # Prior to the refactor the wrapper exposed ``__datafusion_table_provider__``
25+ # so this conversion succeeded. Without it the runtime raises a
26+ # ``NotImplementedError`` complaining about the missing attribute.
27+ return Table (ctx .sql ("SELECT 1 AS value" ))
28+
29+ ctx .register_udtf (capsule_dependent_udtf )
30+
31+ # Executing the UDTF now fails because ``Table`` no longer exposes the
32+ # ``__datafusion_table_provider__`` helper that PyTableFunction expects.
33+ ctx .sql ("SELECT * FROM capsule_dependent()" ).collect ()
34+
35+
36+ if __name__ == "__main__" :
37+ main ()
You can’t perform that action at this time.
0 commit comments