/// Execute all the lazy operations and collect them into a [DataFrame](crate::prelude::DataFrame).
/// Before execution the query is being optimized.
///
/// # Example
///
/// ```rust
/// use polars::prelude::*;
/// use polars::lazy::dsl::*;
///
/// fn example(df: DataFrame) -> Result<DataFrame> {
///       df.lazy()
///         .groupby("foo")
///         .agg(vec!(col("bar").agg_sum(),
///                   col("ham").agg_mean().alias("avg_ham")))
///         .collect()
/// }
/// ```
Execute all the lazy operations and collect them into a [DataFrame](crate::prelude::DataFrame).
Before execution the query is being optimized.
Execute all the lazy operations and collect them into a [ DataFrame ] ( crate :: prelude :: DataFrame ) . Before execution the query is being optimized .
pub fn collect(self) -> Result<DataFrame> {
        let predicate_pushdown = self.predicate_pushdown;
        let projection_pushdown = self.projection_pushdown;
        let type_coercion = self.type_coercion;
        let mut logical_plan = self.get_plan_builder().build();
        let predicate_pushdown_opt = PredicatePushDown {};
        let projection_pushdown_opt = ProjectionPushDown {};
        let type_coercion_opt = TypeCoercion {};
        if cfg!(debug_assertions) {
            // check that the optimization don't interfere with the schema result.
            let prev_schema = logical_plan.schema().clone();
            if projection_pushdown {
                logical_plan = projection_pushdown_opt.optimize(logical_plan)?;
            }
            assert_eq!(logical_plan.schema(), &prev_schema);
            let prev_schema = logical_plan.schema().clone();
            if predicate_pushdown {
                logical_plan = predicate_pushdown_opt.optimize(logical_plan)?;
            }
            assert_eq!(logical_plan.schema(), &prev_schema);
        } else {
            // NOTE: the order is important. Projection pushdown must be before predicate pushdown,
            // The projection may have aliases that interfere with the predicate expressions.
            if projection_pushdown {
                logical_plan = projection_pushdown_opt.optimize(logical_plan)?;
            }
            if predicate_pushdown {
                logical_plan = predicate_pushdown_opt.optimize(logical_plan)?;
            }
        };
        if type_coercion {
            logical_plan = type_coercion_opt.optimize(logical_plan)?;
        }
        let planner = DefaultPlanner::default();
        let physical_plan = planner.create_physical_plan(&logical_plan)?;
        physical_plan.execute()
    }
pub fn collect ( self ) -> Result < DataFrame > { let predicate_pushdown = self . predicate_pushdown ; let projection_pushdown = self . projection_pushdown ; let type_coercion = self . type_coercion ; let mut logical_plan = self . get_plan_builder ( ) . build ( ) ; let predicate_pushdown_opt = PredicatePushDown { } ; let projection_pushdown_opt = ProjectionPushDown { } ; let type_coercion_opt = TypeCoercion { } ; if cfg ! ( debug_assertions ) { // check that the optimization don't interfere with the schema result. let prev_schema = logical_plan . schema ( ) . clone ( ) ; if projection_pushdown { logical_plan = projection_pushdown_opt . optimize ( logical_plan ) ? ; } assert_eq ! ( logical_plan schema ( ) prev_schema ) ; let prev_schema = logical_plan . schema ( ) . clone ( ) ; if predicate_pushdown { logical_plan = predicate_pushdown_opt . optimize ( logical_plan ) ? ; } assert_eq ! ( logical_plan schema ( ) prev_schema ) ; } else { // NOTE: the order is important. Projection pushdown must be before predicate pushdown, // The projection may have aliases that interfere with the predicate expressions. if projection_pushdown { logical_plan = projection_pushdown_opt . optimize ( logical_plan ) ? ; } if predicate_pushdown { logical_plan = predicate_pushdown_opt . optimize ( logical_plan ) ? ; } } ; if type_coercion { logical_plan = type_coercion_opt . optimize ( logical_plan ) ? ; } let planner = DefaultPlanner :: default ( ) ; let physical_plan = planner . create_physical_plan ( & logical_plan ) ? ; physical_plan . execute ( ) }
Execute all the lazy operations and collect them into a [DataFrame](crate::prelude::DataFrame).
Execute all the lazy operations and collect them into a [ DataFrame ] ( crate :: prelude :: DataFrame ) .
self
example
```rust
use polars::prelude::*;
use polars::lazy::dsl::*.


` ` ` rust use polars :: prelude :: * ; use polars :: lazy :: dsl :: * .