fn build(
        columns: &mut HashMap<usize, usize>,
        equivalences: &mut Vec<Vec<MirScalarExpr>>,
        mfp: &mut MapFilterProject,
    ) -> Self {
        // First, determine which columns should be compared due to `equivalences`.
        let mut ready_equivalences = Vec::new();
        for equivalence in equivalences.iter_mut() {
            if let Some(pos) = equivalence
                .iter()
                .position(|e| e.support().into_iter().all(|c| columns.contains_key(&c)))
            {
                let mut should_equate = Vec::new();
                let mut cursor = pos + 1;
                while cursor < equivalence.len() {
                    if equivalence[cursor]
                        .support()
                        .into_iter()
                        .all(|c| columns.contains_key(&c))
                    {
                        // Remove expression and equate with the first bound expression.
                        should_equate.push(equivalence.remove(cursor));
                    } else {
                        cursor += 1;
                    }
                }
                if !should_equate.is_empty() {
                    should_equate.push(equivalence[pos].clone());
                    ready_equivalences.push(should_equate);
                }
            }
        }
        equivalences.retain(|e| e.len() > 1);

        // Update ready_equivalences to reference correct column locations.
        for exprs in ready_equivalences.iter_mut() {
            for expr in exprs.iter_mut() {
                expr.permute_map(&columns);
            }
        }

        // Next, partition `mfp` into `before` and `after`, the former of which can be
        // applied now.
        let (mut before, after) = std::mem::replace(mfp, MapFilterProject::new(mfp.input_arity))
            .partition(columns.clone(), columns.len());

        // Add any newly created columns to `columns`. These columns may be referenced
        // by `after`, and it will be important to track their locations.
        let bonus_columns = before.projection.len() - before.input_arity;
        for bonus_column in 0..bonus_columns {
            columns.insert(mfp.input_arity + bonus_column, columns.len());
        }

        *mfp = after;

        // Before constructing and returning the result, we can remove output columns of `before`
        // that are not needed in further `equivalences` or by `after` (now `mfp`).
        let mut demand = Vec::new();
        demand.extend(mfp.demand());
        for equivalence in equivalences.iter() {
            for expr in equivalence.iter() {
                demand.extend(expr.support());
            }
        }
        demand.sort();
        demand.dedup();
        // We only want to remove columns that are presented as outputs (i.e. can be found as in
        // `columns`). Other columns have yet to be introduced, and we shouldn't have any opinion
        // about them yet.
        demand.retain(|column| columns.contains_key(column));
        // Project `before` output columns using current locations of demanded columns.
        before = before.project(demand.iter().map(|column| columns[column]));
        // Update `columns` to reflect location of retained columns.
        columns.clear();
        for (index, column) in demand.iter().enumerate() {
            columns.insert(*column, index);
        }

        // If `mfp` is a permutation of the columns present in `columns`, then we can
        // apply that permutation to `before` and `columns`, so that `mfp` becomes the
        // identity operation.
        if mfp.expressions.is_empty()
            && mfp.predicates.is_empty()
            && mfp.projection.len() == columns.len()
            && mfp.projection.iter().all(|col| columns.contains_key(col))
            && columns.keys().all(|col| mfp.projection.contains(col))
        {
            // The projection we want to apply to `before`  comes to us from `mfp` in the
            // extended output column reckoning.
            let projection = mfp
                .projection
                .iter()
                .map(|col| columns[col])
                .collect::<Vec<_>>();
            before = before.project(projection);
            // Update the physical locations of each output column.
            columns.clear();
            for (index, column) in mfp.projection.iter().enumerate() {
                columns.insert(*column, index);
            }
        }

        // `before` should not be modified after this point.
        before.optimize();

        // Cons up an instance of the closure with the closed-over state.
        Self {
            ready_equivalences,
            before: before.into_plan().unwrap().into_nontemporal().unwrap(),
        }
    }
/// Construct an instance of the closure from available columns.
///
/// This method updates the available columns, equivalences, and
/// the `MapFilterProject` instance. The columns are updated to
/// include reference to any columns added by the application of
/// this logic, which might result from partial application of
/// the `MapFilterProject` instance.
///
/// If all columns are available for `mfp`, this method works
/// extra hard to ensure that the closure contains all the work,
/// and `mfp` is left as an identity transform (which can then
/// be ignored).
Construct an instance of the closure from available columns.
This method updates the available columns, equivalences, and
the `MapFilterProject` instance. The columns are updated to
include reference to any columns added by the application of
this logic, which might result from partial application of
the `MapFilterProject` instance.

