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(frontend): support drop function without arguments #9561

Merged
merged 3 commits into from
May 3, 2023

Conversation

wangrunji0408
Copy link
Contributor

@wangrunji0408 wangrunji0408 commented May 3, 2023

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

What's changed and what's your intention?

As title. drop function foo; will succeed only when there's exactly one function named foo.

Here are some examples:

dev=> create function foo() ...;
dev=> create function foo(int) ...;

dev=> drop function foo;
ERROR:  QueryError: Catalog error: function name "foo" is not unique
HINT: Specify the argument list to select the function unambiguously.

dev=> drop function foo();
DROP_FUNCTION

# now there's only one function `foo(int)`. this command will succeed to drop it.
dev=> drop function foo;
DROP_FUNCTION

This PR also improved the error message when function is not found.

 dev=> drop function gcd(int);
-ERROR:  QueryError: Catalog error: function not found: gcd
+ERROR:  QueryError: Catalog error: function not found: gcd(integer)

Checklist For Contributors

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • I have demonstrated that backward compatibility is not broken by breaking changes and created issues to track deprecated features to be removed in the future. (Please refer to the issue)
  • All checks passed in ./risedev check (or alias, ./risedev c)

Checklist For Reviewers

  • I have requested macro/micro-benchmarks as this PR can affect performance substantially, and the results are shown.

Documentation

Click here for Documentation

Types of user-facing changes

Please keep the types that apply to your changes, and remove the others.

  • SQL commands, functions, and operators

Release note

Borrowed from Postgres documents:

If the function name is unique in its schema, it can be referred to without an argument list:

DROP FUNCTION foo;

Note that this is different from

DROP FUNCTION foo();

which refers to a function with zero arguments, whereas the first variant can refer to a function with any number of arguments, including zero, as long as the name is unique.

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 requested review from yezizp2012 and xxchan May 3, 2023 10:04
@github-actions github-actions bot added type/fix Bug fix user-facing-changes Contains changes that are visible to users labels May 3, 2023
Comment on lines +64 to +77
None => match reader.get_functions_by_name(db_name, schema_path, &function_name) {
Ok((functions, schema_name)) => {
if functions.len() > 1 {
return Err(ErrorCode::CatalogError(format!("function name {function_name:?} is not unique\nHINT: Specify the argument list to select the function unambiguously.").into()).into());
}
Ok((
functions.into_iter().next().expect("no functions"),
schema_name,
))
}
Err(e) => Err(e),
},
};
match res {
Copy link
Member

Choose a reason for hiding this comment

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

This looks a little spaghetti, but I don't have an immediate idea to improve it 🤪

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. it's quick-and-dirty. 🤪

Comment on lines +488 to +490
if functions.is_empty() {
return None;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this option unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it might panic when this function returns a Some(vec![]). So I added these lines to prevent it.

@codecov
Copy link

codecov bot commented May 3, 2023

Codecov Report

Merging #9561 (4953322) into main (0ce1e53) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #9561      +/-   ##
==========================================
- Coverage   70.74%   70.72%   -0.03%     
==========================================
  Files        1234     1234              
  Lines      206718   206757      +39     
==========================================
- Hits       146243   146228      -15     
- Misses      60475    60529      +54     
Flag Coverage Δ
rust 70.72% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/frontend/src/catalog/root_catalog.rs 59.95% <0.00%> (-2.36%) ⬇️
src/frontend/src/catalog/schema_catalog.rs 47.14% <0.00%> (-0.80%) ⬇️
src/frontend/src/handler/drop_function.rs 0.00% <0.00%> (ø)
src/sqlparser/src/parser.rs 87.09% <0.00%> (ø)

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@wangrunji0408 wangrunji0408 added this pull request to the merge queue May 3, 2023
Merged via the queue into main with commit b385eb6 May 3, 2023
@wangrunji0408 wangrunji0408 deleted the wrj/drop-function branch May 3, 2023 15:14
@CharlieSYH CharlieSYH added the 📖✓ Covered or will be covered in the user docs. label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Bug fix user-facing-changes Contains changes that are visible to users 📖✓ Covered or will be covered in the user docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants