Skip to content

Commit 1685fba

Browse files
committed
huge refactor of persistent memo implementation
This commit completely refactors the memo table, removing the `Memo` trait and instead placing all methods directly on the `PersistentMemo` structure itself. This also cleans up some code in other places.
1 parent 2856496 commit 1685fba

File tree

8 files changed

+392
-399
lines changed

8 files changed

+392
-399
lines changed

optd-mvp/src/entities/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
22
3+
#![allow(unused_imports)]
4+
35
pub use super::cascades_group::Entity as CascadesGroup;
46
pub use super::fingerprint::Entity as Fingerprint;
57
pub use super::logical_children::Entity as LogicalChildren;

optd-mvp/src/expression/logical_expression.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@
44
//! FIXME: Representation needs to know how to "rewrite" child group IDs to whatever a fingerprint
55
//! will need.
66
//!
7-
//! TODO figure out if each relation should be in a different submodule.
7+
//! TODO Remove dead code.
8+
//! TODO Figure out if each relation should be in a different submodule.
89
//! TODO This entire file is a WIP.
910
11+
#![allow(dead_code)]
12+
1013
use crate::entities::*;
1114
use serde::{Deserialize, Serialize};
1215

13-
#[derive(Clone, Debug)]
16+
#[derive(Clone, Debug, PartialEq, Eq)]
1417
pub enum LogicalExpression {
1518
Scan(Scan),
1619
Filter(Filter),
1720
Join(Join),
1821
}
1922

20-
#[derive(Serialize, Deserialize, Clone, Debug)]
23+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
2124
pub struct Scan {
2225
table_schema: String,
2326
}
2427

25-
#[derive(Serialize, Deserialize, Clone, Debug)]
28+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
2629
pub struct Filter {
2730
child: i32,
2831
expression: String,
2932
}
3033

31-
#[derive(Serialize, Deserialize, Clone, Debug)]
34+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
3235
pub struct Join {
3336
left: i32,
3437
right: i32,
@@ -94,24 +97,24 @@ pub use build::*;
9497
#[cfg(test)]
9598
mod build {
9699
use super::*;
97-
use crate::expression::Expression;
100+
use crate::expression::LogicalExpression;
98101

99-
pub fn scan(table_schema: String) -> Expression {
100-
Expression::Logical(LogicalExpression::Scan(Scan { table_schema }))
102+
pub fn scan(table_schema: String) -> LogicalExpression {
103+
LogicalExpression::Scan(Scan { table_schema })
101104
}
102105

103-
pub fn filter(child_group: i32, expression: String) -> Expression {
104-
Expression::Logical(LogicalExpression::Filter(Filter {
106+
pub fn filter(child_group: i32, expression: String) -> LogicalExpression {
107+
LogicalExpression::Filter(Filter {
105108
child: child_group,
106109
expression,
107-
}))
110+
})
108111
}
109112

110-
pub fn join(left_group: i32, right_group: i32, expression: String) -> Expression {
111-
Expression::Logical(LogicalExpression::Join(Join {
113+
pub fn join(left_group: i32, right_group: i32, expression: String) -> LogicalExpression {
114+
LogicalExpression::Join(Join {
112115
left: left_group,
113116
right: right_group,
114117
expression,
115-
}))
118+
})
116119
}
117120
}

optd-mvp/src/expression/physical_expression.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@
22
//!
33
//! FIXME: All fields are placeholders, and group IDs are just represented as i32 for now.
44
//!
5-
//! TODO figure out if each operator should be in a different submodule.
5+
//! TODO Remove dead code.
6+
//! TODO Figure out if each operator should be in a different submodule.
67
//! TODO This entire file is a WIP.
78
9+
#![allow(dead_code)]
10+
811
use crate::entities::*;
912
use serde::{Deserialize, Serialize};
1013

11-
#[derive(Clone, Debug)]
14+
#[derive(Clone, Debug, PartialEq, Eq)]
1215
pub enum PhysicalExpression {
1316
TableScan(TableScan),
1417
Filter(PhysicalFilter),
1518
HashJoin(HashJoin),
1619
}
1720

18-
#[derive(Serialize, Deserialize, Clone, Debug)]
21+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
1922
pub struct TableScan {
2023
table_schema: String,
2124
}
2225

23-
#[derive(Serialize, Deserialize, Clone, Debug)]
26+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
2427
pub struct PhysicalFilter {
2528
child: i32,
2629
expression: String,
2730
}
2831

29-
#[derive(Serialize, Deserialize, Clone, Debug)]
32+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
3033
pub struct HashJoin {
3134
left: i32,
3235
right: i32,
@@ -92,24 +95,24 @@ pub use build::*;
9295
#[cfg(test)]
9396
mod build {
9497
use super::*;
95-
use crate::expression::Expression;
98+
use crate::expression::PhysicalExpression;
9699

97-
pub fn table_scan(table_schema: String) -> Expression {
98-
Expression::Physical(PhysicalExpression::TableScan(TableScan { table_schema }))
100+
pub fn table_scan(table_schema: String) -> PhysicalExpression {
101+
PhysicalExpression::TableScan(TableScan { table_schema })
99102
}
100103

101-
pub fn filter(child_group: i32, expression: String) -> Expression {
102-
Expression::Physical(PhysicalExpression::Filter(PhysicalFilter {
104+
pub fn filter(child_group: i32, expression: String) -> PhysicalExpression {
105+
PhysicalExpression::Filter(PhysicalFilter {
103106
child: child_group,
104107
expression,
105-
}))
108+
})
106109
}
107110

108-
pub fn hash_join(left_group: i32, right_group: i32, expression: String) -> Expression {
109-
Expression::Physical(PhysicalExpression::HashJoin(HashJoin {
111+
pub fn hash_join(left_group: i32, right_group: i32, expression: String) -> PhysicalExpression {
112+
PhysicalExpression::HashJoin(HashJoin {
110113
left: left_group,
111114
right: right_group,
112115
expression,
113-
}))
116+
})
114117
}
115118
}

optd-mvp/src/memo/interface.rs

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

optd-mvp/src/memo/mod.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,31 @@
33
//!
44
//! TODO more docs.
55
6-
mod persistent;
6+
use thiserror::Error;
7+
8+
/// A new type of an integer identifying a unique group.
9+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10+
pub struct GroupId(i32);
11+
12+
/// A new type of an integer identifying a unique logical expression.
13+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14+
pub struct LogicalExpressionId(i32);
715

8-
mod interface;
9-
pub use interface::{Memo, MemoError};
16+
/// A new type of an integer identifying a unique physical expression.
17+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
18+
pub struct PhysicalExpressionId(i32);
19+
20+
/// The different kinds of errors that might occur while running operations on a memo table.
21+
#[derive(Error, Debug)]
22+
pub enum MemoError {
23+
#[error("unknown group ID {0:?}")]
24+
UnknownGroup(GroupId),
25+
#[error("unknown logical expression ID {0:?}")]
26+
UnknownLogicalExpression(LogicalExpressionId),
27+
#[error("unknown physical expression ID {0:?}")]
28+
UnknownPhysicalExpression(PhysicalExpressionId),
29+
#[error("invalid expression encountered")]
30+
InvalidExpression,
31+
}
32+
33+
mod persistent;

0 commit comments

Comments
 (0)