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