Skip to content

Commit

Permalink
rename many types
Browse files Browse the repository at this point in the history
  • Loading branch information
connortsui20 committed Jan 15, 2025
1 parent 3240e31 commit d5cfcba
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 55 deletions.
34 changes: 32 additions & 2 deletions optd-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
mod memo;
pub use memo::MemoNode;
pub use memo::MemoOperator;

/// A type representing a transformation or implementation rule for query operators.
///
/// TODO The variants are just placeholders.
pub enum Rule {
Transformation,
Implementation
Implementation,
}

pub struct GroupId(usize);

Check warning on line 12 in optd-types/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/lib.rs#L12

warning: field `0` is never read --> optd-types/src/lib.rs:12:20 | 12 | pub struct GroupId(usize); | ------- ^^^^^ | | | field in this struct | = help: consider removing this field = note: `#[warn(dead_code)]` on by default
Raw output
optd-types/src/lib.rs:12:12:w:warning: field `0` is never read
  --> optd-types/src/lib.rs:12:20
   |
12 | pub struct GroupId(usize);
   |            ------- ^^^^^
   |            |
   |            field in this struct
   |
   = help: consider removing this field
   = note: `#[warn(dead_code)]` on by default


__END__

pub struct LogicalExpression;

pub struct PhysicalExpression;

pub struct ScalarExpression;

/// 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 enum PartialLogicalExpression {
LogicalExpression(LogicalExpression),
ScalarExpression(ScalarExpression),
GroupId(GroupId),
}

/// 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 enum PartialPhysicalExpression {
LogicalExpression(LogicalExpression),
PhysicalExpression(PhysicalExpression),
Scalar(ScalarExpression),
GroupId(GroupId),
}

/// 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
Expand Down
53 changes: 12 additions & 41 deletions optd-types/src/memo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,14 @@
use relation::{LogicalExpression, Relation};
use scalar::Scalar;

use crate::{GroupId, Rule};
use crate::{PartialLogicalExpression, PartialPhysicalExpression, Rule};
use relation::{LogicalOperator, RelationOperator};
use scalar::ScalarOperator;

mod relation;
mod scalar;

/// A type representing an optimization node / object in the memo table.
pub enum MemoNode {
Relation(Relation),
Scalar(Scalar),
}

pub struct LogicalOperator;

pub struct PhysicalOperator;

/// 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 enum PartialLogicalExpression {
LogicalOperator(LogicalOperator),
Scalar(Scalar),
GroupId(GroupId),
}

/// 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 enum PartialPhysicalExpression {
LogicalOperator(LogicalOperator),
PhysicalOperator(PhysicalOperator),
Scalar(Scalar),
GroupId(GroupId),
pub enum MemoOperator {
RelationOperator(RelationOperator),
ScalarOperator(ScalarOperator),
}

pub struct Memo;

Check warning on line 14 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L14

warning: struct `Memo` is never constructed --> optd-types/src/memo/mod.rs:14:12 | 14 | pub struct Memo; | ^^^^
Raw output
optd-types/src/memo/mod.rs:14:12:w:warning: struct `Memo` is never constructed
  --> optd-types/src/memo/mod.rs:14:12
   |
14 | pub struct Memo;
   |            ^^^^


