Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/plans/optimizer/projection_pushdown/generic.rs
8430 views
1
use polars_utils::idx_vec::UnitVec;
2
3
use super::*;
4
5
#[allow(clippy::too_many_arguments)]
6
pub(super) fn process_generic(
7
proj_pd: &mut ProjectionPushDown,
8
lp: IR,
9
ctx: ProjectionContext,
10
lp_arena: &mut Arena<IR>,
11
expr_arena: &mut Arena<AExpr>,
12
reset_count_star: bool,
13
) -> PolarsResult<IR> {
14
let inputs = lp.get_inputs();
15
let input_count = inputs.len();
16
17
// let mut first_schema = None;
18
// let mut names = None;
19
20
let new_inputs = inputs
21
.into_iter()
22
.map(|node| {
23
if reset_count_star {
24
proj_pd.is_count_star = false;
25
}
26
let alp = lp_arena.take(node);
27
let mut alp = proj_pd.push_down(alp, ctx.clone(), lp_arena, expr_arena)?;
28
29
// double projection can mess up the schema ordering
30
// here we ensure the ordering is maintained.
31
//
32
// Consider this query
33
// df1 => a, b
34
// df2 => a, b
35
//
36
// df3 = df1.join(df2, on = a, b)
37
//
38
// concat([df1, df3]).select(a)
39
//
40
// schema after projection pd
41
// df3 => a, b
42
// df1 => a
43
// so we ensure we do the 'a' projection again before we concatenate
44
if !ctx.acc_projections.is_empty() && input_count > 1 {
45
alp = IRBuilder::from_lp(alp, expr_arena, lp_arena)
46
.project_simple_nodes(ctx.acc_projections.iter().map(|e| e.0))
47
.unwrap()
48
.build();
49
}
50
lp_arena.replace(node, alp);
51
Ok(node)
52
})
53
.collect::<PolarsResult<UnitVec<_>>>()?;
54
55
Ok(lp.with_inputs(new_inputs))
56
}
57
58