vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2487559694
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,72 @@ fn general_array_reverse<O: OffsetSizeTrait +
TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
+ array: &GenericListViewArray<O>,
+ field: &FieldRef,
+) -> Result<ArrayRef> {
+ let offsets = array.offsets();
+ let values = array.values();
+ let sizes = array.sizes();
+
+ // Construct indices, sizes and offsets for the reversed array by
iterating over
+ // the list view array in the logical order, and reversing the order of
the elements.
+ // We end up with a list view array where the elements are in order,
+ // even if the original array had elements out of order.
+ let mut indices: Vec<O> = Vec::with_capacity(values.len());
+ let mut new_sizes = Vec::with_capacity(sizes.len());
+ let mut new_offsets: Vec<O> = Vec::with_capacity(offsets.len());
+ // Add the offset of the first array
+ new_offsets.push(O::zero());
Review Comment:
Unless I'm misunderstanding you, this doesn't work: We have a
`ListViewArray` which is an array of list views. If we reverse the arrays, we
only reverse the order of the list views. But the operation we want here is to
reverse each list view itself.
The most efficient way to reverse each list view would be to modify from
`[offset, offset + size]` to `[offset + size, offset]`. But this requires being
able to make `size` a negative number, which is currently not supported, ref
https://github.com/apache/datafusion/issues/18350#issuecomment-3469954676.
If doing that is in the spirit of the spec, I/we should maybe open a
tracking issue for that? "Support negative sizes for ListViews"
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]