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: add arguments length check in array_expressions #8622

Merged
merged 1 commit into from
Dec 23, 2023

Conversation

Weijun-H
Copy link
Member

@Weijun-H Weijun-H commented Dec 22, 2023

Which issue does this PR close?

As suggestions by @comphead in #8592 (comment), I found many functions in array_expression.rs lack the argument check.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the physical-expr Physical Expressions label Dec 22, 2023
@jayzhan211
Copy link
Contributor

jayzhan211 commented Dec 22, 2023

I thought we should handle this in array signature 🤔

Other than lengths, whether it is list or not, null or empty array handling etc. Those checking may be done in array signature step. I think doing the same thing in different place can be avoided.

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.

thanks @Weijun-H for the followup

@@ -1082,6 +1106,10 @@ fn concat_internal(args: &[ArrayRef]) -> Result<ArrayRef> {

/// Array_concat/Array_cat SQL function
pub fn array_concat(args: &[ArrayRef]) -> Result<ArrayRef> {
if args.is_empty() {
return exec_err!("array_concat expects at least one arguments");
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
return exec_err!("array_concat expects at least one arguments");
return exec_err!("array_concat expects at least one argument");

@@ -883,6 +899,10 @@ pub fn array_append(args: &[ArrayRef]) -> Result<ArrayRef> {

/// Array_sort SQL function
pub fn array_sort(args: &[ArrayRef]) -> Result<ArrayRef> {
if args.is_empty() || args.len() > 3 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to make it more usable in future for all built in functions. To provide the exact available signatures, to let user quickly find what is his mistake

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to make it more usable in future for all built in functions. To provide the exact available signatures, to let user quickly find what is his mistake

@comphead
But we will also handle this while checking signature of array. Why do we need to check it here again? Is there any usage that skip the signature checking but jump to this call directly? If yes, we need to find a way to reuse the checking because the coercion is not supported here currently, length checking may not be enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

Checking input arguments validity in public methods is good practice imho.

But the comment above was mostly to thinking on having a generic approach to return a friendly message to the user about what is wrong and what is the next step. Now we usually saying the input arguments has to be 1, 2, 3 arguments but it is mostly meaningless, we can probably improve it with more detailed message

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the late reply. I agree with the message that more specific information would be better.

@comphead comphead merged commit 7443f30 into apache:main Dec 23, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants