Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-sql/tests/functions_meta.rs
6939 views
1
use polars_core::prelude::*;
2
use polars_lazy::prelude::*;
3
use polars_sql::*;
4
5
#[test]
6
fn test_describe() {
7
let lf = df! {
8
"year"=> [2018],
9
"country"=> ["US"],
10
"sales"=> [1000.0]
11
}
12
.unwrap()
13
.lazy();
14
let mut context = SQLContext::new();
15
context.register("df", lf.clone());
16
let sql = r#"EXPLAIN SELECT year, country, MAX(year) FROM df"#;
17
let res = context.execute(sql).unwrap();
18
let df = res.collect().unwrap();
19
let lf = lf.select([col("year"), col("country"), col("year").max()]);
20
let expected = lf.describe_optimized_plan().unwrap();
21
22
let expected = expected.split('\n').map(Some).collect::<Vec<_>>();
23
let actual = df
24
.column("Logical Plan")
25
.unwrap()
26
.str()
27
.unwrap()
28
.into_iter()
29
.collect::<Vec<_>>();
30
31
assert_eq!(actual, expected);
32
}
33
34