-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
pub fn add(left: u64, right: u64) -> u64 { | ||
left + right | ||
mod memo; | ||
pub use memo::MemoNode; | ||
|
||
/// A type representing a transformation or implementation rule for query operators. | ||
/// | ||
/// TODO The variants are just placeholders. | ||
pub enum Rule { | ||
Transformation, | ||
Implementation | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
pub struct GroupId(usize); | ||
Check warning on line 12 in optd-types/src/lib.rs
|
||
|
||
/// An in-memory tree of logical operators. Used as the input / entrypoint of the optimizer. | ||
/// | ||
/// TODO The variants are just placeholders. The actual type will look more similar to | ||
/// https://docs.rs/substrait/latest/substrait/proto/rel/enum.RelType.html | ||
pub enum LogicalPlan { | ||
Scan(String), | ||
Filter(Box<LogicalPlan>), | ||
Sort(Box<LogicalPlan>), | ||
Join(Box<LogicalPlan>), | ||
} | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
/// An in-memory tree of physical operators. Used as the final materialized output of the optimizer. | ||
/// | ||
/// TODO The variants are just placeholders. The actual type will look more similar to | ||
/// https://docs.rs/substrait/latest/substrait/proto/rel/enum.RelType.html | ||
pub enum PhysicalPlan { | ||
TableScan(String), | ||
IndexScan(String), | ||
PhysicalFilter(Box<PhysicalPlan>), | ||
NestedLoopJoin(Box<PhysicalPlan>), | ||
SortMergeJoin(Box<PhysicalPlan>), | ||
HashJoin(Box<PhysicalPlan>), | ||
MergeSort(Box<PhysicalPlan>), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use relation::{LogicalExpression, Relation}; | ||
use scalar::Scalar; | ||
|
||
use crate::Rule; | ||
|
||
mod relation; | ||
mod scalar; | ||
|
||
/// A type representing an optimization node / object in the memo table. | ||
pub enum MemoNode { | ||
Relation(Relation), | ||
Scalar(Scalar), | ||
} | ||
|
||
/// A type representing a tree of logical nodes, scalar nodes, and group IDs. | ||
/// | ||
/// Note that group IDs must be leaves of this tree. | ||
/// | ||
/// TODO Make this an actual tree with the correct modeling of types. | ||
pub struct PartialLogicalExpression; | ||
Check warning on line 20 in optd-types/src/memo/mod.rs
|
||
|
||
/// A type representing a tree of logical nodes, physical nodes, scalar nodes, and group IDs. | ||
/// | ||
/// Note that group IDs must be leaves of this tree, and that physical nodes cannot have children | ||
/// that are logical nodes. | ||
/// | ||
/// TODO Make this an actual tree with the correct modeling of types. | ||
pub struct PartialPhysicalExpression; | ||
Check warning on line 28 in optd-types/src/memo/mod.rs
|
||
|
||
pub struct Memo; | ||
Check warning on line 30 in optd-types/src/memo/mod.rs
|
||
|
||
impl Memo { | ||
Check warning on line 32 in optd-types/src/memo/mod.rs
|
||
pub async fn check_transformation( | ||
&self, | ||
expr: LogicalExpression, | ||
Check warning on line 35 in optd-types/src/memo/mod.rs
|
||
rule: Rule, | ||
Check warning on line 36 in optd-types/src/memo/mod.rs
|
||
) -> Vec<PartialLogicalExpression> { | ||
todo!() | ||
} | ||
|
||
pub async fn check_implementation( | ||
&self, | ||
expr: LogicalExpression, | ||
Check warning on line 43 in optd-types/src/memo/mod.rs
|
||
rule: Rule, | ||
Check warning on line 44 in optd-types/src/memo/mod.rs
|
||
) -> Vec<PartialPhysicalExpression> { | ||
todo!() | ||
} | ||
|
||
pub fn apply_transformation(&mut self, expr: PartialLogicalExpression, rule: Rule) -> Vec<MemoNode> { | ||
Check warning on line 49 in optd-types/src/memo/mod.rs
|
||
todo!() | ||
} | ||
|
||
pub fn apply_implementation(&mut self, expr: PartialPhysicalExpression, rule: Rule) -> Vec<MemoNode> { | ||
Check warning on line 53 in optd-types/src/memo/mod.rs
|
||
todo!() | ||
} | ||
|
||
pub fn add_expressions(&mut self, new_exprs: Vec<MemoNode>) { | ||
Check warning on line 57 in optd-types/src/memo/mod.rs
|
||
todo!() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::GroupId; | ||
|
||
/// A type representing different kinds of logical expressions / operators. | ||
pub enum LogicalExpression { | ||
Scan(Scan), | ||
Check warning on line 5 in optd-types/src/memo/relation/logical_expression.rs
|
||
Filter(Filter), | ||
Check warning on line 6 in optd-types/src/memo/relation/logical_expression.rs
|
||
Join(Join), | ||
Check warning on line 7 in optd-types/src/memo/relation/logical_expression.rs
|
||
Sort(Sort), | ||
Check warning on line 8 in optd-types/src/memo/relation/logical_expression.rs
|
||
} | ||
|
||
struct Scan { | ||
Check warning on line 11 in optd-types/src/memo/relation/logical_expression.rs
|
||
table_name: String, | ||
} | ||
|
||
struct Filter { | ||
Check warning on line 15 in optd-types/src/memo/relation/logical_expression.rs
|
||
child: GroupId, | ||
predicate: GroupId, | ||
} | ||
|
||
struct Join { | ||
Check warning on line 20 in optd-types/src/memo/relation/logical_expression.rs
|
||
left: GroupId, | ||
right: GroupId, | ||
condition: GroupId, | ||
} | ||
|
||
struct Sort { | ||
Check warning on line 26 in optd-types/src/memo/relation/logical_expression.rs
|
||
child: GroupId, | ||
sort_expr: GroupId, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod logical_expression; | ||
pub use logical_expression::LogicalExpression; | ||
|
||
mod physical_expression; | ||
pub use physical_expression::PhysicalExpression; | ||
|
||
/// A type representing logical or physical operators in a relational algebraic query plan. | ||
pub enum Relation { | ||
Logical(LogicalExpression), | ||
Physical(PhysicalExpression), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::GroupId; | ||
|
||
/// A type representing different kinds of physical expressions / operators. | ||
pub enum PhysicalExpression { | ||
TableScan(TableScan), | ||
Check warning on line 5 in optd-types/src/memo/relation/physical_expression.rs
|
||
PhysicalFilter(PhysicalFilter), | ||
Check warning on line 6 in optd-types/src/memo/relation/physical_expression.rs
|
||
SortMergeJoin(SortMergeJoin), | ||
Check warning on line 7 in optd-types/src/memo/relation/physical_expression.rs
|
||
HashJoin(HashJoin), | ||
Check warning on line 8 in optd-types/src/memo/relation/physical_expression.rs
|
||
MergeSort(MergeSort), | ||
Check warning on line 9 in optd-types/src/memo/relation/physical_expression.rs
|
||
} | ||
|
||
struct TableScan { | ||
Check warning on line 12 in optd-types/src/memo/relation/physical_expression.rs
|
||
table_name: String, | ||
} | ||
|
||
struct PhysicalFilter { | ||
Check warning on line 16 in optd-types/src/memo/relation/physical_expression.rs
|
||
child: GroupId, | ||
predicate: GroupId, | ||
} | ||
|
||
|
||
struct SortMergeJoin { | ||
Check warning on line 22 in optd-types/src/memo/relation/physical_expression.rs
|
||
left: GroupId, | ||
right: GroupId, | ||
condition: GroupId, | ||
sort_expr: GroupId, | ||
} | ||
|
||
struct HashJoin { | ||
Check warning on line 29 in optd-types/src/memo/relation/physical_expression.rs
|
||
left: GroupId, | ||
right: GroupId, | ||
condition: GroupId, | ||
} | ||
|
||
struct MergeSort { | ||
Check warning on line 35 in optd-types/src/memo/relation/physical_expression.rs
|
||
child: GroupId, | ||
sort_expr: GroupId, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// A type that represent scalar SQL expression / predicates. | ||
/// | ||
/// TODO Add fields to this type. | ||
pub struct Scalar; |