If all columns are available for `mfp`, this method works
extra hard to ensure that the closure contains all the work,
and `mfp` is left as an identity transform (which can then
be ignored).
Construct an instance of the closure from available columns . This method updates the available columns equivalences and the ` MapFilterProject ` instance . The columns are updated to include reference to any columns added by the application of this logic which might result from partial application of the ` MapFilterProject ` instance . If all columns are available for ` mfp ` this method works extra hard to ensure that the closure contains all the work and ` mfp ` is left as an identity transform ( which can then be ignored ) .
fn build(
        columns: &mut HashMap<usize, usize>,
        equivalences: &mut Vec<Vec<MirScalarExpr>>,
        mfp: &mut MapFilterProject,
    ) -> Self {
        // First, determine which columns should be compared due to `equivalences`.
        let mut ready_equivalences = Vec::new();
        for equivalence in equivalences.iter_mut() {
            if let Some(pos) = equivalence
                .iter()
                .position(|e| e.support().into_iter().all(|c| columns.contains_key(&c)))
            {
                let mut should_equate = Vec::new();
                let mut cursor = pos + 1;
                while cursor < equivalence.len() {
                    if equivalence[cursor]
                        .support()
                        .into_iter()
                        .all(|c| columns.contains_key(&c))
                    {
                        // Remove expression and equate with the first bound expression.
                        should_equate.push(equivalence.remove(cursor));
                    } else {
                        cursor += 1;
                    }
                }
                if !should_equate.is_empty() {
                    should_equate.push(equivalence[pos].clone());
                    ready_equivalences.push(should_equate);
                }
            }
        }
        equivalences.retain(|e| e.len() > 1);
        // Update ready_equivalences to reference correct column locations.
        for exprs in ready_equivalences.iter_mut() {
            for expr in exprs.iter_mut() {
                expr.permute_map(&columns);
            }
        }
        // Next, partition `mfp` into `before` and `after`, the former of which can be
        // applied now.
        let (mut before, after) = std::mem::replace(mfp, MapFilterProject::new(mfp.input_arity))
            .partition(columns.clone(), columns.len());
        // Add any newly created columns to `columns`. These columns may be referenced
        // by `after`, and it will be important to track their locations.
        let bonus_columns = before.projection.len() - before.input_arity;
        for bonus_column in 0..bonus_columns {
            columns.insert(mfp.input_arity + bonus_column, columns.len());
        }
        *mfp = after;
        // Before constructing and returning the result, we can remove output columns of `before`
        // that are not needed in further `equivalences` or by `after` (now `mfp`).
        let mut demand = Vec::new();
        demand.extend(mfp.demand());
        for equivalence in equivalences.iter() {
            for expr in equivalence.iter() {
                demand.extend(expr.support());
            }
        }
        demand.sort();
        demand.dedup();
        // We only want to remove columns that are presented as outputs (i.e. can be found as in
        // `columns`). Other columns have yet to be introduced, and we shouldn't have any opinion
        // about them yet.
        demand.retain(|column| columns.contains_key(column));
        // Project `before` output columns using current locations of demanded columns.
        before = before.project(demand.iter().map(|column| columns[column]));
        // Update `columns` to reflect location of retained columns.
        columns.clear();
        for (index, column) in demand.iter().enumerate() {
            columns.insert(*column, index);
        }
        // If `mfp` is a permutation of the columns present in `columns`, then we can
        // apply that permutation to `before` and `columns`, so that `mfp` becomes the
        // identity operation.
        if mfp.expressions.is_empty()
            && mfp.predicates.is_empty()
            && mfp.projection.len() == columns.len()
            && mfp.projection.iter().all(|col| columns.contains_key(col))
            && columns.keys().all(|col| mfp.projection.contains(col))
        {
            // The projection we want to apply to `before`  comes to us from `mfp` in the
            // extended output column reckoning.
            let projection = mfp
                .projection
                .iter()
                .map(|col| columns[col])
                .collect::<Vec<_>>();
            before = before.project(projection);
            // Update the physical locations of each output column.
            columns.clear();
            for (index, column) in mfp.projection.iter().enumerate() {
                columns.insert(*column, index);
            }
        }
        // `before` should not be modified after this point.
        before.optimize();
        // Cons up an instance of the closure with the closed-over state.
        Self {
            ready_equivalences,
            before: before.into_plan().unwrap().into_nontemporal().unwrap(),
        }
    }
