Replies: 2 comments 2 replies
-
Sounds great to me |
Beta Was this translation helpful? Give feedback.
-
I agree that all the components are ready, similar to the scalar variation, I think we can save the callable in the bind data. At execution transform the input into Python, call the callable, then transform the output back into DuckDB and return that. What makes a table function more interesting is that you likely want to keep some state in your execution. For example you're reading some special file format through a Python library and need to incrementally return a stream of tuples from it. That last part also brings up an interesting question, should the callable be returning a single row each time? (convenient implementation perhaps, not very performant) or batches of rows of an indicated size? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
Table-valued-functions (TVFs), or table returning UDFs, have been discussed for a while:
Edit 1: Added references to other products
Edit 2: Updated example to show generator
Similar features in other products
Motivation
Common workflows need to:
I've implemented workarounds via extracting out function calls, executing, returning Arrow / Dataframes, registering and and rewriting the SQL.
It seems to me that DuckDB already has all the plumbing here, and DuckDB already has all the plumbing here, and the work here is isolated to a fairly small section of code.
* I have a working draft here, described below. If there's interest, I'll clean it up and open a PR.
API
I'd propose adding two new functions in the Python bindings:
Usage Example:
Example 1
The function can be implemented as a generator, yielding a single row at a time.
The above example uses a generator. Alternatively, it could've return the results at once:
Example 2 - Named Parameters
Parameters
Return Types
TBD: Table In
Beta Was this translation helpful? Give feedback.
All reactions