Skip to content

Commit 13482f3

Browse files
committed
update
1 parent 9139880 commit 13482f3

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

datafusion/functions-nested/src/reverse.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,21 @@ fn fixed_size_array_reverse(
193193
let mut nulls = vec![];
194194
let mut mutable =
195195
MutableArrayData::with_capacities(vec![&original_data], false, capacity);
196-
let value_length = array.value_length();
196+
let value_length = array.value_length() as usize;
197197

198-
for row_index in 0..(array.len() as i32) {
198+
for row_index in 0..array.len() {
199199
// skip the null value
200-
if array.is_null(row_index as usize) {
200+
if array.is_null(row_index) {
201201
nulls.push(false);
202202
mutable.extend(0, 0, 1);
203203
continue;
204204
} else {
205205
nulls.push(true);
206206
}
207-
208207
let start = row_index * value_length;
209-
let end = (row_index + 1) * value_length;
210-
211-
let mut index = end - 1;
212-
213-
while index >= start {
214-
mutable.extend(0, index as usize, index as usize + 1);
215-
index -= 1;
208+
let end = start + value_length;
209+
for idx in (start..end).rev() {
210+
mutable.extend(0, idx, idx + 1);
216211
}
217212
}
218213

datafusion/sqllogictest/test_files/array.slt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7854,9 +7854,12 @@ select array_reverse(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)')), array
78547854
[3, 2, 1] [1]
78557855

78567856
query ??
7857-
select array_reverse(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')), array_reverse(arrow_cast(make_array(1), 'FixedSizeList(1, Int64)'));
7857+
select array_reverse(arrow_cast(make_array(1, 2, 3), 'FixedSizeList(3, Int64)')),
7858+
array_reverse(arrow_cast(make_array(1), 'FixedSizeList(1, Int64)')),
7859+
array_reverse(arrow_cast(make_array(1, NULL, 3), 'FixedSizeList(1, Int64)'));
7860+
array_reverse(arrow_cast(make_array(NULL, NULL, NULL), 'FixedSizeList(1, Int64)'));
78587861
----
7859-
[3, 2, 1] [1]
7862+
[3, 2, 1] [1] [3, NULL, 1] [NULL, NULL, NULL]
78607863

78617864
query ??
78627865
select array_reverse(NULL), array_reverse([]);

0 commit comments

Comments
 (0)