@@ -7,7 +7,7 @@ use std::fmt::{Display, Formatter};
77use std:: sync:: LazyLock ;
88
99use arcref:: ArcRef ;
10- use arrow_array:: { BooleanArray , Datum as ArrowDatum } ;
10+ use arrow_array:: BooleanArray ;
1111use arrow_buffer:: NullBuffer ;
1212use arrow_ord:: cmp;
1313use arrow_ord:: ord:: make_comparator;
@@ -18,7 +18,7 @@ use vortex_error::{VortexError, VortexExpect, VortexResult, vortex_bail, vortex_
1818use vortex_scalar:: Scalar ;
1919
2020use crate :: arrays:: ConstantArray ;
21- use crate :: arrow:: { Datum , from_arrow_array_with_len} ;
21+ use crate :: arrow:: { Datum , IntoArrowArray , from_arrow_array_with_len} ;
2222use crate :: compute:: { ComputeFn , ComputeFnVTable , InvocationArgs , Kernel , Options , Output } ;
2323use crate :: vtable:: VTable ;
2424use crate :: { Array , ArrayRef , Canonical , IntoArray } ;
@@ -295,17 +295,12 @@ fn arrow_compare(
295295 operator : Operator ,
296296) -> VortexResult < ArrayRef > {
297297 assert_eq ! ( left. len( ) , right. len( ) ) ;
298- let len = left. len ( ) ;
299298
300299 let nullable = left. dtype ( ) . is_nullable ( ) || right. dtype ( ) . is_nullable ( ) ;
301300
302301 let array = if left. dtype ( ) . is_nested ( ) || right. dtype ( ) . is_nested ( ) {
303- let rhs = Datum :: try_new_array ( & right. to_canonical ( ) . into_array ( ) ) ?;
304- let ( rhs, _) = rhs. get ( ) ;
305-
306- // prefer the rhs data type since this is usually used in assert_eq!(actual, expect).
307- let lhs = Datum :: with_target_datatype ( & left. to_canonical ( ) . into_array ( ) , rhs. data_type ( ) ) ?;
308- let ( lhs, _) = lhs. get ( ) ;
302+ let rhs = right. to_array ( ) . into_arrow_preferred ( ) ?;
303+ let lhs = left. to_array ( ) . into_arrow ( rhs. data_type ( ) ) ?;
309304
310305 assert ! (
311306 lhs. data_type( ) . equals_datatype( rhs. data_type( ) ) ,
@@ -314,7 +309,8 @@ fn arrow_compare(
314309 rhs. data_type( )
315310 ) ;
316311
317- let cmp = make_comparator ( lhs, rhs, SortOptions :: default ( ) ) ?;
312+ let cmp = make_comparator ( lhs. as_ref ( ) , rhs. as_ref ( ) , SortOptions :: default ( ) ) ?;
313+ let len = left. len ( ) ;
318314 let values = ( 0 ..len)
319315 . map ( |i| {
320316 let cmp = cmp ( i, i) ;
@@ -366,13 +362,14 @@ pub fn scalar_cmp(lhs: &Scalar, rhs: &Scalar, operator: Operator) -> Scalar {
366362#[ cfg( test) ]
367363mod tests {
368364 use rstest:: rstest;
365+ use vortex_buffer:: buffer;
369366 use vortex_dtype:: { FieldName , FieldNames } ;
370367
371368 use super :: * ;
372369 use crate :: ToCanonical ;
373370 use crate :: arrays:: {
374- BoolArray , ConstantArray , ListArray , PrimitiveArray , StructArray , VarBinArray ,
375- VarBinViewArray ,
371+ BoolArray , ConstantArray , ListArray , ListViewArray , PrimitiveArray , StructArray ,
372+ VarBinArray , VarBinViewArray ,
376373 } ;
377374 use crate :: test_harness:: to_int_indices;
378375 use crate :: validity:: Validity ;
@@ -600,4 +597,20 @@ mod tests {
600597 assert ! ( result. bit_buffer( ) . value( idx) ) ;
601598 }
602599 }
600+
601+ #[ test]
602+ fn test_empty_list ( ) {
603+ let list = ListViewArray :: new (
604+ BoolArray :: from_iter ( Vec :: < bool > :: new ( ) ) . into_array ( ) ,
605+ buffer ! [ 0i32 , 0i32 , 0i32 ] . into_array ( ) ,
606+ buffer ! [ 0i32 , 0i32 , 0i32 ] . into_array ( ) ,
607+ Validity :: AllValid ,
608+ ) ;
609+
610+ // Compare two lists together
611+ let result = compare ( list. as_ref ( ) , list. as_ref ( ) , Operator :: Eq ) . unwrap ( ) ;
612+ assert ! ( result. scalar_at( 0 ) . is_valid( ) ) ;
613+ assert ! ( result. scalar_at( 1 ) . is_valid( ) ) ;
614+ assert ! ( result. scalar_at( 2 ) . is_valid( ) ) ;
615+ }
603616}
0 commit comments