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

Window UDF signature check #12045

Merged
merged 3 commits into from
Aug 18, 2024
Merged

Window UDF signature check #12045

merged 3 commits into from
Aug 18, 2024

Conversation

jayzhan211
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

We haven't add signature check for window udf, so we didn't get the expected error if the arguments failed to match the signature

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Signed-off-by: jayzhan211 <[email protected]>
@github-actions github-actions bot added logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Aug 18, 2024
1 1

# RowNumber expect 0 args.
query error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not an error on main

Copy link
Contributor

Choose a reason for hiding this comment

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

Wild -- I double checked and you are right

DataFusion CLI v41.0.0
> create table t(a int, b int) as values (1, 2);
0 row(s) fetched.
Elapsed 0.015 seconds.

> select a, row_number() over (order by b) as rn from t;
+---+----+
| a | rn |
+---+----+
| 1 | 1  |
+---+----+
1 row(s) fetched.
Elapsed 0.006 seconds.

> select a, row_number(a) over (order by b) as rn from t;
+---+----+
| a | rn |
+---+----+
| 1 | 1  |
+---+----+
1 row(s) fetched.
Elapsed 0.002 seconds.

Signed-off-by: jayzhan211 <[email protected]>
@jayzhan211 jayzhan211 marked this pull request as ready for review August 18, 2024 03:58
Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

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

Thanks @jayzhan211 Overall LGTM but one typo comment.

/// Coerce arguments of a function call to types that the function can evaluate.
///
/// This function is only called if [`WindowUDFImpl::signature`] returns [`crate::TypeSignature::UserDefined`]. Most
/// UDAFs should return one of the other variants of `TypeSignature` which handle common
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// UDAFs should return one of the other variants of `TypeSignature` which handle common
/// UDWFs should return one of the other variants of `TypeSignature` which handle common

It looks like a typo (?

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.

Thanks @jayzhan211 and @goldmedal for the review

I didn't realize there was no signature checking 🤯

@@ -95,6 +94,32 @@ pub fn data_types_with_aggregate_udf(
try_coerce_types(valid_types, current_types, &signature.type_signature)
}

pub fn data_types_with_window_udf(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add documentation for this (pub) function? I think we could basically follow the pattern of the docs on data_types_with_scalar_udf above

1 1

# RowNumber expect 0 args.
query error
Copy link
Contributor

Choose a reason for hiding this comment

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

Wild -- I double checked and you are right

DataFusion CLI v41.0.0
> create table t(a int, b int) as values (1, 2);
0 row(s) fetched.
Elapsed 0.015 seconds.

> select a, row_number() over (order by b) as rn from t;
+---+----+
| a | rn |
+---+----+
| 1 | 1  |
+---+----+
1 row(s) fetched.
Elapsed 0.006 seconds.

> select a, row_number(a) over (order by b) as rn from t;
+---+----+
| a | rn |
+---+----+
| 1 | 1  |
+---+----+
1 row(s) fetched.
Elapsed 0.002 seconds.

Signed-off-by: jayzhan211 <[email protected]>
@jayzhan211 jayzhan211 merged commit a91be04 into apache:main Aug 18, 2024
24 checks passed
@jayzhan211 jayzhan211 deleted the udwf-sig branch August 18, 2024 12:47
@jayzhan211
Copy link
Contributor Author

Thanks @goldmedal @alamb

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 sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants