felipecrv commented on code in PR #6969:
URL: https://github.com/apache/arrow-rs/pull/6969#discussion_r1957164663


##########
arrow-data/src/equal/list_view.rs:
##########
@@ -0,0 +1,73 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ArrayData;
+use arrow_buffer::ArrowNativeType;
+use num::Integer;
+
+use super::equal_range;
+
+pub(super) fn list_view_equal<T: ArrowNativeType + Integer>(
+    lhs: &ArrayData,
+    rhs: &ArrayData,
+    lhs_start: usize,
+    rhs_start: usize,
+    len: usize,
+) -> bool {
+    let lhs_offsets = lhs.buffer::<T>(0);
+    let rhs_offsets = rhs.buffer::<T>(0);
+    let lhs_sizes = lhs.buffer::<T>(1);
+    let rhs_sizes = rhs.buffer::<T>(1);
+    let lhs_nulls = lhs.nulls();
+    let rhs_nulls = rhs.nulls();
+    for i in 0..len {
+        let lhs_pos = lhs_start + i;
+        let rhs_pos = rhs_start + i;
+
+        // get offset and size
+        let lhs_offset_start = lhs_offsets[lhs_pos].to_usize().unwrap();
+        let rhs_offset_start = rhs_offsets[rhs_pos].to_usize().unwrap();
+        let lhs_size = lhs_sizes[lhs_pos].to_usize().unwrap();
+        let rhs_size = rhs_sizes[rhs_pos].to_usize().unwrap();
+
+        if lhs_size != rhs_size {
+            return false;
+        }
+
+        // check if null
+        if let (Some(lhs_null), Some(rhs_null)) = (lhs_nulls, rhs_nulls) {
+            if lhs_null.is_null(lhs_pos) != rhs_null.is_null(rhs_pos) {
+                return false;
+            }
+            if lhs_null.is_null(lhs_pos) {
+                continue;
+            }
+        }

Review Comment:
   Compare the validity buffers as the first step, then find the chunks of 
valid values and loop through them.
   
   Another trick could be find the longest contiguous chunk on both sides so 
that the `equal_range()` call can loop through very big chunks of values. If 
the list values are canonical (one after the other), only one call to 
`equal_range` will ever be done which is great for the CPU and very cache 
friendly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to