jayzhan211 commented on code in PR #5408:
URL: https://github.com/apache/arrow-rs/pull/5408#discussion_r1495985778


##########
arrow-ord/src/cmp.rs:
##########
@@ -166,6 +169,83 @@ pub fn not_distinct(lhs: &dyn Datum, rhs: &dyn Datum) -> 
Result<BooleanArray, Ar
     compare_op(Op::NotDistinct, lhs, rhs)
 }
 
+pub fn compare_list(l: ArrayRef, r: ArrayRef) -> Ordering {
+    let l_t = l.data_type();
+    let r_t = r.data_type();
+    let l_len = l.len();
+    let r_len = r.len();
+    let min_len = std::cmp::min(l_len, r_len);
+
+    let cmp = if let (DataType::List(_), DataType::List(_)) = (l_t, r_t) {
+        let l = l.as_list::<i32>();
+        let r = r.as_list::<i32>();
+
+        Box::new(move |i, j| compare_list(l.value(i), r.value(j)))

Review Comment:
   I got a lifetime error when moving this to fn that returns Dyncompartor. To 
avoid getting it to complex, I leave it here.
   ```rust
   error: lifetime may not live long enough
     --> arrow-ord/src/ord.rs:36:9
      |
   32 | fn compare_ist(l: &dyn Array, r: &dyn Array) -> DynComparator {
      |                                  - let's call the lifetime of this 
reference `'2`
   ...
   36 |         Box::new(move |i, j| compare_list(l.value(i), r.value(j)))
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
returning this value requires that `'2` must outlive `'static`
      |
   help: to declare that the trait object captures data from argument `r`, you 
can add a lifetime parameter `'a` in the type alias
      |
   30 | pub type DynComparator<'a> = Box<dyn Fn(usize, usize) -> Ordering + 
Send + Sync + 'a>;
      |                       ++++                                              
        ++++
   
   error: could not compile `arrow-ord` (lib test) due to 2 previous errors
   ```



##########
arrow-ord/src/cmp.rs:
##########
@@ -166,6 +169,83 @@ pub fn not_distinct(lhs: &dyn Datum, rhs: &dyn Datum) -> 
Result<BooleanArray, Ar
     compare_op(Op::NotDistinct, lhs, rhs)
 }
 
+pub fn compare_list(l: ArrayRef, r: ArrayRef) -> Ordering {
+    let l_t = l.data_type();
+    let r_t = r.data_type();
+    let l_len = l.len();
+    let r_len = r.len();
+    let min_len = std::cmp::min(l_len, r_len);
+
+    let cmp = if let (DataType::List(_), DataType::List(_)) = (l_t, r_t) {
+        let l = l.as_list::<i32>();
+        let r = r.as_list::<i32>();
+
+        Box::new(move |i, j| compare_list(l.value(i), r.value(j)))

Review Comment:
   I got a lifetime error when moving this to fn that returns Dyncompartor. To 
avoid getting it too complex, I leave it here.
   ```rust
   error: lifetime may not live long enough
     --> arrow-ord/src/ord.rs:36:9
      |
   32 | fn compare_ist(l: &dyn Array, r: &dyn Array) -> DynComparator {
      |                                  - let's call the lifetime of this 
reference `'2`
   ...
   36 |         Box::new(move |i, j| compare_list(l.value(i), r.value(j)))
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
returning this value requires that `'2` must outlive `'static`
      |
   help: to declare that the trait object captures data from argument `r`, you 
can add a lifetime parameter `'a` in the type alias
      |
   30 | pub type DynComparator<'a> = Box<dyn Fn(usize, usize) -> Ordering + 
Send + Sync + 'a>;
      |                       ++++                                              
        ++++
   
   error: could not compile `arrow-ord` (lib test) due to 2 previous errors
   ```



-- 
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