pub fn optimize_dataflow_demand_inner<'a, I>(
    view_sequence: I,
    demand: &mut HashMap<Id, BTreeSet<usize>>,
) -> Result<(), TransformError>
where
    I: Iterator<Item = (Id, &'a mut MirRelationExpr)>,
{
    // Maps id -> The projection that was pushed down on the view with the
    // corresponding id.
    let mut applied_projection = HashMap::new();
    // Collect the mutable references to views after pushing projection down
    // in order to run cleanup actions on them in a second loop.
    let mut view_refs = Vec::new();
    let projection_pushdown = crate::projection_pushdown::ProjectionPushdown;
    for (id, view) in view_sequence {
        if let Some(columns) = demand.get(&id) {
            let projection_pushed_down = columns.iter().map(|c| *c).collect();
            // Push down the projection consisting of the entries of `columns`
            // in increasing order.
            projection_pushdown.action(view, &projection_pushed_down, demand);
            applied_projection.insert(id, projection_pushed_down);
        } else if id == Id::Global(GlobalId::Explain) {
            // If we just want to explain the plan for a given view, then there
            // will be no upstream demand. Just demand all columns from views
            // that are not depended on by another view.
            let arity = view.arity();
            projection_pushdown.action(view, &(0..arity).collect(), demand);
        }
        view_refs.push(view);
    }

    let typ_update = crate::update_let::UpdateLet::default();
    for view in view_refs {
        // Update column references to views where projections were pushed down.
        projection_pushdown.update_projection_around_get(view, &applied_projection);
        // Types need to be updated after ProjectionPushdown
        // because the width of each view may have changed.
        typ_update.action(view, &mut HashMap::new(), &mut IdGen::default())?;
    }

    Ok(())
}
/// Pushes demand through views in `view_sequence` in order, removing
/// columns not demanded.
///
/// This method is made public for the sake of testing.
/// TODO: make this private once we allow multiple exports per dataflow.
Pushes demand through views in `view_sequence` in order, removing
columns not demanded.

This method is made public for the sake of testing.
TODO: make this private once we allow multiple exports per dataflow.
Pushes demand through views in ` view_sequence ` in order removing columns not demanded . This method is made public for the sake of testing . TODO : make this private once we allow multiple exports per dataflow .
pub fn optimize_dataflow_demand_inner<'a, I>(
    view_sequence: I,
    demand: &mut HashMap<Id, BTreeSet<usize>>,
) -> Result<(), TransformError>
where
    I: Iterator<Item = (Id, &'a mut MirRelationExpr)>,
{
    // Maps id -> The projection that was pushed down on the view with the
    // corresponding id.
    let mut applied_projection = HashMap::new();
    // Collect the mutable references to views after pushing projection down
    // in order to run cleanup actions on them in a second loop.
    let mut view_refs = Vec::new();
    let projection_pushdown = crate::projection_pushdown::ProjectionPushdown;
    for (id, view) in view_sequence {
        if let Some(columns) = demand.get(&id) {
            let projection_pushed_down = columns.iter().map(|c| *c).collect();
            // Push down the projection consisting of the entries of `columns`
            // in increasing order.
            projection_pushdown.action(view, &projection_pushed_down, demand);
            applied_projection.insert(id, projection_pushed_down);
        } else if id == Id::Global(GlobalId::Explain) {
            // If we just want to explain the plan for a given view, then there
            // will be no upstream demand. Just demand all columns from views
            // that are not depended on by another view.
            let arity = view.arity();
            projection_pushdown.action(view, &(0..arity).collect(), demand);
        }
        view_refs.push(view);
    }
    let typ_update = crate::update_let::UpdateLet::default();
    for view in view_refs {
        // Update column references to views where projections were pushed down.
        projection_pushdown.update_projection_around_get(view, &applied_projection);
        // Types need to be updated after ProjectionPushdown
        // because the width of each view may have changed.
        typ_update.action(view, &mut HashMap::new(), &mut IdGen::default())?;
    }
    Ok(())
}
pub fn optimize_dataflow_demand_inner < ' a , I > ( view_sequence : I , demand : & mut HashMap < Id , BTreeSet < usize > > , ) -> Result < ( ) , TransformError > where I : Iterator < Item = ( Id , & ' a mut MirRelationExpr ) > , { // Maps id -> The projection that was pushed down on the view with the // corresponding id. let mut applied_projection = HashMap :: new ( ) ; // Collect the mutable references to views after pushing projection down // in order to run cleanup actions on them in a second loop. let mut view_refs = Vec :: new ( ) ; let projection_pushdown = crate :: projection_pushdown :: ProjectionPushdown ; for ( id , view ) in view_sequence { if let Some ( columns ) = demand . get ( & id ) { let projection_pushed_down = columns . iter ( ) . map ( | c | * c ) . collect ( ) ; // Push down the projection consisting of the entries of `columns` // in increasing order. projection_pushdown . action ( view , & projection_pushed_down , demand ) ; applied_projection . insert ( id , projection_pushed_down ) ; } else if id == Id :: Global ( GlobalId :: Explain ) { // If we just want to explain the plan for a given view, then there // will be no upstream demand. Just demand all columns from views // that are not depended on by another view. let arity = view . arity ( ) ; projection_pushdown . action ( view , & ( 0 .. arity ) . collect ( ) , demand ) ; } view_refs . push ( view ) ; } let typ_update = crate :: update_let :: UpdateLet :: default ( ) ; for view in view_refs { // Update column references to views where projections were pushed down. projection_pushdown . update_projection_around_get ( view , & applied_projection ) ; // Types need to be updated after ProjectionPushdown // because the width of each view may have changed. typ_update . action ( view , & mut HashMap :: new ( ) , & mut IdGen :: default ( ) ) ? ; } Ok ( ( ) ) }
Pushes demand through views in `view_sequence` in order, removing
columns not demanded.
Pushes demand through views in ` view_sequence ` in order removing columns not demanded .
view_sequence
I
demand
&mut HashMap<Id, BTreeSet<usize>>
view_sequence
I
demand
&mut HashMap<Id, BTreeSet<usize>>