-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
83 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,41 @@ | ||
mod push_down_projections; | ||
|
||
use push_down_projections::ProjectionPushDownRule; | ||
|
||
use crate::{error::Result, logical::plan::LogicalPlan}; | ||
|
||
pub trait OptimizerRule { | ||
fn name(&self) -> &str; | ||
|
||
fn optimize(&self, plan: &LogicalPlan) -> Result<Option<LogicalPlan>>; | ||
} | ||
|
||
pub struct Optimzier { | ||
rules: Vec<Box<dyn OptimizerRule + Sync + Send>>, | ||
} | ||
|
||
impl Optimzier { | ||
pub fn new() -> Self { | ||
Self { | ||
rules: vec![Box::new(ProjectionPushDownRule)], | ||
} | ||
} | ||
|
||
pub fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan> { | ||
let mut plan = plan.clone(); | ||
let mut optimized = true; | ||
while optimized { | ||
optimized = false; | ||
for rule in &self.rules { | ||
match rule.optimize(&plan)? { | ||
Some(new_plan) => { | ||
plan = new_plan; | ||
optimized = true; | ||
} | ||
None => {} | ||
} | ||
} | ||
} | ||
Ok(plan) | ||
} | ||
} |
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