-
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.
restructure everything and add rules module
- Loading branch information
1 parent
dadf40c
commit 7d405d1
Showing
14 changed files
with
143 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
#![allow(unused)] | ||
#![allow(unused_variables)] | ||
|
||
pub mod expression; | ||
pub mod memo; | ||
pub mod operator; | ||
pub mod plan; | ||
pub mod rules; | ||
|
||
/// TODO make distinction between relational groups and scalar groups. | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct GroupId(u64); | ||
|
||
/// TODO Add docs. | ||
#[allow(dead_code)] | ||
pub struct ExprId(u64); |
6 changes: 2 additions & 4 deletions
6
optd-types/src/memo/implementation.rs → optd-types/src/memo.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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,4 +1,4 @@ | ||
use std::{marker::PhantomData, sync::Arc}; | ||
use std::marker::PhantomData; | ||
|
||
pub mod logical; | ||
pub mod physical; | ||
|
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,13 @@ | ||
use super::*; | ||
|
||
pub struct HashJoinRule; | ||
|
||
impl ImplementationRule for HashJoinRule { | ||
async fn check_pattern(&self, expr: Expr, memo: &Memo) -> Vec<PartialPhysicalPlan> { | ||
todo!() | ||
} | ||
|
||
fn apply(&self, expr: PartialPhysicalPlan) -> Vec<Expr> { | ||
todo!() | ||
} | ||
} |
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,31 @@ | ||
use crate::{expression::Expr, memo::Memo, plan::partial_physical_plan::PartialPhysicalPlan}; | ||
|
||
#[allow(dead_code)] | ||
#[trait_variant::make(Send)] | ||
pub trait ImplementationRule { | ||
/// Checks if the implementation rule matches the current expression and its children. | ||
/// Returns a vector of partially materialized physical plans. | ||
/// | ||
/// This returns a vector because the rule matching the input root expression could have matched | ||
/// with multiple child expressions. | ||
/// | ||
/// For example, let's say the input expression is `Filter(G1)`, and the group G1 has | ||
/// two expressions `e1 = HashJoin(HashJoin(A, B), C)` and `e2 = HashJoin(A, HashJoin(B, C))`. | ||
/// | ||
/// If the rule wants to match against `Filter(HashJoin(?L, ?R))`, then this function will | ||
/// partially materialize two expressions `Filter(e1)` and `Filter(e2)`. It is then up to the | ||
/// memo table API to apply modifications to the partially materialized physical plans (for | ||
/// example, a pushing a filter predicate into the condition of the `HashJoin`). | ||
/// | ||
/// TODO: Ideally this should return a `Stream` instead of a fully materialized Vector. | ||
async fn check_pattern(&self, expr: Expr, memo: &Memo) -> Vec<PartialPhysicalPlan>; | ||
|
||
/// Applys modifications to a partially materialized physical plan. | ||
/// | ||
/// These changes can create new expressions (logical, physical, and scalar). | ||
fn apply(&self, expr: PartialPhysicalPlan) -> Vec<Expr>; | ||
} | ||
|
||
pub mod hash_join; | ||
pub mod physical_filter; | ||
pub mod table_scan; |
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,13 @@ | ||
use super::*; | ||
|
||
pub struct PhysicalFilterRule; | ||
|
||
impl ImplementationRule for PhysicalFilterRule { | ||
async fn check_pattern(&self, expr: Expr, memo: &Memo) -> Vec<PartialPhysicalPlan> { | ||
todo!() | ||
} | ||
|
||
fn apply(&self, expr: PartialPhysicalPlan) -> Vec<Expr> { | ||
todo!() | ||
} | ||
} |
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,13 @@ | ||
use super::*; | ||
|
||
pub struct TableScanRule; | ||
|
||
impl ImplementationRule for TableScanRule { | ||
async fn check_pattern(&self, expr: Expr, memo: &Memo) -> Vec<PartialPhysicalPlan> { | ||
todo!() | ||
} | ||
|
||
fn apply(&self, expr: PartialPhysicalPlan) -> Vec<Expr> { | ||
todo!() | ||
} | ||
} |
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,5 @@ | ||
//! This module rules. | ||
mod transformation; | ||
|
||
mod implementation; |
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,13 @@ | ||
use super::*; | ||
|
||
pub struct JoinAssociativityRule; | ||
|
||
impl TransformationRule for JoinAssociativityRule { | ||
async fn check_pattern(&self, expr: LogicalExpr, memo: &Memo) -> Vec<PartialLogicalPlan> { | ||
todo!() | ||
} | ||
|
||
fn apply(&self, expr: PartialLogicalPlan) -> Vec<Expr> { | ||
todo!() | ||
} | ||
} |
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,13 @@ | ||
use super::*; | ||
|
||
pub struct JoinCommutativityRule; | ||
|
||
impl TransformationRule for JoinCommutativityRule { | ||
async fn check_pattern(&self, expr: LogicalExpr, memo: &Memo) -> Vec<PartialLogicalPlan> { | ||
todo!() | ||
} | ||
|
||
fn apply(&self, expr: PartialLogicalPlan) -> Vec<Expr> { | ||
todo!() | ||
} | ||
} |
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,35 @@ | ||
use crate::{ | ||
expression::{relational::logical::LogicalExpr, Expr}, | ||
memo::Memo, | ||
plan::partial_logical_plan::PartialLogicalPlan, | ||
}; | ||
|
||
#[allow(dead_code)] | ||
#[trait_variant::make(Send)] | ||
pub trait TransformationRule { | ||
/// Checks if the transformation rule matches the current expression and its children. | ||
/// Returns a vector of partially materialized logical plans. | ||
/// | ||
/// This returns a vector because the rule matching the input root expression could have matched | ||
/// with multiple child expressions. | ||
/// | ||
/// For example, let's say the input expression is `Filter(G1)`, and the group G1 has two | ||
/// expressions `e1 = Join(Join(A, B), C)` and `e2 = Join(A, Join(B, C))`. | ||
/// | ||
/// If the rule wants to match against `Filter(Join(?L, ?R))`, then this function will partially | ||
/// materialize two expressions `Filter(e1)` and `Filter(e2)`. It is then up to the memo table | ||
/// API to apply modifications to the partially materialized logical plans (for example, a | ||
/// filter pushdown under a `Join`). | ||
/// | ||
/// TODO: Ideally this should return a `Stream` instead of a fully materialized Vector. | ||
async fn check_pattern(&self, expr: LogicalExpr, memo: &Memo) -> Vec<PartialLogicalPlan>; | ||
|
||
/// Applys modifications to a partially materialized logical plan. | ||
/// | ||
/// These changes can create new logical or scalar expressions. However, note that | ||
/// transformation rules will _not_ create new physical expressions. | ||
fn apply(&self, expr: PartialLogicalPlan) -> Vec<Expr>; | ||
} | ||
|
||
pub mod join_associativity; | ||
pub mod join_commutativity; |