pub fn build_comparator<'a>(
    pairs: &'a [(&'a [&'a dyn Array], &SortOptions)],
) -> Result<Comparator<'a>> {
    // prepare the comparison function of _values_ between all pairs of arrays
    let indices_pairs = (0..pairs[0].0.len())
        .combinations(2)
        .map(|indices| (indices[0], indices[1]));

    let data = indices_pairs
        .map(|(lhs_index, rhs_index)| {
            let multi_column_comparator = pairs
                .iter()
                .map(move |(arrays, _)| {
                    Ok((
                        Box::new(move |row| arrays[lhs_index].is_valid(row)) as IsValid<'a>,
                        Box::new(move |row| arrays[rhs_index].is_valid(row)) as IsValid<'a>,
                        build_compare(arrays[lhs_index], arrays[rhs_index])?,
                    ))
                })
                .collect::<Result<Vec<_>>>()?;
            Ok(((lhs_index, rhs_index), multi_column_comparator))
        })
        .collect::<Result<HashMap<(usize, usize), Vec<(IsValid, IsValid, DynComparator)>>>>()?;

    // prepare a comparison function taking into account _nulls_ and sort options
    let cmp = move |left_index, left_row, right_index, right_row| {
        let data = data.get(&(left_index, right_index)).unwrap();
        //data.iter().zip(pairs.iter()).for_each()
        for c in 0..pairs.len() {
            let descending = pairs[c].1.descending;
            let null_first = pairs[c].1.nulls_first;
            let (l_is_valid, r_is_valid, value_comparator) = &data[c];
            let mut result = match ((l_is_valid)(left_row), (r_is_valid)(right_row)) {
                (true, true) => (value_comparator)(left_row, right_row),
                (false, true) => {
                    if null_first {
                        Ordering::Less
                    } else {
                        Ordering::Greater
                    }
                }
                (true, false) => {
                    if null_first {
                        Ordering::Greater
                    } else {
                        Ordering::Less
                    }
                }
                (false, false) => Ordering::Equal,
            };
            if descending {
                result = result.reverse();
            };
            if result != Ordering::Equal {
                // we found a relevant comparison => short-circuit and return it
                return result;
            }
        }
        Ordering::Equal
    };
    Ok(Box::new(cmp))
}
/// returns a comparison function between any two arrays of each pair of arrays, according to `SortOptions`.
returns a comparison function between any two arrays of each pair of arrays, according to `SortOptions`.
returns a comparison function between any two arrays of each pair of arrays according to ` SortOptions ` .
pub fn build_comparator<'a>(
    pairs: &'a [(&'a [&'a dyn Array], &SortOptions)],
) -> Result<Comparator<'a>> {
    // prepare the comparison function of _values_ between all pairs of arrays
    let indices_pairs = (0..pairs[0].0.len())
        .combinations(2)
        .map(|indices| (indices[0], indices[1]));
    let data = indices_pairs
        .map(|(lhs_index, rhs_index)| {
            let multi_column_comparator = pairs
                .iter()
                .map(move |(arrays, _)| {
                    Ok((
                        Box::new(move |row| arrays[lhs_index].is_valid(row)) as IsValid<'a>,
                        Box::new(move |row| arrays[rhs_index].is_valid(row)) as IsValid<'a>,
                        build_compare(arrays[lhs_index], arrays[rhs_index])?,
                    ))
                })
                .collect::<Result<Vec<_>>>()?;
            Ok(((lhs_index, rhs_index), multi_column_comparator))
        })
        .collect::<Result<HashMap<(usize, usize), Vec<(IsValid, IsValid, DynComparator)>>>>()?;
    // prepare a comparison function taking into account _nulls_ and sort options
    let cmp = move |left_index, left_row, right_index, right_row| {
        let data = data.get(&(left_index, right_index)).unwrap();
        //data.iter().zip(pairs.iter()).for_each()
        for c in 0..pairs.len() {
            let descending = pairs[c].1.descending;
            let null_first = pairs[c].1.nulls_first;
            let (l_is_valid, r_is_valid, value_comparator) = &data[c];
            let mut result = match ((l_is_valid)(left_row), (r_is_valid)(right_row)) {
                (true, true) => (value_comparator)(left_row, right_row),
                (false, true) => {
                    if null_first {
                        Ordering::Less
                    } else {
                        Ordering::Greater
                    }
                }
                (true, false) => {
                    if null_first {
                        Ordering::Greater
                    } else {
                        Ordering::Less
                    }
                }
                (false, false) => Ordering::Equal,
            };
            if descending {
                result = result.reverse();
            };
            if result != Ordering::Equal {
                // we found a relevant comparison => short-circuit and return it
                return result;
            }
        }
        Ordering::Equal
    };
    Ok(Box::new(cmp))
}
pub fn build_comparator < ' a > ( pairs : & ' a [ ( & ' a [ & ' a dyn Array ] , & SortOptions ) ] , ) -> Result < Comparator < ' a > > { // prepare the comparison function of _values_ between all pairs of arrays let indices_pairs = ( 0 .. pairs [ 0 ] . 0 . len ( ) ) . combinations ( 2 ) . map ( | indices | ( indices [ 0 ] , indices [ 1 ] ) ) ; let data = indices_pairs . map ( | ( lhs_index , rhs_index ) | { let multi_column_comparator = pairs . iter ( ) . map ( move | ( arrays , _ ) | { Ok ( ( Box :: new ( move | row | arrays [ lhs_index ] . is_valid ( row ) ) as IsValid < ' a > , Box :: new ( move | row | arrays [ rhs_index ] . is_valid ( row ) ) as IsValid < ' a > , build_compare ( arrays [ lhs_index ] , arrays [ rhs_index ] ) ? , ) ) } ) . collect :: < Result < Vec < _ > > > ( ) ? ; Ok ( ( ( lhs_index , rhs_index ) , multi_column_comparator ) ) } ) . collect :: < Result < HashMap < ( usize , usize ) , Vec < ( IsValid , IsValid , DynComparator ) > > > > ( ) ? ; // prepare a comparison function taking into account _nulls_ and sort options let cmp = move | left_index , left_row , right_index , right_row | { let data = data . get ( & ( left_index , right_index ) ) . unwrap ( ) ; //data.iter().zip(pairs.iter()).for_each() for c in 0 .. pairs . len ( ) { let descending = pairs [ c ] . 1 . descending ; let null_first = pairs [ c ] . 1 . nulls_first ; let ( l_is_valid , r_is_valid , value_comparator ) = & data [ c ] ; let mut result = match ( ( l_is_valid ) ( left_row ) , ( r_is_valid ) ( right_row ) ) { ( true , true ) => ( value_comparator ) ( left_row , right_row ) , ( false , true ) => { if null_first { Ordering :: Less } else { Ordering :: Greater } } ( true , false ) => { if null_first { Ordering :: Greater } else { Ordering :: Less } } ( false , false ) => Ordering :: Equal , } ; if descending { result = result . reverse ( ) ; } ; if result != Ordering :: Equal { // we found a relevant comparison => short-circuit and return it return result ; } } Ordering :: Equal } ; Ok ( Box :: new ( cmp ) ) }
returns a comparison function between any two arrays of each pair of arrays, according to `SortOptions`.
returns a comparison function between any two arrays of each pair of arrays according to ` SortOptions ` .
pairs
&'a [(&'a [&'a dyn Array], &SortOptions)]
pairs
&'a [(&'a [&'a dyn Array], &SortOptions)]