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

fix(binder): fix function call binding #18177

Merged
merged 4 commits into from
Aug 22, 2024
Merged

fix(binder): fix function call binding #18177

merged 4 commits into from
Aug 22, 2024

Conversation

stdrc
Copy link
Member

@stdrc stdrc commented Aug 22, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Previously our bind_function is a mess. An example is #17560, which is because we bind UD(A/T)F and window function in different path, and we never considered a combination of the two.

This PR re-organizes bind_function and is a pre-requisition for fixing #17560.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@stdrc stdrc changed the title add some simple comment fix(binder): fix function call binding Aug 22, 2024
@github-actions github-actions bot added type/fix Bug fix and removed Invalid PR Title labels Aug 22, 2024
@stdrc stdrc marked this pull request as ready for review August 22, 2024 06:47
@stdrc stdrc marked this pull request as draft August 22, 2024 06:50
@stdrc stdrc marked this pull request as ready for review August 22, 2024 06:56
@@ -19,7 +19,7 @@ use crate::aggregate::AggKind;
use crate::Result;

/// Kind of window functions.
#[derive(Debug, Display, FromStr, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Display, FromStr /* for builtin */, Clone, PartialEq, Eq, Hash)]
Copy link
Contributor

Choose a reason for hiding this comment

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

What is "for builtin"

Copy link
Member Author

@stdrc stdrc Aug 22, 2024

Choose a reason for hiding this comment

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

We can only parse builtin window functions directly from a string. For UDAF as window function we have to go through a function look up logic.

@@ -62,7 +62,7 @@
Failed to bind expression: lag(x)

Caused by:
Invalid input syntax: Window function `lag` must have OVER clause
function lag(integer) does not exist, do you mean log
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems this error message is less precise?

Copy link
Member Author

@stdrc stdrc Aug 22, 2024

Choose a reason for hiding this comment

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

To me, the two error messages both look good. Actually I think it's equally possible that the user 1) forgets to write OVER clause when intended to do a window function call or 2) mistypes the normal scalar function log as lag. I mean from the view of editing distance between the given query and the two correct syntaxes.

Copy link
Member Author

Choose a reason for hiding this comment

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

May need additional work to achieve msg like function lag(integer) does not exist as a scalar function, do you mean log or do you forget the OVER clause which is better. We can leave it to future.

// For type inference, we need to bind the array type first.
return self.bind_array_transform(f);
reject_syntax!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems heavy to me to introduce a macro instead of just a function to construct

            return Err(ErrorCode::InvalidInputSyntax($msg.to_string()).into());

But I'm not going to block this PR with it.

Copy link
Contributor

@kwannoel kwannoel 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!

Base automatically changed from rc/fix-function-parser to main August 22, 2024 09:20
@stdrc stdrc force-pushed the rc/fix-function-binder branch from 0ec8cd5 to 830794c Compare August 22, 2024 10:13
Copy link
Member

Choose a reason for hiding this comment

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

The diff of this file on GitHub is a mess as well. 🤣

stdrc added 4 commits August 22, 2024 22:01
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
@stdrc stdrc force-pushed the rc/fix-function-binder branch from 830794c to 8574edc Compare August 22, 2024 14:04
@stdrc stdrc enabled auto-merge August 22, 2024 14:04
@stdrc stdrc disabled auto-merge August 22, 2024 14:04
@stdrc stdrc added this pull request to the merge queue Aug 22, 2024
Merged via the queue into main with commit 2fa8034 Aug 22, 2024
30 of 31 checks passed
@stdrc stdrc deleted the rc/fix-function-binder branch August 22, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants