-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
panics
#10547
fix: array_slice
panics
#10547
Conversation
let stride = stride.unwrap_or(1); | ||
if stride.is_zero() { | ||
return exec_err!( | ||
"array_slice got invalid stride: {:?}, it cannot be 0", | ||
stride | ||
); | ||
} else if from <= to && stride.is_negative() { | ||
} else if (from <= to && stride.is_negative()) |
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.
When from
is equal to to
, it should not return an empty list.
The fix for it is not included in this PR, it has been added to issue #10548.
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.
Thank you @jonahgao
Thank you for reviewing @alamb |
* fix: array_slice panics * add test * add test * update test * fix comment * fix clippy
Which issue does this PR close?
Closes #10425.
Rationale for this change
Note: Negative
from
orto
implies counting from the end of the list and both are standardized to the corresponding positive index.When
from
is greater thanto
andstride
is a positive, the following loop becomes infinite, until theindex
becomes excessively large and panics.datafusion/datafusion/functions-array/src/extract.rs
Lines 468 to 478 in 842f393
The fix is to return an empty list directly in this situation.
What changes are included in this PR?
Fix panic.
Are these changes tested?
Yes
Are there any user-facing changes?
No