-
-
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.
- Loading branch information
Showing
9 changed files
with
122 additions
and
22 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
65 changes: 65 additions & 0 deletions
65
polars/polars-lazy/src/logical_plan/optimizer/delay_rechunk.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::prelude::stack_opt::OptimizationRule; | ||
use crate::prelude::*; | ||
use polars_utils::arena::{Arena, Node}; | ||
|
||
pub(crate) struct DelayRechunk {} | ||
|
||
impl OptimizationRule for DelayRechunk { | ||
fn optimize_plan( | ||
&mut self, | ||
lp_arena: &mut Arena<ALogicalPlan>, | ||
_expr_arena: &mut Arena<AExpr>, | ||
node: Node, | ||
) -> Option<ALogicalPlan> { | ||
match lp_arena.get(node) { | ||
// An aggregation can be partitioned, its wasteful to rechunk before that partition. | ||
ALogicalPlan::Aggregate { input, .. } => { | ||
use ALogicalPlan::*; | ||
let mut input_node = None; | ||
for (node, lp) in (&*lp_arena).iter(*input) { | ||
match lp { | ||
// we get the input node | ||
#[cfg(feature = "parquet")] | ||
ParquetScan { .. } => { | ||
input_node = Some(node); | ||
break; | ||
} | ||
#[cfg(feature = "csv-file")] | ||
CsvScan { .. } => { | ||
input_node = Some(node); | ||
break; | ||
} | ||
#[cfg(feature = "ipc")] | ||
IpcScan { .. } => { | ||
input_node = Some(node); | ||
break; | ||
} | ||
|
||
// don't delay rechunk if there is a join first | ||
Join { .. } => break, | ||
_ => {} | ||
} | ||
} | ||
|
||
if let Some(node) = input_node { | ||
match lp_arena.get_mut(node) { | ||
#[cfg(feature = "csv-file")] | ||
CsvScan { options, .. } => { | ||
options.rechunk = false; | ||
} | ||
#[cfg(feature = "parquet")] | ||
ParquetScan { options, .. } => options.rechunk = false, | ||
#[cfg(feature = "ipc")] | ||
IpcScan { options, .. } => { | ||
options.rechunk = false; | ||
} | ||
_ => unreachable!(), | ||
} | ||
}; | ||
|
||
None | ||
} | ||
_ => None, | ||
} | ||
} | ||
} |
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