Skip to content
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

Minor: Move function signature check to planning stage #9401

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

2010YOUY01
Copy link
Contributor

Which issue does this PR close?

NA

Rationale for this change

I noticed a recent PR #9377 tried to check function argument number inside a specific function's implementation
It can be done at a higher level during planning (as it was in old builtin function implementation)

What changes are included in this PR?

  1. Move checking function argument number logic outside of function implementation body (for all recently ported function did such check)
  2. Check argument number during planning (same as old builtin function's implementation)

Are these changes tested?

Covered by existing test introduced in #9377

Are there any user-facing changes?

No

@github-actions github-actions bot added logical-expr Logical plan and expressions optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Feb 29, 2024
Comment on lines +143 to +152
data_types(&arg_data_types, fun.signature()).map_err(|_| {
plan_datafusion_err!(
"{}",
utils::generate_signature_error_msg(
fun.name(),
fun.signature().clone(),
&arg_data_types,
)
)
})?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this! Doing it during the planning stage eliminates so much duplicate code:)

FYI @jonahgao, this addresses the TODO we talked about in this comment

Copy link
Member

Choose a reason for hiding this comment

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

Nice! 👍

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

lgtm thanks @2010YOUY01
Thats good start to unify error messages if signature cannot be found

@@ -84,7 +84,7 @@ statement error Error during planning: No function matches the given name and ar
SELECT concat();

# error message for wrong function signature (Uniform: t args all from some common types)
statement error DataFusion error: Failed to coerce arguments for NULLIF
statement error DataFusion error: Error during planning: No function matches the given name and argument types 'nullif\(Int64\)'. You might need to add explicit type casts.
Copy link
Contributor

Choose a reason for hiding this comment

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

That is a much nicer error message

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @2010YOUY01 (and welcome back!)

@jayzhan211
Copy link
Contributor

Let me merge this nice change

@jayzhan211 jayzhan211 merged commit 9aa01f3 into apache:main Mar 1, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants