fn order_aggregate_datums<'a, I>(
    datums: I,
    order_by: &[ColumnOrder],
) -> impl Iterator<Item = Datum<'a>>
where
    I: IntoIterator<Item = Datum<'a>>,
{
    let mut rows: Vec<(Datum, Row)> = datums
        .into_iter()
        .filter_map(|d| {
            let list = d.unwrap_list();
            let expr = list.iter().next().unwrap();
            let order_row = Row::pack(list.iter().skip(1));
            Some((expr, order_row))
        })
        .collect();

    let mut left_datum_vec = repr::DatumVec::new();
    let mut right_datum_vec = repr::DatumVec::new();
    let mut sort_by = |left: &(_, Row), right: &(_, Row)| {
        let left = &left.1;
        let right = &right.1;
        let left_datums = left_datum_vec.borrow_with(left);
        let right_datums = right_datum_vec.borrow_with(right);
        compare_columns(&order_by, &left_datums, &right_datums, || left.cmp(&right))
    };
    rows.sort_by(&mut sort_by);
    rows.into_iter().map(|(expr, _order_row)| expr)
}
// Assuming datums is a List, sort them by the 2nd through Nth elements
// corresponding to order_by, then return the 1st element.
Assuming datums is a List, sort them by the 2nd through Nth elements
corresponding to order_by, then return the 1st element.
Assuming datums is a List sort them by the 2nd through Nth elements corresponding to order_by then return the 1st element .
fn order_aggregate_datums<'a, I>(
    datums: I,
    order_by: &[ColumnOrder],
) -> impl Iterator<Item = Datum<'a>>
where
    I: IntoIterator<Item = Datum<'a>>,
{
    let mut rows: Vec<(Datum, Row)> = datums
        .into_iter()
        .filter_map(|d| {
            let list = d.unwrap_list();
            let expr = list.iter().next().unwrap();
            let order_row = Row::pack(list.iter().skip(1));
            Some((expr, order_row))
        })
        .collect();
    let mut left_datum_vec = repr::DatumVec::new();
    let mut right_datum_vec = repr::DatumVec::new();
    let mut sort_by = |left: &(_, Row), right: &(_, Row)| {
        let left = &left.1;
        let right = &right.1;
        let left_datums = left_datum_vec.borrow_with(left);
        let right_datums = right_datum_vec.borrow_with(right);
        compare_columns(&order_by, &left_datums, &right_datums, || left.cmp(&right))
    };
    rows.sort_by(&mut sort_by);
    rows.into_iter().map(|(expr, _order_row)| expr)
}
fn order_aggregate_datums < ' a , I > ( datums : I , order_by : & [ ColumnOrder ] , ) -> impl Iterator < Item = Datum < ' a > > where I : IntoIterator < Item = Datum < ' a > > , { let mut rows : Vec < ( Datum , Row ) > = datums . into_iter ( ) . filter_map ( | d | { let list = d . unwrap_list ( ) ; let expr = list . iter ( ) . next ( ) . unwrap ( ) ; let order_row = Row :: pack ( list . iter ( ) . skip ( 1 ) ) ; Some ( ( expr , order_row ) ) } ) . collect ( ) ; let mut left_datum_vec = repr :: DatumVec :: new ( ) ; let mut right_datum_vec = repr :: DatumVec :: new ( ) ; let mut sort_by = | left : & ( _ , Row ) , right : & ( _ , Row ) | { let left = & left . 1 ; let right = & right . 1 ; let left_datums = left_datum_vec . borrow_with ( left ) ; let right_datums = right_datum_vec . borrow_with ( right ) ; compare_columns ( & order_by , & left_datums , & right_datums , | | left . cmp ( & right ) ) } ; rows . sort_by ( & mut sort_by ) ; rows . into_iter ( ) . map ( | ( expr , _order_row ) | expr ) }
Assuming datums is a List, sort them by the 2nd through Nth elements
corresponding to order_by, then return the 1st element.
Assuming datums is a List sort them by the 2nd through Nth elements corresponding to order_by then return the 1st element .
datums
I
order_by
&[ColumnOrder]
datums
I
order_by
&[ColumnOrder]