__END__
Expand All @@ -54,17 +25,17 @@ impl Memo {
///
/// If the rule wants to match against `Filter(Join(?L, ?R))`, then this function will partially
/// materialize two expressions `Filter(e1)` and `Filter(e2)`.
pub async fn check_transformation(
pub async fn check_transformation(
&self,
expr: LogicalExpression,
expr: LogicalOperator,

Check warning on line 30 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L30

warning: unused variable: `expr` --> optd-types/src/memo/mod.rs:30:9 | 30 | expr: LogicalOperator, | ^^^^ help: if this is intentional, prefix it with an underscore: `_expr` | = note: `#[warn(unused_variables)]` on by default
Raw output
optd-types/src/memo/mod.rs:30:9:w:warning: unused variable: `expr`
  --> optd-types/src/memo/mod.rs:30:9
   |
30 |         expr: LogicalOperator,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_expr`
   |
   = note: `#[warn(unused_variables)]` on by default


__END__
rule: Rule,

Check warning on line 31 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L31

warning: unused variable: `rule` --> optd-types/src/memo/mod.rs:31:9 | 31 | rule: Rule, | ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`
Raw output
optd-types/src/memo/mod.rs:31:9:w:warning: unused variable: `rule`
  --> optd-types/src/memo/mod.rs:31:9
   |
31 |         rule: Rule,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`


__END__
) -> Vec<PartialLogicalExpression> {
todo!()
}

pub async fn check_implementation(
&self,
expr: LogicalExpression,
expr: LogicalOperator,

Check warning on line 38 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L38

warning: unused variable: `expr` --> optd-types/src/memo/mod.rs:38:9 | 38 | expr: LogicalOperator, | ^^^^ help: if this is intentional, prefix it with an underscore: `_expr`
Raw output
optd-types/src/memo/mod.rs:38:9:w:warning: unused variable: `expr`
  --> optd-types/src/memo/mod.rs:38:9
   |
38 |         expr: LogicalOperator,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_expr`


__END__
rule: Rule,

Check warning on line 39 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L39

warning: unused variable: `rule` --> optd-types/src/memo/mod.rs:39:9 | 39 | rule: Rule, | ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`
Raw output
optd-types/src/memo/mod.rs:39:9:w:warning: unused variable: `rule`
  --> optd-types/src/memo/mod.rs:39:9
   |
39 |         rule: Rule,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`


__END__
) -> Vec<PartialPhysicalExpression> {
todo!()
Expand All @@ -74,19 +45,19 @@ impl Memo {
&mut self,
expr: PartialLogicalExpression,

Check warning on line 46 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L46

warning: unused variable: `expr` --> optd-types/src/memo/mod.rs:46:9 | 46 | expr: PartialLogicalExpression, | ^^^^ help: if this is intentional, prefix it with an underscore: `_expr`
Raw output
optd-types/src/memo/mod.rs:46:9:w:warning: unused variable: `expr`
  --> optd-types/src/memo/mod.rs:46:9
   |
46 |         expr: PartialLogicalExpression,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_expr`


__END__
rule: Rule,

Check warning on line 47 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L47

warning: unused variable: `rule` --> optd-types/src/memo/mod.rs:47:9 | 47 | rule: Rule, | ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`
Raw output
optd-types/src/memo/mod.rs:47:9:w:warning: unused variable: `rule`
  --> optd-types/src/memo/mod.rs:47:9
   |
47 |         rule: Rule,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`


__END__
) -> Vec<MemoNode> {
) -> Vec<MemoOperator> {
todo!()
}

pub fn apply_implementation(
&mut self,
expr: PartialPhysicalExpression,

Check warning on line 54 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L54

warning: unused variable: `expr` --> optd-types/src/memo/mod.rs:54:9 | 54 | expr: PartialPhysicalExpression, | ^^^^ help: if this is intentional, prefix it with an underscore: `_expr`
Raw output
optd-types/src/memo/mod.rs:54:9:w:warning: unused variable: `expr`
  --> optd-types/src/memo/mod.rs:54:9
   |
54 |         expr: PartialPhysicalExpression,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_expr`


__END__
rule: Rule,

Check warning on line 55 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L55

warning: unused variable: `rule` --> optd-types/src/memo/mod.rs:55:9 | 55 | rule: Rule, | ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`
Raw output
optd-types/src/memo/mod.rs:55:9:w:warning: unused variable: `rule`
  --> optd-types/src/memo/mod.rs:55:9
   |
55 |         rule: Rule,
   |         ^^^^ help: if this is intentional, prefix it with an underscore: `_rule`


__END__
) -> Vec<MemoNode> {
) -> Vec<MemoOperator> {
todo!()
}

pub fn add_expressions(&mut self, new_exprs: Vec<MemoNode>) {
pub fn add_expressions(&mut self, new_exprs: Vec<MemoOperator>) {

Check warning on line 60 in optd-types/src/memo/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/mod.rs#L60

warning: unused variable: `new_exprs` --> optd-types/src/memo/mod.rs:60:39 | 60 | pub fn add_expressions(&mut self, new_exprs: Vec<MemoOperator>) { | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_new_exprs`
Raw output
optd-types/src/memo/mod.rs:60:39:w:warning: unused variable: `new_exprs`
  --> optd-types/src/memo/mod.rs:60:39
   |
60 |     pub fn add_expressions(&mut self, new_exprs: Vec<MemoOperator>) {
   |                                       ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_new_exprs`


__END__
todo!()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::GroupId;

/// A type representing different kinds of logical expressions / operators.
pub enum LogicalExpression {
pub enum LogicalOperator {
Scan(Scan),

Check warning on line 5 in optd-types/src/memo/relation/logical.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/relation/logical.rs#L5

warning: type `memo::relation::logical::Scan` is more private than the item `memo::relation::logical::LogicalOperator::Scan::0` --> optd-types/src/memo/relation/logical.rs:5:10 | 5 | Scan(Scan), | ^^^^ field `memo::relation::logical::LogicalOperator::Scan::0` is reachable at visibility `pub` | note: but type `memo::relation::logical::Scan` is only usable at visibility `pub(self)` --> optd-types/src/memo/relation/logical.rs:11:1 | 11 | struct Scan { | ^^^^^^^^^^^ = note: `#[warn(private_interfaces)]` on by default
Raw output
optd-types/src/memo/relation/logical.rs:5:10:w:warning: type `memo::relation::logical::Scan` is more private than the item `memo::relation::logical::LogicalOperator::Scan::0`
  --> optd-types/src/memo/relation/logical.rs:5:10
   |
5  |     Scan(Scan),
   |          ^^^^ field `memo::relation::logical::LogicalOperator::Scan::0` is reachable at visibility `pub`
   |
note: but type `memo::relation::logical::Scan` is only usable at visibility `pub(self)`
  --> optd-types/src/memo/relation/logical.rs:11:1
   |
11 | struct Scan {
   | ^^^^^^^^^^^
   = note: `#[warn(private_interfaces)]` on by default


__END__
Filter(Filter),

Check warning on line 6 in optd-types/src/memo/relation/logical.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/relation/logical.rs#L6

warning: type `memo::relation::logical::Filter` is more private than the item `memo::relation::logical::LogicalOperator::Filter::0` --> optd-types/src/memo/relation/logical.rs:6:12 | 6 | Filter(Filter), | ^^^^^^ field `memo::relation::logical::LogicalOperator::Filter::0` is reachable at visibility `pub` | note: but type `memo::relation::logical::Filter` is only usable at visibility `pub(self)` --> optd-types/src/memo/relation/logical.rs:15:1 | 15 | struct Filter { | ^^^^^^^^^^^^^
Raw output
optd-types/src/memo/relation/logical.rs:6:12:w:warning: type `memo::relation::logical::Filter` is more private than the item `memo::relation::logical::LogicalOperator::Filter::0`
  --> optd-types/src/memo/relation/logical.rs:6:12
   |
6  |     Filter(Filter),
   |            ^^^^^^ field `memo::relation::logical::LogicalOperator::Filter::0` is reachable at visibility `pub`
   |
note: but type `memo::relation::logical::Filter` is only usable at visibility `pub(self)`
  --> optd-types/src/memo/relation/logical.rs:15:1
   |
15 | struct Filter {
   | ^^^^^^^^^^^^^


__END__
Join(Join),

Check warning on line 7 in optd-types/src/memo/relation/logical.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/relation/logical.rs#L7

warning: type `memo::relation::logical::Join` is more private than the item `memo::relation::logical::LogicalOperator::Join::0` --> optd-types/src/memo/relation/logical.rs:7:10 | 7 | Join(Join), | ^^^^ field `memo::relation::logical::LogicalOperator::Join::0` is reachable at visibility `pub` | note: but type `memo::relation::logical::Join` is only usable at visibility `pub(self)` --> optd-types/src/memo/relation/logical.rs:20:1 | 20 | struct Join { | ^^^^^^^^^^^
Raw output
optd-types/src/memo/relation/logical.rs:7:10:w:warning: type `memo::relation::logical::Join` is more private than the item `memo::relation::logical::LogicalOperator::Join::0`
  --> optd-types/src/memo/relation/logical.rs:7:10
   |
7  |     Join(Join),
   |          ^^^^ field `memo::relation::logical::LogicalOperator::Join::0` is reachable at visibility `pub`
   |
note: but type `memo::relation::logical::Join` is only usable at visibility `pub(self)`
  --> optd-types/src/memo/relation/logical.rs:20:1
   |
20 | struct Join {
   | ^^^^^^^^^^^


__END__
Expand Down
14 changes: 7 additions & 7 deletions optd-types/src/memo/relation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod logical_expression;
pub use logical_expression::LogicalExpression;
mod logical;
pub use logical::LogicalOperator;

mod physical_expression;
pub use physical_expression::PhysicalExpression;
mod physical;
pub use physical::PhysicalOperator;

/// A type representing logical or physical operators in a relational algebraic query plan.
pub enum Relation {
Logical(LogicalExpression),
Physical(PhysicalExpression),
pub enum RelationOperator {
LogicalOperator(LogicalOperator),
PhysicalOperator(PhysicalOperator),
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::GroupId;

/// A type representing different kinds of physical expressions / operators.
pub enum PhysicalExpression {
pub enum PhysicalOperator {
TableScan(TableScan),

Check warning on line 5 in optd-types/src/memo/relation/physical.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/relation/physical.rs#L5

warning: type `memo::relation::physical::TableScan` is more private than the item `memo::relation::physical::PhysicalOperator::TableScan::0` --> optd-types/src/memo/relation/physical.rs:5:15 | 5 | TableScan(TableScan), | ^^^^^^^^^ field `memo::relation::physical::PhysicalOperator::TableScan::0` is reachable at visibility `pub` | note: but type `memo::relation::physical::TableScan` is only usable at visibility `pub(self)` --> optd-types/src/memo/relation/physical.rs:12:1 | 12 | struct TableScan { | ^^^^^^^^^^^^^^^^
Raw output
optd-types/src/memo/relation/physical.rs:5:15:w:warning: type `memo::relation::physical::TableScan` is more private than the item `memo::relation::physical::PhysicalOperator::TableScan::0`
  --> optd-types/src/memo/relation/physical.rs:5:15
   |
5  |     TableScan(TableScan),
   |               ^^^^^^^^^ field `memo::relation::physical::PhysicalOperator::TableScan::0` is reachable at visibility `pub`
   |
note: but type `memo::relation::physical::TableScan` is only usable at visibility `pub(self)`
  --> optd-types/src/memo/relation/physical.rs:12:1
   |
12 | struct TableScan {
   | ^^^^^^^^^^^^^^^^


__END__
PhysicalFilter(PhysicalFilter),

Check warning on line 6 in optd-types/src/memo/relation/physical.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/relation/physical.rs#L6

warning: type `memo::relation::physical::PhysicalFilter` is more private than the item `memo::relation::physical::PhysicalOperator::PhysicalFilter::0` --> optd-types/src/memo/relation/physical.rs:6:20 | 6 | PhysicalFilter(PhysicalFilter), | ^^^^^^^^^^^^^^ field `memo::relation::physical::PhysicalOperator::PhysicalFilter::0` is reachable at visibility `pub` | note: but type `memo::relation::physical::PhysicalFilter` is only usable at visibility `pub(self)` --> optd-types/src/memo/relation/physical.rs:16:1 | 16 | struct PhysicalFilter { | ^^^^^^^^^^^^^^^^^^^^^
Raw output
optd-types/src/memo/relation/physical.rs:6:20:w:warning: type `memo::relation::physical::PhysicalFilter` is more private than the item `memo::relation::physical::PhysicalOperator::PhysicalFilter::0`
  --> optd-types/src/memo/relation/physical.rs:6:20
   |
6  |     PhysicalFilter(PhysicalFilter),
   |                    ^^^^^^^^^^^^^^ field `memo::relation::physical::PhysicalOperator::PhysicalFilter::0` is reachable at visibility `pub`
   |
note: but type `memo::relation::physical::PhysicalFilter` is only usable at visibility `pub(self)`
  --> optd-types/src/memo/relation/physical.rs:16:1
   |
16 | struct PhysicalFilter {
   | ^^^^^^^^^^^^^^^^^^^^^


__END__
SortMergeJoin(SortMergeJoin),

Check warning on line 7 in optd-types/src/memo/relation/physical.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/relation/physical.rs#L7

warning: type `memo::relation::physical::SortMergeJoin` is more private than the item `memo::relation::physical::PhysicalOperator::SortMergeJoin::0` --> optd-types/src/memo/relation/physical.rs:7:19 | 7 | SortMergeJoin(SortMergeJoin), | ^^^^^^^^^^^^^ field `memo::relation::physical::PhysicalOperator::SortMergeJoin::0` is reachable at visibility `pub` | note: but type `memo::relation::physical::SortMergeJoin` is only usable at visibility `pub(self)` --> optd-types/src/memo/relation/physical.rs:21:1 | 21 | struct SortMergeJoin { | ^^^^^^^^^^^^^^^^^^^^
Raw output
optd-types/src/memo/relation/physical.rs:7:19:w:warning: type `memo::relation::physical::SortMergeJoin` is more private than the item `memo::relation::physical::PhysicalOperator::SortMergeJoin::0`
  --> optd-types/src/memo/relation/physical.rs:7:19
   |
7  |     SortMergeJoin(SortMergeJoin),
   |                   ^^^^^^^^^^^^^ field `memo::relation::physical::PhysicalOperator::SortMergeJoin::0` is reachable at visibility `pub`
   |
note: but type `memo::relation::physical::SortMergeJoin` is only usable at visibility `pub(self)`
  --> optd-types/src/memo/relation/physical.rs:21:1
   |
21 | struct SortMergeJoin {
   | ^^^^^^^^^^^^^^^^^^^^


__END__
Expand All @@ -18,7 +18,6 @@ struct PhysicalFilter {
predicate: GroupId,
}


struct SortMergeJoin {

Check warning on line 21 in optd-types/src/memo/relation/physical.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] optd-types/src/memo/relation/physical.rs#L21

warning: fields `left`, `right`, `condition`, and `sort_expr` are never read --> optd-types/src/memo/relation/physical.rs:22:5 | 21 | struct SortMergeJoin { | ------------- fields in this struct 22 | left: GroupId, | ^^^^ 23 | right: GroupId, | ^^^^^ 24 | condition: GroupId, | ^^^^^^^^^ 25 | sort_expr: GroupId, | ^^^^^^^^^
Raw output
optd-types/src/memo/relation/physical.rs:21:8:w:warning: fields `left`, `right`, `condition`, and `sort_expr` are never read
  --> optd-types/src/memo/relation/physical.rs:22:5
   |
21 | struct SortMergeJoin {
   |        ------------- fields in this struct
22 |     left: GroupId,
   |     ^^^^
23 |     right: GroupId,
   |     ^^^^^
24 |     condition: GroupId,
   |     ^^^^^^^^^
25 |     sort_expr: GroupId,
   |     ^^^^^^^^^


__END__
left: GroupId,
right: GroupId,
Expand All @@ -36,4 +35,3 @@ struct MergeSort {
child: GroupId,
sort_expr: GroupId,
}

2 changes: 1 addition & 1 deletion optd-types/src/memo/scalar.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// A type that represent scalar SQL expression / predicates.
///
/// TODO Add fields to this type.
pub struct Scalar;
pub struct ScalarOperator;

0 comments on commit d5cfcba

Please sign in to comment.