Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-lazy/src/tests/schema.rs
8430 views
1
use super::*;
2
3
#[test]
4
fn test_schema_update_after_projection_pd() -> PolarsResult<()> {
5
let df = df![
6
"a" => [1],
7
"b" => [1],
8
"c" => [1],
9
]?;
10
11
let q = df
12
.lazy()
13
.with_column(col("a").implode())
14
.explode(
15
by_name(["a"], true, false),
16
ExplodeOptions {
17
empty_as_null: true,
18
keep_nulls: true,
19
},
20
)
21
.select([cols(["a", "b"]).as_expr()]);
22
23
// run optimizations
24
// Get the explode node
25
let IRPlan {
26
lp_top,
27
lp_arena,
28
expr_arena: _,
29
} = q.to_alp_optimized()?;
30
31
// assert the schema has been corrected with the projection pushdown run
32
let lp = lp_arena.get(lp_top);
33
assert!(matches!(
34
lp,
35
IR::MapFunction {
36
function: FunctionIR::Explode { .. },
37
..
38
}
39
));
40
41
let schema = lp.schema(&lp_arena).into_owned();
42
let mut expected = Schema::default();
43
expected.with_column("a".into(), DataType::Int32);
44
expected.with_column("b".into(), DataType::Int32);
45
assert_eq!(schema.as_ref(), &expected);
46
47
Ok(())
48
}
49
50