Skip to content

Commit 1f7d7fc

Browse files
committed
rename many types
1 parent 3240e31 commit 1f7d7fc

File tree

9 files changed

+153
-113
lines changed

9 files changed

+153
-113
lines changed

optd-types/src/expression/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use relation::RelationExpression;
2+
use scalar::ScalarExpression;
3+
4+
mod relation;
5+
mod scalar;
6+
7+
pub use relation::{LogicalExpression, PhysicalExpression};
8+
9+
/// A type representing an optimization operator in the memo table.
10+
pub enum Expression {
11+
RelationExpression(RelationExpression),
12+
ScalarExpression(ScalarExpression),
13+
}

optd-types/src/memo/relation/logical_expression.rs renamed to optd-types/src/expression/relation/logical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::GroupId;
22

3-
/// A type representing different kinds of logical expressions / operators.
3+
/// A type representing different kinds of logical expressions in the memo table.
44
pub enum LogicalExpression {
55
Scan(Scan),
66
Filter(Filter),
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mod logical;
2+
pub use logical::LogicalExpression;
3+
4+
mod physical;
5+
pub use physical::PhysicalExpression;
6+
7+
/// A type representing logical or physical expressions in the memo table.
8+
pub enum RelationExpression {
9+
LogicalExpression(LogicalExpression),
10+
PhysicalExpression(PhysicalExpression),
11+
}

optd-types/src/memo/relation/physical_expression.rs renamed to optd-types/src/expression/relation/physical.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::GroupId;
22

3-
/// A type representing different kinds of physical expressions / operators.
3+
/// A type representing different kinds of physical expressions in the memo table.
44
pub enum PhysicalExpression {
55
TableScan(TableScan),
66
PhysicalFilter(PhysicalFilter),
@@ -18,7 +18,6 @@ struct PhysicalFilter {
1818
predicate: GroupId,
1919
}
2020

21-
2221
struct SortMergeJoin {
2322
left: GroupId,
2423
right: GroupId,
@@ -36,4 +35,3 @@ struct MergeSort {
3635
child: GroupId,
3736
sort_expr: GroupId,
3837
}
39-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/// A type that represent scalar SQL expression / predicates.
22
///
33
/// TODO Add fields to this type.
4-
pub struct Scalar;
4+
pub struct ScalarExpression;

optd-types/src/lib.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1+
mod expression;
12
mod memo;
2-
pub use memo::MemoNode;
33

4-
/// A type representing a transformation or implementation rule for query operators.
4+
pub struct GroupId(usize);
5+
6+
pub struct LogicalOperator;
7+
8+
pub struct PhysicalOperator;
9+
10+
pub struct ScalarOperator;
11+
12+
/// A type representing a tree of logical nodes, scalar nodes, and group IDs.
513
///
6-
/// TODO The variants are just placeholders.
7-
pub enum Rule {
8-
Transformation,
9-
Implementation
14+
/// Note that group IDs must be leaves of this tree.
15+
///
16+
/// TODO Make this an actual tree with the correct modeling of types.
17+
pub enum PartialLogicalPlan {
18+
LogicalOperator(LogicalOperator),
19+
ScalarOperator(ScalarOperator),
20+
GroupId(GroupId),
1021
}
1122

12-
pub struct GroupId(usize);
23+
/// A type representing a tree of logical nodes, physical nodes, scalar nodes, and group IDs.
24+
///
25+
/// Note that group IDs must be leaves of this tree, and that physical nodes cannot have children
26+
/// that are logical nodes.
27+
///
28+
/// TODO Make this an actual tree with the correct modeling of types.
29+
pub enum PartialPhysicalPlan {
30+
LogicalOperator(LogicalOperator),
31+
PhysicalOperator(PhysicalOperator),
32+
ScalarOperator(ScalarOperator),
33+
GroupId(GroupId),
34+
}
1335

1436
/// An in-memory tree of logical operators. Used as the input / entrypoint of the optimizer.
1537
///

optd-types/src/memo/mod.rs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,12 @@
1-
use relation::{LogicalExpression, Relation};
2-
use scalar::Scalar;
1+
use crate::expression::{Expression, LogicalExpression};
2+
use crate::{PartialLogicalPlan, PartialPhysicalPlan};
33

4-
use crate::{GroupId, Rule};
5-
6-
mod relation;
7-
mod scalar;
8-
9-
/// A type representing an optimization node / object in the memo table.
10-
pub enum MemoNode {
11-
Relation(Relation),
12-
Scalar(Scalar),
13-
}
14-
15-
pub struct LogicalOperator;
16-
17-
pub struct PhysicalOperator;
18-
19-
/// A type representing a tree of logical nodes, scalar nodes, and group IDs.
20-
///
21-
/// Note that group IDs must be leaves of this tree.
22-
///
23-
/// TODO Make this an actual tree with the correct modeling of types.
24-
pub enum PartialLogicalExpression {
25-
LogicalOperator(LogicalOperator),
26-
Scalar(Scalar),
27-
GroupId(GroupId),
28-
}
29-
30-
/// A type representing a tree of logical nodes, physical nodes, scalar nodes, and group IDs.
31-
///
32-
/// Note that group IDs must be leaves of this tree, and that physical nodes cannot have children
33-
/// that are logical nodes.
4+
/// A type representing a transformation or implementation rule for query operators.
345
///
35-
/// TODO Make this an actual tree with the correct modeling of types.
36-
pub enum PartialPhysicalExpression {
37-
LogicalOperator(LogicalOperator),
38-
PhysicalOperator(PhysicalOperator),
39-
Scalar(Scalar),
40-
GroupId(GroupId),
6+
/// TODO The variants are just placeholders.
7+
pub enum Rule {
8+
Transformation,
9+
Implementation,
4110
}
4211

4312
pub struct Memo;
@@ -54,39 +23,39 @@ impl Memo {
5423
///
5524
/// If the rule wants to match against `Filter(Join(?L, ?R))`, then this function will partially
5625
/// materialize two expressions `Filter(e1)` and `Filter(e2)`.
57-
pub async fn check_transformation(
26+
pub async fn check_transformation(
5827
&self,
5928
expr: LogicalExpression,
6029
rule: Rule,
61-
) -> Vec<PartialLogicalExpression> {
30+
) -> Vec<PartialLogicalPlan> {
6231
todo!()
6332
}
6433

6534
pub async fn check_implementation(
6635
&self,
6736
expr: LogicalExpression,
6837
rule: Rule,
69-
) -> Vec<PartialPhysicalExpression> {
38+
) -> Vec<PartialPhysicalPlan> {
7039
todo!()
7140
}
7241

7342
pub fn apply_transformation(
7443
&mut self,
75-
expr: PartialLogicalExpression,
44+
expr: PartialLogicalPlan,
7645
rule: Rule,
77-
) -> Vec<MemoNode> {
46+
) -> Vec<Expression> {
7847
todo!()
7948
}
8049

8150
pub fn apply_implementation(
8251
&mut self,
83-
expr: PartialPhysicalExpression,
52+
expr: PartialPhysicalPlan,
8453
rule: Rule,
85-
) -> Vec<MemoNode> {
54+
) -> Vec<Expression> {
8655
todo!()
8756
}
8857

89-
pub fn add_expressions(&mut self, new_exprs: Vec<MemoNode>) {
58+
pub async fn add_expressions(&mut self, new_exprs: Vec<Expression>) {
9059
todo!()
9160
}
9261
}

optd-types/src/memo/relation/mod.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)