-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: wrong result of range function #8313
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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()); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Emm, this is good advice, but it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and I think we should add a test case for it 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I added ut for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind putting the test in sqllogoictest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/apache/arrow-datafusion/blob/b648d4e22e82989c65523e62312e1995a1543888/datafusion/sqllogictest/test_files/array.slt#L2748C1-L2752C23 |
||||||||||||||||||||||||||||||||||||
offsets.push(values.len() as i32); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
let arr = Arc::new(ListArray::try_new( | ||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2752,7 +2752,7 @@ select range(5), | |||||||
range(1, -5, 1) | ||||||||
; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move the test to the sqllogistest, overall LGTM 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated~ |
||||||||
---- | ||||||||
[0, 1, 2, 3, 4] [2, 3, 4] [2, 5, 8] [1] [] | ||||||||
[0, 1, 2, 3, 4] [2, 3, 4] [2, 5, 8] [] [] | ||||||||
|
||||||||
query ??? | ||||||||
select generate_series(5), | ||||||||
|
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.