fn build ( columns : & mut HashMap < usize , usize > , equivalences : & mut Vec < Vec < MirScalarExpr > > , mfp : & mut MapFilterProject , ) -> Self { // First, determine which columns should be compared due to `equivalences`. let mut ready_equivalences = Vec :: new ( ) ; for equivalence in equivalences . iter_mut ( ) { if let Some ( pos ) = equivalence . iter ( ) . position ( | e | e . support ( ) . into_iter ( ) . all ( | c | columns . contains_key ( & c ) ) ) { let mut should_equate = Vec :: new ( ) ; let mut cursor = pos + 1 ; while cursor < equivalence . len ( ) { if equivalence [ cursor ] . support ( ) . into_iter ( ) . all ( | c | columns . contains_key ( & c ) ) { // Remove expression and equate with the first bound expression. should_equate . push ( equivalence . remove ( cursor ) ) ; } else { cursor += 1 ; } } if ! should_equate . is_empty ( ) { should_equate . push ( equivalence [ pos ] . clone ( ) ) ; ready_equivalences . push ( should_equate ) ; } } } equivalences . retain ( | e | e . len ( ) > 1 ) ; // Update ready_equivalences to reference correct column locations. for exprs in ready_equivalences . iter_mut ( ) { for expr in exprs . iter_mut ( ) { expr . permute_map ( & columns ) ; } } // Next, partition `mfp` into `before` and `after`, the former of which can be // applied now. let ( mut before , after ) = std :: mem :: replace ( mfp , MapFilterProject :: new ( mfp . input_arity ) ) . partition ( columns . clone ( ) , columns . len ( ) ) ; // Add any newly created columns to `columns`. These columns may be referenced // by `after`, and it will be important to track their locations. let bonus_columns = before . projection . len ( ) - before . input_arity ; for bonus_column in 0 .. bonus_columns { columns . insert ( mfp . input_arity + bonus_column , columns . len ( ) ) ; } * mfp = after ; // Before constructing and returning the result, we can remove output columns of `before` // that are not needed in further `equivalences` or by `after` (now `mfp`). let mut demand = Vec :: new ( ) ; demand . extend ( mfp . demand ( ) ) ; for equivalence in equivalences . iter ( ) { for expr in equivalence . iter ( ) { demand . extend ( expr . support ( ) ) ; } } demand . sort ( ) ; demand . dedup ( ) ; // We only want to remove columns that are presented as outputs (i.e. can be found as in // `columns`). Other columns have yet to be introduced, and we shouldn't have any opinion // about them yet. demand . retain ( | column | columns . contains_key ( column ) ) ; // Project `before` output columns using current locations of demanded columns. before = before . project ( demand . iter ( ) . map ( | column | columns [ column ] ) ) ; // Update `columns` to reflect location of retained columns. columns . clear ( ) ; for ( index , column ) in demand . iter ( ) . enumerate ( ) { columns . insert ( * column , index ) ; } // If `mfp` is a permutation of the columns present in `columns`, then we can // apply that permutation to `before` and `columns`, so that `mfp` becomes the // identity operation. if mfp . expressions . is_empty ( ) && mfp . predicates . is_empty ( ) && mfp . projection . len ( ) == columns . len ( ) && mfp . projection . iter ( ) . all ( | col | columns . contains_key ( col ) ) && columns . keys ( ) . all ( | col | mfp . projection . contains ( col ) ) { // The projection we want to apply to `before`  comes to us from `mfp` in the // extended output column reckoning. let projection = mfp . projection . iter ( ) . map ( | col | columns [ col ] ) . collect :: < Vec < _ > > ( ) ; before = before . project ( projection ) ; // Update the physical locations of each output column. columns . clear ( ) ; for ( index , column ) in mfp . projection . iter ( ) . enumerate ( ) { columns . insert ( * column , index ) ; } } // `before` should not be modified after this point. before . optimize ( ) ; // Cons up an instance of the closure with the closed-over state. Self { ready_equivalences , before : before . into_plan ( ) . unwrap ( ) . into_nontemporal ( ) . unwrap ( ) , } }
Construct an instance of the closure from available columns.
Construct an instance of the closure from available columns .
columns
&mut HashMap<usize, usize>
equivalences
&mut Vec<Vec<MirScalarExpr>>
mfp
&mut MapFilterProject
columns
&mut HashMap<usize, usize>
equivalences
&mut Vec<Vec<MirScalarExpr>>
mfp
&mut MapFilterProject