-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very simple predicates were not pushed down to the scan level Fixed and added proper tests. Will add more.
- Loading branch information
Showing
7 changed files
with
102 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
mod predicate_pushdown; | ||
mod queries; | ||
use polars_core::prelude::*; | ||
use polars_io::prelude::*; | ||
use std::io::Cursor; | ||
|
||
use crate::functions::{argsort_by, pearson_corr}; | ||
use crate::logical_plan::iterator::ArenaLpIter; | ||
use crate::logical_plan::optimizer::simplify_expr::SimplifyExprRule; | ||
use crate::logical_plan::optimizer::stack_opt::{OptimizationRule, StackOptimizer}; | ||
use crate::prelude::*; | ||
use polars_core::chunked_array::builder::get_list_builder; | ||
#[cfg(feature = "temporal")] | ||
use polars_core::utils::chrono::{NaiveDate, NaiveDateTime, NaiveTime}; | ||
use polars_core::{df, prelude::*}; | ||
use std::iter::FromIterator; | ||
|
||
fn scan_foods_csv() -> LazyFrame { | ||
let path = "../../examples/aggregate_multiple_files_in_chunks/datasets/foods1.csv"; | ||
LazyCsvReader::new(path.to_string()).finish().unwrap() | ||
} | ||
|
||
pub(crate) fn fruits_cars() -> DataFrame { | ||
df!( | ||
"A"=> [1, 2, 3, 4, 5], | ||
"fruits"=> ["banana", "banana", "apple", "apple", "banana"], | ||
"B"=> [5, 4, 3, 2, 1], | ||
"cars"=> ["beetle", "audi", "beetle", "beetle", "beetle"] | ||
) | ||
.unwrap() | ||
} | ||
|
||
// physical plan see: datafusion/physical_plan/planner.rs.html#61-63 | ||
|
||
pub(crate) fn get_df() -> DataFrame { | ||
let s = r#" | ||
"sepal.length","sepal.width","petal.length","petal.width","variety" | ||
5.1,3.5,1.4,.2,"Setosa" | ||
4.9,3,1.4,.2,"Setosa" | ||
4.7,3.2,1.3,.2,"Setosa" | ||
4.6,3.1,1.5,.2,"Setosa" | ||
5,3.6,1.4,.2,"Setosa" | ||
5.4,3.9,1.7,.4,"Setosa" | ||
4.6,3.4,1.4,.3,"Setosa" | ||
"#; | ||
|
||
let file = Cursor::new(s); | ||
|
||
let df = CsvReader::new(file) | ||
// we also check if infer schema ignores errors | ||
.infer_schema(Some(3)) | ||
.has_header(true) | ||
.finish() | ||
.unwrap(); | ||
df | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use super::*; | ||
|
||
fn projection_at_scan(lp_arena: &Arena<ALogicalPlan>, lp: Node) -> bool { | ||
(&lp_arena).iter(lp).all(|(_, lp)| { | ||
if let ALogicalPlan::DataFrameScan { selection, .. } = lp { | ||
selection.is_some() | ||
} else { | ||
true | ||
} | ||
}) | ||
} | ||
|
||
#[test] | ||
fn test_pred_pd_1() -> Result<()> { | ||
let df = fruits_cars(); | ||
|
||
let mut expr_arena = Arena::with_capacity(16); | ||
let mut lp_arena = Arena::with_capacity(8); | ||
let lp = df | ||
.clone() | ||
.lazy() | ||
.select([col("A"), col("B")]) | ||
.filter(col("A").gt(lit(1))) | ||
.optimize(&mut lp_arena, &mut expr_arena)?; | ||
|
||
assert!(projection_at_scan(&lp_arena, lp)); | ||
|
||
// check if we understand that we can unwrap the alias | ||
let lp = df | ||
.lazy() | ||
.select([col("A").alias("C"), col("B")]) | ||
.filter(col("C").gt(lit(1))) | ||
.optimize(&mut lp_arena, &mut expr_arena)?; | ||
|
||
assert!(projection_at_scan(&lp_arena, lp)); | ||
|
||
Ok(()) | ||
} |
27 changes: 1 addition & 26 deletions
27
polars/polars-lazy/src/test.rs → polars/polars-lazy/src/tests/queries.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters