Skip to content

Conversation

@2010YOUY01
Copy link
Contributor

Which issue does this PR close?

Closes #6396 .

Rationale for this change

When wrong function signature is given, it's more clear to provide error message with "what's the right function signature" instead of "what's wrong"
Previous PRs in #6396 have implemented such error messages for built-in scalar functions, this PR would like to also implement it for aggregate/window functions.

Before:

DataFusion CLI v28.0.0select corr();
Error during planning: The function Correlation expects 2 arguments, but 0 were provided
❯ select regr_slope(1, '2');
Error during planning: The function RegrSlope does not support inputs of type Int64.
❯ select row_number(column1)
over (order by column1 rows between 2 preceding and current row)
from (values (1,2), (2,4), (3,6), (4,12), (5,15), (6, 18));
Error during planning: The function expected 0 arguments but received 1

PR:

select corr();
Error during planning: No function matches the given name and argument types 'CORRELATION()'. You might need to add explicit type casts.
        Candidate functions:
        CORRELATION(Int8/Int16/Int32/Int64/UInt8/UInt16/UInt32/UInt64/Float32/Float64, Int8/Int16/Int32/Int64/UInt8/UInt16/UInt32/UInt64/Float32/Float64)
❯ select regr_slope(1, '2');
Error during planning: No function matches the given name and argument types 'REGR_SLOPE(Int64, Utf8)'. You might need to add explicit type casts.
        Candidate functions:
        REGR_SLOPE(Int8/Int16/Int32/Int64/UInt8/UInt16/UInt32/UInt64/Float32/Float64, Int8/Int16/Int32/Int64/UInt8/UInt16/UInt32/UInt64/Float32/Float64)
❯ select row_number(column1)
over (order by column1 rows between 2 preceding and current row)
from (values (1,2), (2,4), (3,6), (4,12), (5,15), (6, 18));
Error during planning: No function matches the given name and argument types 'ROW_NUMBER(Int64)'. You might need to add explicit type casts.
        Candidate functions:
        ROW_NUMBER()

What changes are included in this PR?

Overwrite original errors for wrong function signature with new one.
Original errors are thrown in return_type(), I've checked all overwritten errors are for wrong signature, they can be aggregated into one with more detailed error message

Are these changes tested?

sqllogictests

Are there any user-facing changes?

No

@github-actions github-actions bot added logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) labels Aug 11, 2023
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 -- this is a very nice UX improvement I think 👍

select regr_slope(1, '2');

# WindowFunction using AggregateFunction wrong signature
statement error DataFusion error: Error during planning: No function matches the given name and argument types 'REGR_SLOPE\(Float32, Utf8\)'\. You might need to add explicit type casts\.\n\tCandidate functions:\n\tREGR_SLOPE\(Int8/Int16/Int32/Int64/UInt8/UInt16/UInt32/UInt64/Float32/Float64, Int8/Int16/Int32/Int64/UInt8/UInt16/UInt32/UInt64/Float32/Float64\)
Copy link
Contributor

Choose a reason for hiding this comment

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

candidate functions look 👍

@alamb alamb merged commit 0062778 into apache:main Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate 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.

Improve error message for function signature mismatch

2 participants