Weijun-H commented on code in PR #8313:
URL: https://github.com/apache/arrow-datafusion/pull/8313#discussion_r1403493996
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -741,13 +741,22 @@ pub fn gen_range(args: &[ArrayRef]) -> Result<ArrayRef> {
let mut offsets = vec![0];
for (idx, stop) in stop_array.iter().enumerate() {
let stop = stop.unwrap_or(0);
- let start = start_array.as_ref().map(|arr|
arr.value(idx)).unwrap_or(0);
+ let mut start = start_array.as_ref().map(|arr|
arr.value(idx)).unwrap_or(0);
Review Comment:
```suggestion
let start = start_array.as_ref().map(|arr|
arr.value(idx)).unwrap_or(0);
```
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -741,13 +741,22 @@ pub fn gen_range(args: &[ArrayRef]) -> Result<ArrayRef> {
let mut offsets = vec![0];
for (idx, stop) in stop_array.iter().enumerate() {
let stop = stop.unwrap_or(0);
- let start = start_array.as_ref().map(|arr|
arr.value(idx)).unwrap_or(0);
+ let mut start = start_array.as_ref().map(|arr|
arr.value(idx)).unwrap_or(0);
let step = step_array.as_ref().map(|arr| arr.value(idx)).unwrap_or(1);
if step == 0 {
return exec_err!("step can't be 0 for function range(start [,
stop, step]");
}
- let value = (start..stop).step_by(step as usize);
- values.extend(value);
+ let value;
+ if step < 0 {
+ while stop < start {
+ values.push(start);
+ start += step;
+ }
+ } else {
+ value = (start..stop).step_by(step as usize);
+ values.extend(value.clone());
+ }
+
Review Comment:
```suggestion
if step < 0 {
// Decreasing range
values.extend((stop..start).rev().step_by((-step) as usize));
} else {
// Increasing range
values.extend((start..stop).step_by(step as usize));
}
```
--
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]