-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: array_slice
and array_element
panicked on empty args
#10804
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1974,6 +1978,10 @@ select array_slice(a, -1, 2, 1), array_slice(a, -1, 2), | |||
[] [] [] [] | |||
[6.0] [6.0] [] [] | |||
|
|||
# Testing with empty arguments should result in an error | |||
query error DataFusion error: Error during planning: Error during planning: \[data_types_with_scalar_udf\] signature VariadicAny does not support zero arguments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is handled by signature!
@@ -97,8 +97,11 @@ impl ScalarUDFImpl for ArrayElement { | |||
} | |||
|
|||
fn display_name(&self, args: &[Expr]) -> Result<String> { | |||
let args_name: Vec<String> = args.iter().map(|e| e.to_string()).collect(); | |||
Ok(format!("{}[{}]", args_name[0], args_name[1])) | |||
Ok(format!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is a nice drive by cleanup
Thanks @jonahgao and @jayzhan211 |
Thank you for the review @jayzhan211 @alamb |
…#10804) * fix: `array_slice` and `array_element` panicked on empty args * Use single-line error
Which issue does this PR close?
Closes #10791.
Rationale for this change
When the
args
are empty, they panic at display_name, due to "index out of bounds".datafusion/datafusion/functions-array/src/extract.rs
Lines 253 to 256 in ece7ae5
The fix is to use an empty string as the arg name if it is out of bounds, allow
display_name
to pass through, and subsequently generating an error by checking the signature.What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?
No