Skip to content

Require all zero argument UDFs use Signature::Nullary, improve error messages #13871

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 9 commits into from

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Dec 21, 2024

Which issue does this PR close?

Rationale for this change

As described on #13763

In version s 43.0.0 and earlier of DataFusion, a TypeSignature::Any(0) means your udf could be called with zero arguments:

SELECT my_udf();

However in version 44.0.0 you get a very confusing error that says zero arguments are not supported but then gives you a candidate function is the one it just said was not supported:

SELECT my_udf();

Error during planning: example_union does not support zero arguments. 
No function matches the given name and argument types 'my_udf()'. 
You might need to add explicit type casts.

Candidate functions:
example_union()

Also, Signature::Exact(vec![]) does work.

What changes are included in this PR?

  1. Add tests showing various ways to call udfs with no arguments
  2. Update Signature::supports_zero_args to disallow exact

Are these changes tested?

Yes, now integration tests are added, and redundant unit tests removed

Are there any user-facing changes?

@alamb alamb marked this pull request as draft December 21, 2024 14:12
@alamb alamb changed the title Re-support Signature::Any(0), and add tests for zero arguments Re-support Signature::Any(0), and add tests for zero argument udfs Dec 21, 2024
@alamb alamb force-pushed the alamb/signature_nullary branch from 6def9f3 to 2f83cd0 Compare December 21, 2024 14:18
@github-actions github-actions bot removed the sql SQL Planner label Dec 21, 2024
alamb and others added 4 commits December 21, 2024 13:42
…rgument functions

- Updated the `Simple0ArgsScalarUDF` to utilize `Signature::nullary` instead of `Signature::exact`.
- Modified tests to reflect the change in signature handling for zero-argument functions.
- Enhanced error messages in type coercion functions to clarify the requirement for nullary signatures.
- Cleaned up redundant checks and improved code readability in the type coercion logic.

This change improves consistency in how zero-argument functions are defined and validated across the codebase.
Signed-off-by: Jay Zhan <jayzhan211@gmail.com>
@jayzhan211
Copy link
Contributor

I update the fix here alamb#22

Require all zero argument UDFs use `Signature::Nullary`, improve error messages
@github-actions github-actions bot added logical-expr Logical plan and expressions functions Changes to functions implementation labels Dec 22, 2024
@alamb alamb changed the title Re-support Signature::Any(0), and add tests for zero argument udfs Require all zero argument UDFs use Signature::Nullary, improve error messages Dec 22, 2024
@github-actions github-actions bot added the optimizer Optimizer rules label Dec 22, 2024
@alamb
Copy link
Contributor Author

alamb commented Dec 22, 2024

Given there are a few more built in functions with exact, I think we should postpone this PR until next release (aka postpone merge for a few days)

In the intervening time I will prepare a PR that just improves the error message for 43.

Thank you for your help @jayzhan211

@alamb
Copy link
Contributor Author

alamb commented Dec 22, 2024

Here is a PR with just improvements to the error messages

@alamb
Copy link
Contributor Author

alamb commented Feb 11, 2025

I don't have time to finish this work now. If anyone else wants to try and make progress, feel free

@alamb alamb closed this Feb 11, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
core Core DataFusion crate functions Changes to functions implementation logical-expr Logical plan and expressions optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make migration to Signature::nullary in 44.0.0 easier / less confusing
2 participants