This is an automated email from the ASF dual-hosted git repository.

jeffreyvo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 253c5419b9 feat: add ListView and LargeListView support to arrow-ord 
(#9347)
253c5419b9 is described below

commit 253c5419b9378e05f29b66a1964db642f136286a
Author: Yan Tingwang <[email protected]>
AuthorDate: Thu Feb 5 11:23:42 2026 +0800

    feat: add ListView and LargeListView support to arrow-ord (#9347)
    
    # Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax.
    -->
     Closes #9341.
    
    # Rationale for this change
    arrow-ord doesnot support ListView
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    -->
    
    # What changes are included in this PR?
    add ListView/LargeListView support to the arrow-ord module
    <!--
    There is no need to duplicate the description in the issue here but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    # Are these changes tested?
    
    Yes, all changes are thoroughly tested
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    -->
    
    # Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please call them out.
    -->
    New APIs:
    
    ```
    arrow_ord::comparison::in_list_view() - Check if primitive array values 
exist in a ListView array
    arrow_ord::comparison::in_list_view_utf8() - Check if string array values 
exist in a ListView array
    ```
    
    Enhanced Functionality:
    
    ```
    arrow_ord::sort::sort_to_indices() now supports ListView and LargeListView 
types
    arrow_ord::sort::sort() now supports ListView and LargeListView types
    ```
---
 arrow-ord/src/sort.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/arrow-ord/src/sort.rs b/arrow-ord/src/sort.rs
index f7f553abb6..773d9cf12e 100644
--- a/arrow-ord/src/sort.rs
+++ b/arrow-ord/src/sort.rs
@@ -256,7 +256,9 @@ fn can_sort_to_indices(data_type: &DataType) -> bool {
         )
         || match data_type {
             DataType::List(f) if can_rank(f.data_type()) => true,
+            DataType::ListView(f) if can_rank(f.data_type()) => true,
             DataType::LargeList(f) if can_rank(f.data_type()) => true,
+            DataType::LargeListView(f) if can_rank(f.data_type()) => true,
             DataType::FixedSizeList(f, _) if can_rank(f.data_type()) => true,
             DataType::Dictionary(_, values) if can_rank(values.as_ref()) => 
true,
             DataType::RunEndEncoded(_, f) if 
can_sort_to_indices(f.data_type()) => true,
@@ -286,7 +288,9 @@ pub fn sort_to_indices(
         DataType::BinaryView => sort_byte_view(array.as_binary_view(), v, n, 
options, limit),
         DataType::FixedSizeBinary(_) => 
sort_fixed_size_binary(array.as_fixed_size_binary(), v, n, options, limit),
         DataType::List(_) => sort_list(array.as_list::<i32>(), v, n, options, 
limit)?,
+        DataType::ListView(_) => sort_list_view(array.as_list_view::<i32>(), 
v, n, options, limit)?,
         DataType::LargeList(_) => sort_list(array.as_list::<i64>(), v, n, 
options, limit)?,
+        DataType::LargeListView(_) => 
sort_list_view(array.as_list_view::<i64>(), v, n, options, limit)?,
         DataType::FixedSizeList(_, _) => 
sort_fixed_size_list(array.as_fixed_size_list(), v, n, options, limit)?,
         DataType::Dictionary(_, _) => downcast_dictionary_array!{
             array => sort_dictionary(array, v, n, options, limit)?,
@@ -581,6 +585,28 @@ fn sort_list<O: OffsetSizeTrait>(
     Ok(sort_impl(options, &mut valids, &null_indices, limit, Ord::cmp).into())
 }
 
+fn sort_list_view<O: OffsetSizeTrait>(
+    array: &GenericListViewArray<O>,
+    value_indices: Vec<u32>,
+    null_indices: Vec<u32>,
+    options: SortOptions,
+    limit: Option<usize>,
+) -> Result<UInt32Array, ArrowError> {
+    let rank = child_rank(array.values().as_ref(), options)?;
+    let offsets = array.offsets();
+    let sizes = array.sizes();
+    let mut valids = value_indices
+        .into_iter()
+        .map(|index| {
+            let start = offsets[index as usize].as_usize();
+            let size = sizes[index as usize].as_usize();
+            let end = start + size;
+            (index, &rank[start..end])
+        })
+        .collect::<Vec<(u32, &[u32])>>();
+    Ok(sort_impl(options, &mut valids, &null_indices, limit, Ord::cmp).into())
+}
+
 fn sort_fixed_size_list(
     array: &FixedSizeListArray,
     value_indices: Vec<u32>,
@@ -1373,16 +1399,37 @@ mod tests {
 
         assert_eq!(&sorted, &expected);
 
+        // for ListView
+        let input = Arc::new(ListViewArray::from_iter_primitive::<T, _, 
_>(data.clone()));
+        let sorted = match limit {
+            Some(_) => sort_limit(&(input as ArrayRef), options, 
limit).unwrap(),
+            _ => sort(&(input as ArrayRef), options).unwrap(),
+        };
+        let expected = Arc::new(ListViewArray::from_iter_primitive::<T, _, _>(
+            expected_data.clone(),
+        )) as ArrayRef;
+        assert_eq!(&sorted, &expected);
+
         // for LargeList
-        let input = Arc::new(LargeListArray::from_iter_primitive::<T, _, 
_>(data));
+        let input = Arc::new(LargeListArray::from_iter_primitive::<T, _, 
_>(data.clone()));
         let sorted = match limit {
             Some(_) => sort_limit(&(input as ArrayRef), options, 
limit).unwrap(),
             _ => sort(&(input as ArrayRef), options).unwrap(),
         };
         let expected = Arc::new(LargeListArray::from_iter_primitive::<T, _, _>(
-            expected_data,
+            expected_data.clone(),
         )) as ArrayRef;
+        assert_eq!(&sorted, &expected);
 
+        // for LargeListView
+        let input = Arc::new(LargeListViewArray::from_iter_primitive::<T, _, 
_>(data));
+        let sorted = match limit {
+            Some(_) => sort_limit(&(input as ArrayRef), options, 
limit).unwrap(),
+            _ => sort(&(input as ArrayRef), options).unwrap(),
+        };
+        let expected = Arc::new(LargeListViewArray::from_iter_primitive::<T, 
_, _>(
+            expected_data,
+        )) as ArrayRef;
         assert_eq!(&sorted, &expected);
     }
 

Reply via email to