-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Optimizer; remove double SORT and redundant projections (#15573)
- Loading branch information
Showing
7 changed files
with
74 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use super::*; | ||
|
||
#[test] | ||
fn test_schema_update_after_projection_pd() -> PolarsResult<()> { | ||
let df = df![ | ||
"a" => [1], | ||
"b" => [1], | ||
"c" => [1], | ||
]?; | ||
|
||
let q = df | ||
.lazy() | ||
.with_column(col("a").implode()) | ||
.explode([col("a")]) | ||
.select([cols(["a", "b"])]); | ||
|
||
// run optimizations | ||
// Get the explode node | ||
let (input, lp_arena, _expr_arena) = q.to_alp_optimized()?; | ||
|
||
// assert the schema has been corrected with the projection pushdown run | ||
let lp = lp_arena.get(input); | ||
assert!(matches!( | ||
lp, | ||
IR::MapFunction { | ||
function: FunctionNode::Explode { .. }, | ||
.. | ||
} | ||
)); | ||
|
||
let schema = lp.schema(&lp_arena).into_owned(); | ||
let mut expected = Schema::new(); | ||
expected.with_column("a".into(), DataType::Int32); | ||
expected.with_column("b".into(), DataType::Int32); | ||
assert_eq!(schema.as_ref(), &expected); | ||
|
||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -1,30 +1 @@ | ||
use super::*; | ||
|
||
#[test] | ||
fn test_schema_update_after_projection_pd() -> PolarsResult<()> { | ||
let df = df![ | ||
"a" => [1], | ||
"b" => [1], | ||
"c" => [1], | ||
]?; | ||
|
||
let q = df | ||
.lazy() | ||
.with_column(col("a").implode()) | ||
.explode([col("a")]) | ||
.select([cols(["a", "b"])]); | ||
|
||
// run optimizations | ||
let (node, lp_arena, _expr_arena) = q.to_alp_optimized()?; | ||
// get the explode node | ||
let input = lp_arena.get(node).get_inputs()[0]; | ||
// assert the schema has been corrected with the projection pushdown run | ||
lp_arena.get(input); | ||
let schema = lp_arena.get(input).schema(&lp_arena).into_owned(); | ||
let mut expected = Schema::new(); | ||
expected.with_column("a".into(), DataType::Int32); | ||
expected.with_column("b".into(), DataType::Int32); | ||
assert_eq!(schema.as_ref(), &expected); | ||
|
||
Ok(()) | ||
} |
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,8 @@ | ||
import polars as pl | ||
|
||
|
||
def test_remove_double_sort() -> None: | ||
assert ( | ||
pl.LazyFrame({"a": [1, 2, 3, 3]}).sort("a").sort("a").explain().count("SORT") | ||
== 1 | ||
) |
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