jayzhan211 commented on code in PR #8829:
URL: https://github.com/apache/arrow-datafusion/pull/8829#discussion_r1451077923
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -702,15 +721,75 @@ where
if let (Some(from), Some(to)) = (from_index, to_index) {
if from <= to {
assert!(start + to <= end);
- mutable.extend(
- 0,
- (start + from).to_usize().unwrap(),
- (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 {
+ if stride.is_zero() {
+ return exec_err!(
+ "array_slice got invalid stride: {}, it cannot be
0",
+ stride
+ );
+ } else if stride.is_negative() {
+ // return empty array
+ offsets.push(offsets[row_index]);
+ continue;
+ }
+ let mut index = start + from;
+ let mut cnt = 0;
+ let stride: O = stride.try_into().map_err(|_| {
+ internal_datafusion_err!(
+ "array_slice got invalid stride: {}",
+ stride
+ )
+ })?;
+ while index <= start + to {
+ mutable.extend(
+ 0,
+ index.to_usize().unwrap(),
+ index.to_usize().unwrap() + 1,
+ );
+ index += stride;
+ cnt += 1;
+ }
+ offsets.push(offsets[row_index] + O::usize_as(cnt));
+ } else {
+ // stride is default to 1
+ mutable.extend(
+ 0,
+ (start + from).to_usize().unwrap(),
+ (start + to + O::usize_as(1)).to_usize().unwrap(),
+ );
+ offsets.push(offsets[row_index] + (to - from +
O::usize_as(1)));
+ }
} else {
+ let stride = if let Some(stride) = stride {
+ if !stride.is_negative() {
Review Comment:
you can use `is_positive()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]