You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "vegarsti (via GitHub)" <gi...@apache.org> on 2025/11/01 06:38:27 UTC
[PR] Support reverse for ListView [datafusion]
vegarsti opened a new pull request, #18424:
URL: https://github.com/apache/datafusion/pull/18424
## Which issue does this PR close?
- Closes #18350.
## Rationale for this change
We want to be able to reverse a ListView.
## What changes are included in this PR?
- Downcast `&dyn Array` to `ListView`: `as_list_view_array`
- Downcast `&dyn Array` to `LargeListView`: `as_large_list_view_array`
- Branches in `array_reverse_inner` to reverse `ListView` and `LargeListView`
## Are these changes tested?
Yes, but please suggest more cases to cover
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2491738042
##########
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:
All good! 😄
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2487758392
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Alright, I tried the benchmark here #18425 with `array_len` of 10k (it's 100k on the branch), using MutableData is way worse 🫨 Baseline is the code on this PR, the code from this snippet is [here](https://gist.github.com/vegarsti/28be107e53670428750874bfc0cdb621).
```
array_reverse time: [44.858 µs 44.865 µs 44.874 µs]
change: [+545.75% +547.46% +549.17%] (p = 0.00 < 0.05)
Performance has regressed.
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484880239
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
+ }
+
+ // Materialize values from underlying array with take
+ let indices_array: ArrayRef = if O::IS_LARGE {
+ Arc::new(arrow::array::UInt64Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u64)
+ .collect::<Vec<_>>(),
+ ))
+ } else {
+ Arc::new(UInt32Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u32)
+ .collect::<Vec<_>>(),
+ ))
+ };
+ let values_reversed = take(&values, &indices_array, None)?;
+
+ Ok(Arc::new(GenericListViewArray::<O>::try_new(
+ Arc::clone(field),
+ ScalarBuffer::from(new_offsets),
+ ScalarBuffer::from(new_sizes),
+ values_reversed,
+ has_nulls.then_some(NullBuffer::from(new_nulls)),
Review Comment:
Oh, yes! Thanks! I mixed these up, but indeed we can, since we keep the logical order of the arrays.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#issuecomment-3475922162
This was too simplistic, it doesn't work for out of order offsets, which is quite important for ListView! Moving to draft.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
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.
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2483842679
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // Construct indices corresponding to the reversed arrays
+ let mut indices: Vec<O> = Vec::with_capacity(values.len());
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ }
+
+ // Take values from underlying array in the reversed order
+ let indices_array: ArrayRef = match size_of::<O>() {
Review Comment:
Changed to use `O::IS_LARGE` but still wondering about the approach
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484879159
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
Review Comment:
Yes! If there is another array, we add the offset of that array. Added this as a comment. There might be a nicer way to do this, though! If we remove the check, we have one offset more than number of arrays - since we add offset 0 before the loop - which fails in the constructor.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2489053365
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Thanks, good catch. Done in 7d39f69
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484879672
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
Review Comment:
Doh! Thank you!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2491716947
##########
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:
I think i was confused -- sorry about that
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2487543191
##########
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());
+ for (i, offset) in offsets.iter().enumerate() {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if array.is_null(i) {
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ }
Review Comment:
Great point, this current implementation did indeed fail that test!
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
Review Comment:
Perfect, thank you!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2491917610
##########
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:
🙏
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2487758392
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Alright, I tried the benchmark here #18425 with `array_len` of 10k (it's 100k on the branch), using MutableData is way worse 🫨 Baseline is the code on this PR, the code from this snippet is [here](https://gist.github.com/vegarsti/28be107e53670428750874bfc0cdb621).
```
array_reverse time: [44.858 µs 44.865 µs 44.874 µs]
change: [+545.75% +547.46% +549.17%] (p = 0.00 < 0.05)
Performance has regressed.
```
This indicates it might be worth using `take` instead of `MutableData` on the regular array one too.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2486523946
##########
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:
Per https://arrow.apache.org/docs/format/Columnar.html#listview-layout
the offsets for a ListView are simply the offsets into the child array
So I think the fastest/ simplest implementation is going to be
1. reverse both the offsets and lengths array
2. reverse the nulls array
3. create a new list array with the new offsets/lengths/nulls and child
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484879301
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Indeed not! Thanks!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484882102
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
Review Comment:
Good point about the roundtrip! I will try to fix that.
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
+ }
+
+ // Materialize values from underlying array with take
+ let indices_array: ArrayRef = if O::IS_LARGE {
+ Arc::new(arrow::array::UInt64Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u64)
+ .collect::<Vec<_>>(),
+ ))
+ } else {
+ Arc::new(UInt32Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u32)
+ .collect::<Vec<_>>(),
+ ))
+ };
Review Comment:
Yeah, this feels cumbersome!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2483842679
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // Construct indices corresponding to the reversed arrays
+ let mut indices: Vec<O> = Vec::with_capacity(values.len());
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ }
+
+ // Take values from underlying array in the reversed order
+ let indices_array: ArrayRef = match size_of::<O>() {
Review Comment:
Changed to use `O::IS_LARGE`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2486575561
##########
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());
Review Comment:
FWIW you can convert the existing indices to a Vec for in place update as well -- I tried to document that a bit more in https://github.com/apache/arrow-rs/pull/8771
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2489051740
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -219,3 +300,148 @@ fn fixed_size_array_reverse(
Some(nulls.into()),
)?))
}
+
+#[cfg(test)]
+mod tests {
+ use crate::reverse::list_view_reverse;
+ use arrow::{
+ array::{
+ AsArray, GenericListViewArray, Int32Array, LargeListViewArray, ListViewArray,
+ OffsetSizeTrait,
+ },
+ buffer::{NullBuffer, ScalarBuffer},
+ datatypes::{DataType, Field, Int32Type},
+ };
+ use datafusion_common::Result;
+ use std::sync::Arc;
+
+ fn list_view_values<O: OffsetSizeTrait>(
+ array: &GenericListViewArray<O>,
+ ) -> Vec<Option<Vec<i32>>> {
+ array
+ .iter()
+ .map(|x| x.map(|x| x.as_primitive::<Int32Type>().values().to_vec()))
+ .collect()
+ }
+
+ #[test]
+ fn test_reverse_list_view() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![0, 1, 6, 6]);
+ let sizes = ScalarBuffer::from(vec![1, 5, 0, 3]);
+ let values = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = ListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i32>());
+ let expected = vec![
+ Some(vec![1]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![9, 8, 7]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_large_list_view() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![0, 1, 6, 6]);
+ let sizes = ScalarBuffer::from(vec![1, 5, 0, 3]);
+ let values = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = LargeListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i64>());
+ let expected = vec![
+ Some(vec![1]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![9, 8, 7]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_list_view_out_of_order() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![6, 1, 6, 0]); // out of order
+ let sizes = ScalarBuffer::from(vec![3, 5, 0, 1]);
+ let values = Arc::new(Int32Array::from(vec![
+ 1, // fourth array: offset 0, size 1
+ 2, 3, 4, 5, 6, // second array: offset 1, size 5
+ // third array: offset 6, size 0 (and null)
+ 7, 8, 9, // first array: offset 6, size 3
+ ]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = ListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i32>());
+ let expected = vec![
+ Some(vec![9, 8, 7]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![1]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_list_view_with_nulls() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![16, 1, 6, 0]); // out of order
+ let sizes = ScalarBuffer::from(vec![3, 5, 10, 1]);
+ let values = Arc::new(Int32Array::from(vec![
+ 1, // fourth array: offset 0, size 1
+ 2, 3, 4, 5, 6, // second array: offset 1, size 5
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // third array: offset 6, size 10
+ 7, 8, 9, // first array: offset 6, size 3
+ ]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = ListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i32>());
+ let expected = vec![
+ Some(vec![9, 8, 7]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![1]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_list_view_empty() -> Result<()> {
Review Comment:
Good idea! Done in 7d39f69
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2488546840
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -219,3 +300,148 @@ fn fixed_size_array_reverse(
Some(nulls.into()),
)?))
}
+
+#[cfg(test)]
+mod tests {
+ use crate::reverse::list_view_reverse;
+ use arrow::{
+ array::{
+ AsArray, GenericListViewArray, Int32Array, LargeListViewArray, ListViewArray,
+ OffsetSizeTrait,
+ },
+ buffer::{NullBuffer, ScalarBuffer},
+ datatypes::{DataType, Field, Int32Type},
+ };
+ use datafusion_common::Result;
+ use std::sync::Arc;
+
+ fn list_view_values<O: OffsetSizeTrait>(
+ array: &GenericListViewArray<O>,
+ ) -> Vec<Option<Vec<i32>>> {
+ array
+ .iter()
+ .map(|x| x.map(|x| x.as_primitive::<Int32Type>().values().to_vec()))
+ .collect()
+ }
+
+ #[test]
+ fn test_reverse_list_view() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![0, 1, 6, 6]);
+ let sizes = ScalarBuffer::from(vec![1, 5, 0, 3]);
+ let values = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = ListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i32>());
+ let expected = vec![
+ Some(vec![1]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![9, 8, 7]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_large_list_view() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![0, 1, 6, 6]);
+ let sizes = ScalarBuffer::from(vec![1, 5, 0, 3]);
+ let values = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = LargeListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i64>());
+ let expected = vec![
+ Some(vec![1]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![9, 8, 7]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_list_view_out_of_order() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![6, 1, 6, 0]); // out of order
+ let sizes = ScalarBuffer::from(vec![3, 5, 0, 1]);
+ let values = Arc::new(Int32Array::from(vec![
+ 1, // fourth array: offset 0, size 1
+ 2, 3, 4, 5, 6, // second array: offset 1, size 5
+ // third array: offset 6, size 0 (and null)
+ 7, 8, 9, // first array: offset 6, size 3
+ ]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = ListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i32>());
+ let expected = vec![
+ Some(vec![9, 8, 7]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![1]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_list_view_with_nulls() -> Result<()> {
+ let field = Arc::new(Field::new("a", DataType::Int32, false));
+ let offsets = ScalarBuffer::from(vec![16, 1, 6, 0]); // out of order
+ let sizes = ScalarBuffer::from(vec![3, 5, 10, 1]);
+ let values = Arc::new(Int32Array::from(vec![
+ 1, // fourth array: offset 0, size 1
+ 2, 3, 4, 5, 6, // second array: offset 1, size 5
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // third array: offset 6, size 10
+ 7, 8, 9, // first array: offset 6, size 3
+ ]));
+ let nulls = Some(NullBuffer::from(vec![true, true, false, true]));
+ let list_view = ListViewArray::new(field, offsets, sizes, values, nulls);
+ let result = list_view_reverse(
+ &list_view,
+ &Arc::new(Field::new("test", DataType::Int32, true)),
+ )?;
+ let reversed = list_view_values(result.as_list_view::<i32>());
+ let expected = vec![
+ Some(vec![9, 8, 7]),
+ Some(vec![6, 5, 4, 3, 2]),
+ None,
+ Some(vec![1]),
+ ];
+ assert_eq!(expected, reversed);
+ Ok(())
+ }
+
+ #[test]
+ fn test_reverse_list_view_empty() -> Result<()> {
Review Comment:
Could we also have a test case where its all nulls?
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Sounds good to go with take in that case
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Might need to merge up from main, the trait bound is still here on the new function
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484880702
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Good idea, I will try that
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2483162083
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // Construct indices corresponding to the reversed arrays
+ let mut indices: Vec<O> = Vec::with_capacity(values.len());
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ }
+
+ // Take values from underlying array in the reversed order
+ let indices_array: ArrayRef = match size_of::<O>() {
Review Comment:
I'm not sure about this, but I wanted to 1) avoid unwraps 2) don't use 64 if 32 was sufficient.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484883892
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
Review Comment:
Don't catch what you mean by "a loop instead of a for" though! Mind explaining?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#issuecomment-3488769412
Thanks @vegarsti
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484795942
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
Review Comment:
```suggestion
for (i, offset) in offsets.iter().enumerate() {
```
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
+ }
+
+ // Materialize values from underlying array with take
+ let indices_array: ArrayRef = if O::IS_LARGE {
+ Arc::new(arrow::array::UInt64Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u64)
+ .collect::<Vec<_>>(),
+ ))
+ } else {
+ Arc::new(UInt32Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u32)
+ .collect::<Vec<_>>(),
+ ))
+ };
Review Comment:
Hmm I do wonder if there is a better way to do this, will keep thinking 🤔
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
Review Comment:
Could you help me understand the reasoning for this check?
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
+ }
+
+ // Materialize values from underlying array with take
+ let indices_array: ArrayRef = if O::IS_LARGE {
+ Arc::new(arrow::array::UInt64Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u64)
+ .collect::<Vec<_>>(),
+ ))
+ } else {
+ Arc::new(UInt32Array::from(
+ indices
+ .iter()
+ .map(|i| i.as_usize() as u32)
+ .collect::<Vec<_>>(),
+ ))
+ };
+ let values_reversed = take(&values, &indices_array, None)?;
+
+ Ok(Arc::new(GenericListViewArray::<O>::try_new(
+ Arc::clone(field),
+ ScalarBuffer::from(new_offsets),
+ ScalarBuffer::from(new_sizes),
+ values_reversed,
+ has_nulls.then_some(NullBuffer::from(new_nulls)),
Review Comment:
I think we can just directly grab the null buffer from the input array
(I know the other reverse functions don't do this, but I think it's a valid approach instead of recreating the null buffer element by element)
```suggestion
array.nulls().cloned(),
```
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
```suggestion
fn list_view_reverse<O: OffsetSizeTrait>(
```
I don't think the extra bound is used
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
Using `take` makes sense to me here. If you have time you could try both approaches and run a benchmark?
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
Review Comment:
```suggestion
let offsets = array.offsets();
let values = array.values();
let sizes = array.sizes();
```
I don't think there's a strict need to clone and deconstruct the array, can just grab constituent parts like so
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
Review Comment:
I feel this roundtripping from O -> usize -> O could be simplified, perhaps if we use a loop instead of a for? Thoughts? 🤔
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2487547871
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
Review Comment:
Included in latest commit e72469f
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
Review Comment:
Included in latest commit e72469f
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2487548766
##########
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());
+ for (i, offset) in offsets.iter().enumerate() {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if array.is_null(i) {
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ }
Review Comment:
Included in latest commit e72469f
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2483157948
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,35 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
+ array: &GenericListViewArray<O>,
+ _field: &FieldRef,
+) -> Result<ArrayRef> {
+ let (field, offsets, sizes, values, nulls) = array.clone().into_parts();
+
+ // Construct indices corresponding to the reversed arrays
+ let mut indices: Vec<u32> = Vec::with_capacity(values.len());
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(idx.try_into().unwrap());
Review Comment:
We need to avoid this `unwrap`! But I haven't figured out how to return a Result<_, DataFusionError> correctly
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2483160475
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,35 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
+ array: &GenericListViewArray<O>,
+ _field: &FieldRef,
+) -> Result<ArrayRef> {
+ let (field, offsets, sizes, values, nulls) = array.clone().into_parts();
+
+ // Construct indices corresponding to the reversed arrays
+ let mut indices: Vec<u32> = Vec::with_capacity(values.len());
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(idx.try_into().unwrap());
Review Comment:
Next commit handle this by looking at the offset
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2485221534
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
Review Comment:
Ah it's pushing the offset for the _next_ list each time? So we don't want to do it in the last iteration as we're finished.
Maybe it's better to do this via a rolling offset, something like (in pseudocode):
```
let mut offset = 0
for loop {
offsets.push(offset)
offset += size
}
```
It can eliminate this if branch, but also I think can cover an edge case regarding nulls (see next comment)
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
Review Comment:
Something similar to how `general_array_reverse` does it:
https://github.com/apache/datafusion/blob/9238779f45418e07108079aeef3b51de85e9fb8f/datafusion/functions-nested/src/reverse.rs#L160-L164
e.g.
```suggestion
let array_start = offset;
let array_end = array_start.add(sizes[i]);
let mut idx = array_end - O::one();
while idx >= array_start {
indices.push(idx);
idx -= O::one();
}
```
##########
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());
+ for (i, offset) in offsets.iter().enumerate() {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if array.is_null(i) {
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ }
Review Comment:
Do we have a test case where we have only null inputs? Because if we push an offset at the start, then encounter a ListView with a single null element, I think we end up where offsets length is 2 but sizes length is 1.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2487544343
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
Review Comment:
More readable, too! Thank you!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484879159
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
+
+ // 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());
+ let mut new_nulls =
+ Vec::with_capacity(nulls.clone().map(|nulls| nulls.len()).unwrap_or(0));
+ new_offsets.push(O::zero());
+ let has_nulls = nulls.is_some();
+ for (i, offset) in offsets.iter().enumerate().take(offsets.len()) {
+ // If this array is null, we set the new array to null with size 0 and continue
+ if let Some(ref nulls) = nulls {
+ if nulls.is_null(i) {
+ new_nulls.push(false); // null
+ new_sizes.push(O::zero());
+ new_offsets.push(new_offsets[i]);
+ continue;
+ } else {
+ new_nulls.push(true); // valid
+ }
+ }
+
+ // Each array is located at [offset, offset + size), so we collect indices in the reverse order
+ let array_start = offset.as_usize();
+ let array_end = array_start + sizes[i].as_usize();
+ for idx in (array_start..array_end).rev() {
+ indices.push(O::usize_as(idx));
+ }
+ new_sizes.push(sizes[i]);
+ if i < sizes.len() - 1 {
+ new_offsets.push(new_offsets[i] + sizes[i]);
+ }
Review Comment:
Yes! If there is another array, we add the offset of that array. Added this as a comment. If we remove the check, we have one offset more than number of arrays - since we add offset 0 before the loop - which fails in the constructor.
There might be a nicer way to do this, though!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2484879507
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +195,75 @@ 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, sizes, values, nulls) = array.clone().into_parts();
Review Comment:
Good point, thanks. I do end up using all except `field`, but this is more readable
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey merged PR #18424:
URL: https://github.com/apache/datafusion/pull/18424
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support reverse for ListView [datafusion]
Posted by "vegarsti (via GitHub)" <gi...@apache.org>.
vegarsti commented on code in PR #18424:
URL: https://github.com/apache/datafusion/pull/18424#discussion_r2483171613
##########
datafusion/functions-nested/src/reverse.rs:
##########
@@ -183,6 +196,50 @@ fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
)?))
}
+fn list_view_reverse<O: OffsetSizeTrait + TryFrom<i64>>(
Review Comment:
I have to admit I did not spend much time looking at `general_array_reverse`, maybe I should have... It constructs a `MutableArrayData` and operates on it, while this uses `take`. There might be a good reason why `general_array_reverse` doesn't use `take`?
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org