Skip to content

Commit af1eb8a

Browse files
committed
fix: enhance error handling for missing __datafusion_table_provider__ in UDTF example
1 parent 48ac12e commit af1eb8a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

examples/table_capsule_failure.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
55
This example mirrors how advanced integrations unwrap ``Table`` instances via the
66
``__datafusion_table_provider__`` PyCapsule. The refactor that removed this method
7-
means user-defined table functions returning ``Table`` now raise ``NotImplementedError``.
7+
means user-defined table functions returning ``Table`` now raise ``NotImplementedError``
8+
and the script prints the resulting error message instead of crashing.
89
"""
910

1011
from __future__ import annotations
@@ -16,6 +17,7 @@ def main() -> None:
1617
"""Register a Python table UDTF that returns a ``Table`` and trigger it."""
1718

1819
ctx = SessionContext()
20+
failing_table = Table(ctx.sql("SELECT 1 AS value"))
1921

2022
@udtf("capsule_dependent")
2123
def capsule_dependent_udtf() -> Table:
@@ -24,13 +26,21 @@ def capsule_dependent_udtf() -> Table:
2426
# Prior to the refactor the wrapper exposed ``__datafusion_table_provider__``
2527
# so this conversion succeeded. Without it the runtime raises a
2628
# ``NotImplementedError`` complaining about the missing attribute.
27-
return Table(ctx.sql("SELECT 1 AS value"))
29+
return failing_table
2830

2931
ctx.register_udtf(capsule_dependent_udtf)
3032

3133
# Executing the UDTF now fails because ``Table`` no longer exposes the
3234
# ``__datafusion_table_provider__`` helper that PyTableFunction expects.
33-
ctx.sql("SELECT * FROM capsule_dependent()").collect()
35+
try:
36+
ctx.sql("SELECT * FROM capsule_dependent()").collect()
37+
except NotImplementedError as err:
38+
# Document the regression by surfacing the missing capsule attribute
39+
# instead of crashing with a panic inside the execution engine.
40+
print(
41+
"capsule_dependent() failed due to missing __datafusion_table_provider__: "
42+
f"{err}"
43+
)
3444

3545

3646
if __name__ == "__main__":

0 commit comments

Comments
 (0)