Skip to content

Commit c0a5770

Browse files
committed
Add example to demonstrate failure of table UDTFs due to missing __datafusion_table_provider__
1 parent 802b984 commit c0a5770

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/table_capsule_failure.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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()

0 commit comments

Comments
 (0)