-
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
feat: support stride
in array_slice
, change indexes to be1
based
#8829
Conversation
stride
in array_slice
|
||
query error Execution error: array_slice got invalid stride: 0, it cannot be 0 | ||
select array_slice(make_array(1, 2, 3, 4, 5), 1, 5, 0), array_slice(make_array('h', 'e', 'l', 'l', 'o'), 1, 5, 0); | ||
|
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.
SELECT([1, 2, 3, 4, 5])[4:2:-2];
are also needed. And other examples in duckdb, we should consider them too.
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.
Yes, I think so. And we could do it in ticket #8830 .
6b56383
to
d41c3a2
Compare
@@ -680,6 +689,16 @@ where | |||
let end = offset_window[1]; | |||
let len = end - start; | |||
|
|||
let stride = if let Some(stride) = stride { |
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.
this construction most likely can be replaced by .map/.and_then
?
(start + to + O::usize_as(1)).to_usize().unwrap(), | ||
); | ||
offsets.push(offsets[row_index] + (to - from + O::usize_as(1))); | ||
if let Some(stride) = stride { |
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.
this check may be earlier?
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.
Thanks @Weijun-H, just couple of minors, and we need to modify the user documentation?
datafusion/expr/src/expr_fn.rs
Outdated
@@ -731,7 +731,7 @@ scalar_expr!( | |||
scalar_expr!( | |||
ArraySlice, | |||
array_slice, | |||
array offset length, | |||
array offset length stride, |
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 seems offset length
is incorrect, it should be begin end
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.
LGTM
stride
in array_slice
stride
in array_slice
d11a0cc
to
977f2e1
Compare
stalled until #8847 fixed |
@@ -700,17 +709,67 @@ where | |||
}; | |||
|
|||
if let (Some(from), Some(to)) = (from_index, to_index) { | |||
let stride = stride.map(|s| s.value(row_index)); |
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.
👍
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.
Thanks @Weijun-H for the fixes, its much nicer now. Waiting for the CI
Marking as draft to make it clear this PR is not waiting on review |
977f2e1
to
297ef22
Compare
stride
in array_slice
stride
in array_slice
, change indexes to be 1 based
stride
in array_slice
, change indexes to be 1 basedstride
in array_slice
, change indexes to be0
based
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.
Looks good to me @Weijun-H -- thank you
Can you confirm the behavior change to be 0
based indexes rather than 1
based indexes is intentional? I updated the PR title but I wanted to double check
stride
in array_slice
, change indexes to be0
basedstride
in array_slice
, change indexes to be1
based
Which issue does this PR close?
Closes #8784
Rationale for this change
What changes are included in this PR?
support array_slice with stride argument
Are these changes tested?
Are there any user-facing changes?