Skip to content

Commit

Permalink
Separate scalar expressions from logical
Browse files Browse the repository at this point in the history
  • Loading branch information
AlSchlo committed Jan 29, 2025
1 parent 583f9de commit 913bae8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
11 changes: 2 additions & 9 deletions optd-core/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
use crate::memo::GroupId;
use crate::operator::relational::logical::LogicalOperator;
use crate::operator::relational::physical::PhysicalOperator;
use crate::operator::scalar::ScalarOperator;

/// A logical expression in the memo table.
///
/// References children using [`GroupId`]s for expression sharing
/// and memoization.
pub enum LogicalExpression {
Relational(LogicalOperator<GroupId, GroupId>),
Scalar(ScalarOperator<GroupId>),
}
pub type LogicalExpression = LogicalOperator<GroupId, GroupId>;

/// A physical expression in the memo table.
///
/// Like [`LogicalExpression`] but with specific implementation
/// strategies.
pub enum PhysicalExpression {
Relational(PhysicalOperator<GroupId, GroupId>),
Scalar(ScalarOperator<GroupId>),
}
pub type PhysicalExpression = PhysicalOperator<GroupId, GroupId>;
16 changes: 7 additions & 9 deletions optd-core/src/rules/implementation/hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ pub struct HashJoinRule;
// https://github.com/cmu-db/optd/issues/15
impl ImplementationRule for HashJoinRule {
fn check_and_apply(&self, expr: LogicalExpression) -> Option<PhysicalExpression> {
if let LogicalExpression::Relational(LogicalOperator::Join(join)) = expr {
return Some(PhysicalExpression::Relational(PhysicalOperator::HashJoin(
HashJoin {
join_type: join.join_type,
probe_side: join.left,
build_side: join.right,
condition: join.condition,
},
)));
if let LogicalOperator::Join(join) = expr {
return Some(PhysicalOperator::HashJoin(HashJoin {
join_type: join.join_type,
probe_side: join.left,
build_side: join.right,
condition: join.condition,
}));
}
None
}
Expand Down
12 changes: 5 additions & 7 deletions optd-core/src/rules/implementation/physical_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ pub struct PhysicalFilterRule;

impl ImplementationRule for PhysicalFilterRule {
fn check_and_apply(&self, expr: LogicalExpression) -> Option<PhysicalExpression> {
if let LogicalExpression::Relational(LogicalOperator::Filter(filter)) = expr {
return Some(PhysicalExpression::Relational(PhysicalOperator::Filter(
Filter {
child: filter.child,
predicate: filter.predicate,
},
)));
if let LogicalOperator::Filter(filter) = expr {
return Some(PhysicalOperator::Filter(Filter {
child: filter.child,
predicate: filter.predicate,
}));
}

None
Expand Down
12 changes: 5 additions & 7 deletions optd-core/src/rules/implementation/table_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ pub struct TableScanRule;

impl ImplementationRule for TableScanRule {
fn check_and_apply(&self, expr: LogicalExpression) -> Option<PhysicalExpression> {
if let LogicalExpression::Relational(LogicalOperator::Scan(scan)) = expr {
return Some(PhysicalExpression::Relational(PhysicalOperator::TableScan(
TableScan {
table_name: scan.table_name,
predicate: scan.predicate,
},
)));
if let LogicalOperator::Scan(scan) = expr {
return Some(PhysicalOperator::TableScan(TableScan {
table_name: scan.table_name,
predicate: scan.predicate,
}));
}

None
Expand Down

0 comments on commit 913bae8

Please sign in to comment.