Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/docs/source/src/rust/user-guide/concepts/streaming.rs
7889 views
1
use polars::prelude::*;
2
3
fn main() -> Result<(), Box<dyn std::error::Error>> {
4
// --8<-- [start:streaming]
5
let q1 = LazyCsvReader::new(PlPath::new("docs/assets/data/iris.csv"))
6
.with_has_header(true)
7
.finish()?
8
.filter(col("sepal_length").gt(lit(5)))
9
.group_by(vec![col("species")])
10
.agg([col("sepal_width").mean()]);
11
12
let df = q1.clone().with_new_streaming(true).collect()?;
13
println!("{df}");
14
// --8<-- [end:streaming]
15
16
// --8<-- [start:example]
17
let query_plan = q1.with_new_streaming(true).explain(true)?;
18
println!("{query_plan}");
19
// --8<-- [end:example]
20
21
// --8<-- [start:example2]
22
let q2 = LazyCsvReader::new(PlPath::new("docs/assets/data/iris.csv"))
23
.finish()?
24
.with_columns(vec![
25
col("sepal_length")
26
.mean()
27
.over(vec![col("species")])
28
.alias("sepal_length_mean"),
29
]);
30
31
let query_plan = q2.with_new_streaming(true).explain(true)?;
32
println!("{query_plan}");
33
// --8<-- [end:example2]
34
35
Ok(())
36
}
37
38