Skip to content

feat: add user defined table function support #1113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

timsaucer
Copy link
Contributor

Which issue does this PR close?

This addresses part of #1017

Rationale for this change

This feature exposes the ability to create user defined functions. Support exists in the upstream datafusion repository but was not exposed in the Python bindings.

What changes are included in this PR?

This adds a new udtf function and associated classes for creating user defined table functions. With this change you can either provide a pure python or a rust backed udtf.

There are new unit tests provided with this PR and an example usage.

Are there any user-facing changes?

This is a pure addition.

@timsaucer timsaucer force-pushed the feat/user-defined-table-functions branch from 2b7de60 to a55969c Compare May 5, 2025 13:56
@timsaucer
Copy link
Contributor Author

@mesejo @kosiew @chenkovsky @kevinjqliu Would any of you mind doing a review? We haven't released datafusion-python in a while and this is one of the PRs waiting to go in. 2/3

Copy link
Contributor

@kosiew kosiew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good to me.

I left a minor comment and one more regarding a missing _create_table_udf_decorator function.

Comment on lines 27 to 29
arrow = { version = "55" }
arrow-array = { version = "55" }
arrow-schema = { version = "55" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’ve pinned arrow = { version = "55" }, but other examples use arrow = { version = "55.0.0" }?

Should it be 55.*?

if args and hasattr(args[0], "__datafusion_table_function__"):
return TableFunction(args[1], args[0])
# Case 2: Used as a decorator with parameters
return TableFunction._create_table_udf_decorator(*args, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find _create_table_udf_decorator in TableFunction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kosiew Thank you! Added!

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@timsaucer timsaucer requested a review from kosiew May 16, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants