Skip to content

Commit 3962965

Browse files
authored
First PR cleanup (#18)
## Problem #4 Was the first major PR, but since we were making a lot of changes last minute there were a few things that slipped through with respect to quality control. ## Summary of changes - Added very strict clippy documentation requirements. Discussion below. - Added documentation for everything except the `operator::relational::physical` module and the `operator::scalar` module, as those seem kind of unstable right now. - Changed the scalar generic param of expressions to use `ScalarGroupId` instead of `GroupId`. - Added several TODOs that I think will be resolved pretty quickly, though I'd appreciate it if others took a look at those in the case that we can actually get those done now. Now that we have something to work off of, requiring documentation on everything (including private items) means that we'll pay the cost right now of making sure people understand what we're doing in the future. I'm willing to relax it a little bit if we put _other_ stuff in place that ensure nobody in the future encounters large chunks of code with zero documentation.
1 parent c41cf41 commit 3962965

File tree

23 files changed

+187
-57
lines changed

23 files changed

+187
-57
lines changed

docs/src/architecture/glossary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ See the following sections for more information.
126126

127127
A logical expression is a version of a [Relational Expression].
128128

129-
TODO(connor) Add more details.
129+
TODO(connor): Add more details.
130130

131131
Examples of logical expressions include Logical Scan, Logical Join, or Logical Sort expressions
132132
(which can just be shorthanded to Scan, Join, or Sort).
@@ -135,7 +135,7 @@ Examples of logical expressions include Logical Scan, Logical Join, or Logical S
135135

136136
A physical expression is a version of a [Relational Expression].
137137

138-
TODO(connor) Add more details.
138+
TODO(connor): Add more details.
139139

140140
Examples of physical expressions include Table Scan, Index Scan, Hash Join, or Sort Merge Join.
141141

optd-core/src/expression.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
//! Types for logical and physical expressions in the optimizer.
22
3-
use crate::memo::GroupId;
3+
use crate::memo::{GroupId, ScalarGroupId};
44
use crate::operator::relational::logical::LogicalOperator;
55
use crate::operator::relational::physical::PhysicalOperator;
66

77
/// A logical expression in the memo table.
88
///
9-
/// References children using [`GroupId`]s for expression sharing
10-
/// and memoization.
11-
pub type LogicalExpression = LogicalOperator<GroupId, GroupId>;
9+
/// References children using [`GroupId`]s for expression sharing and memoization.
10+
pub type LogicalExpression = LogicalOperator<GroupId, ScalarGroupId>;
1211

1312
/// A physical expression in the memo table.
1413
///
15-
/// Like [`LogicalExpression`] but with specific implementation
16-
/// strategies.
17-
pub type PhysicalExpression = PhysicalOperator<GroupId, GroupId>;
14+
/// Like [`LogicalExpression`] but with specific implementation strategies.
15+
pub type PhysicalExpression = PhysicalOperator<GroupId, ScalarGroupId>;

optd-core/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! TODO Add docs. We will likely want to add a `#![doc = include_str!("../README.md")]` here.
2+
3+
#![warn(missing_docs)]
4+
#![warn(clippy::missing_docs_in_private_items)]
5+
#![warn(clippy::missing_errors_doc)]
6+
#![warn(clippy::missing_panics_doc)]
7+
#![warn(clippy::missing_safety_doc)]
8+
19
pub mod expression;
210
pub mod memo;
311
pub mod operator;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
//! A logical filter.
2+
13
/// Logical filter operator that selects rows matching a condition.
24
///
35
/// Takes input relation (`Relation`) and filters rows using a boolean predicate (`Scalar`).
46
#[derive(Clone)]
57
pub struct Filter<Relation, Scalar> {
8+
/// The input relation.
69
pub child: Relation,
10+
/// The filter expression denoting the predicate condition for this filter operation.
11+
///
12+
/// For example, a filter predicate could be `column_a > 42`, or it could be something like
13+
/// `column_b < 100 AND column_c > 1000`.
714
pub predicate: Scalar,
815
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
//! A logical join.
2+
13
/// Logical join operator that combines rows from two relations.
24
///
35
/// Takes left and right relations (`Relation`) and joins their rows using a join condition
46
/// (`Scalar`).
57
#[derive(Clone)]
68
pub struct Join<Relation, Scalar> {
9+
/// TODO(alexis) Mocked for now.
710
pub join_type: String,
11+
/// The left input relation.
812
pub left: Relation,
13+
/// The right input relation.
914
pub right: Relation,
15+
/// The join expression denoting the join condition that links the two input relations.
16+
///
17+
/// For example, a join operation could have a condition on `t1.id = t2.id` (an equijoin).
1018
pub condition: Scalar,
1119
}

optd-core/src/operator/relational/logical/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use scan::Scan;
2222
/// [`LogicalPlan`]: crate::plan::logical_plan::LogicalPlan
2323
/// [`PartialLogicalPlan`]: crate::plan::partial_logical_plan::PartialLogicalPlan
2424
/// [`LogicalExpression`]: crate::expression::LogicalExpression
25+
#[allow(missing_docs)]
2526
#[derive(Clone)]
2627
pub enum LogicalOperator<Relation, Scalar> {
2728
Scan(Scan<Scalar>),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
//! A logical projection.
2+
13
/// Logical project operator that specifies output columns.
24
///
35
/// Takes input relation (`Relation`) and defines output columns/expressions
46
/// (`Scalar`).
57
#[derive(Clone)]
68
pub struct Project<Relation, Scalar> {
9+
/// The input relation.
710
pub child: Relation,
11+
/// TODO(everyone): What exactly is going on here?
812
pub fields: Vec<Scalar>,
913
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
//! A logical scan.
2+
13
/// Logical scan operator that reads from a base table.
24
///
35
/// Reads from table (`String`) and optionally filters rows using a pushdown predicate
46
/// (`Scalar`).
57
#[derive(Clone)]
68
pub struct Scan<Scalar> {
7-
pub table_name: String, // TODO(alexis): Mocked for now.
9+
/// TODO(alexis) Mocked for now.
10+
pub table_name: String,
11+
/// An optional filter expression for predicate pushdown into scan operators.
12+
///
13+
/// For example, a `Filter(Scan(A), column_a < 42)` can be converted into a predicate pushdown
14+
/// `Scan(A, column < 42)` to prevent having to materialize many tuples.
815
pub predicate: Option<Scalar>,
916
}

optd-core/src/operator/relational/physical/filter/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/// (`Scalar`) that evaluates to true/false. Only rows where predicate is true
55
/// are emitted.
66
#[derive(Clone)]
7-
pub struct Filter<Relation, Scalar> {
7+
pub struct PhysicalFilter<Relation, Scalar> {
88
pub child: Relation,
99
pub predicate: Scalar,
1010
}

optd-core/src/operator/relational/physical/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
//! Type definitions of physical operators in optd.
22
3+
// TODO(connor):
4+
// The module structure here is somewhat questionable, as it has multiple physical operators that
5+
// should really only have 1 implementor (filter and project).
6+
// For now, we can hold off on documenting stuff here until that is stabilized.
7+
#![allow(missing_docs)]
8+
39
pub mod filter;
410
pub mod join;
511
pub mod project;
612
pub mod scan;
713

8-
use filter::filter::Filter;
14+
use filter::filter::PhysicalFilter;
915
use join::{hash_join::HashJoin, merge_join::MergeJoin, nested_loop_join::NestedLoopJoin};
1016
use project::project::Project;
1117
use scan::table_scan::TableScan;
@@ -22,10 +28,11 @@ use scan::table_scan::TableScan;
2228
///
2329
/// [`PhysicalPlan`]: crate::plan::physical_plan::PhysicalPlan
2430
/// [`PhysicalExpression`]: crate::expression::PhysicalExpression
31+
#[allow(missing_docs)]
2532
#[derive(Clone)]
2633
pub enum PhysicalOperator<Relation, Scalar> {
2734
TableScan(TableScan<Scalar>),
28-
Filter(Filter<Relation, Scalar>),
35+
Filter(PhysicalFilter<Relation, Scalar>),
2936
Project(Project<Relation, Scalar>),
3037
HashJoin(HashJoin<Relation, Scalar>),
3138
NestedLoopJoin(NestedLoopJoin<Relation, Scalar>),

0 commit comments

Comments
 (0)