Path: blob/main/crates/polars-lazy/src/physical_plan/exotic.rs
6939 views
use polars_core::prelude::*;1use polars_expr::{ExpressionConversionState, create_physical_expr};23use crate::prelude::*;45pub(crate) fn contains_column_refs(expr: &Expr) -> bool {6for e in expr.into_iter() {7match e {8Expr::Column(c) if !c.eq(&PlSmallStr::EMPTY) => return true,9Expr::Selector(_) => return true,10#[cfg(feature = "dtype-struct")]11Expr::Field(_) => return true,12#[cfg(feature = "dtype-struct")]13Expr::Function {14function:15FunctionExpr::StructExpr(16StructFunction::FieldByName(_) | StructFunction::SelectFields(_),17),18..19} => return true,20_ => {},21}22}23false24}2526pub(crate) fn prepare_expression_for_context(27name: PlSmallStr,28expr: &Expr,29dtype: &DataType,30ctxt: Context,31) -> PolarsResult<Arc<dyn PhysicalExpr>> {32let mut lp_arena = Arena::with_capacity(8);33let mut expr_arena = Arena::with_capacity(10);3435// create a dummy lazyframe and run a very simple optimization run so that36// type coercion and simplify expression optimizations run.37let column = Series::full_null(name, 0, dtype);38let df = column.into_frame();39let input_schema = df.schema().clone();40let lf = df41.lazy()42.without_optimizations()43.with_simplify_expr(true)44.select([expr.clone()]);45let optimized = lf.optimize(&mut lp_arena, &mut expr_arena)?;46let lp = lp_arena.get(optimized);47let aexpr = lp48.exprs()49.next()50.ok_or_else(|| polars_err!(ComputeError: "expected expressions in the context"))?;5152create_physical_expr(53aexpr,54ctxt,55&expr_arena,56&input_schema,57&mut ExpressionConversionState::new(true),58)59}606162