Skip to content

Commit 6497e62

Browse files
authored
Clean up doc comments and add periods (#43)
## Problem Cleans up a bit of the CPS PR. ## Summary of changes This commit adds periods to all of the comments in the cir and engine. I also added some more detail here and there. This commit also unifies all of the types in the cir to make it easier to interact with those types. Imo it makes more sense to have them all in one place rather than to have to figure out the paths to each of them every time you import.
1 parent 60c275f commit 6497e62

28 files changed

+506
-517
lines changed

optd-core/src/bridge/from_cir.rs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
use crate::cir::{
2-
goal::Goal,
3-
group::GroupId,
4-
operators::{Child, OperatorData},
5-
plans::{PartialLogicalPlan, PartialPhysicalPlan},
6-
properties::{LogicalProperties, PhysicalProperties, PropertiesData},
7-
};
1+
//! Converts optd's type representations (CIR) into DSL [`Value`]s (HIR).
2+
3+
use crate::cir::*;
84
use optd_dsl::analyzer::hir::{
95
self, CoreData, Literal, LogicalOp, Materializable, Operator, PhysicalOp, Value,
106
};
@@ -13,19 +9,15 @@ use CoreData::*;
139
use Literal::*;
1410
use Materializable::*;
1511

16-
//=============================================================================
17-
// Main conversion functions
18-
//=============================================================================
19-
20-
/// Converts a PartialLogicalPlan into a HIR Value representation.
12+
/// Converts a [`PartialLogicalPlan`] into a [`Value`].
2113
pub(crate) fn partial_logical_to_value(plan: &PartialLogicalPlan) -> Value {
2214
match plan {
2315
PartialLogicalPlan::UnMaterialized(group_id) => {
24-
// For unmaterialized logical operators, we create a Value with the group ID
16+
// For unmaterialized logical operators, we create a `Value` with the group ID.
2517
Value(Logical(LogicalOp(UnMaterialized(hir::GroupId(group_id.0)))))
2618
}
2719
PartialLogicalPlan::Materialized(node) => {
28-
// For materialized logical operators, we create a Value with the operator data
20+
// For materialized logical operators, we create a `Value` with the operator data.
2921
let operator = Operator {
3022
tag: node.tag.clone(),
3123
data: convert_operator_data_to_values(&node.data),
@@ -37,11 +29,11 @@ pub(crate) fn partial_logical_to_value(plan: &PartialLogicalPlan) -> Value {
3729
}
3830
}
3931

40-
/// Converts a PartialPhysicalPlan into a HIR Value representation.
32+
/// Converts a [`PartialPhysicalPlan`] into a [`Value`].
4133
pub(crate) fn partial_physical_to_value(plan: &PartialPhysicalPlan) -> Value {
4234
match plan {
4335
PartialPhysicalPlan::UnMaterialized(goal) => {
44-
// For unmaterialized physical operators, we create a Value with the goal
36+
// For unmaterialized physical operators, we create a `Value` with the goal
4537
let hir_goal = cir_goal_to_hir(goal);
4638
Value(Physical(PhysicalOp(UnMaterialized(hir_goal))))
4739
}
@@ -58,7 +50,7 @@ pub(crate) fn partial_physical_to_value(plan: &PartialPhysicalPlan) -> Value {
5850
}
5951
}
6052

61-
/// Converts LogicalProperties to a HIR Value representation.
53+
/// Converts [`LogicalProperties`] into a [`Value`].
6254
#[allow(dead_code)]
6355
pub(crate) fn logical_properties_to_value(properties: &LogicalProperties) -> Value {
6456
match &properties.0 {
@@ -67,19 +59,15 @@ pub(crate) fn logical_properties_to_value(properties: &LogicalProperties) -> Val
6759
}
6860
}
6961

70-
/// Converts PhysicalProperties to a HIR Value representation.
62+
/// Converts [`PhysicalProperties`] into a [`Value`].
7163
pub(crate) fn physical_properties_to_value(properties: &PhysicalProperties) -> Value {
7264
match &properties.0 {
7365
Some(data) => properties_data_to_value(data),
7466
None => Value(Null),
7567
}
7668
}
7769

78-
//=============================================================================
79-
// CIR to HIR conversion helpers
80-
//=============================================================================
81-
82-
/// Converts a CIR Goal to a HIR Goal.
70+
/// Converts a CIR [`Goal`] to a HIR [`Goal`](hir::Goal).
8371
fn cir_goal_to_hir(goal: &Goal) -> hir::Goal {
8472
let group_id = cir_group_id_to_hir(&goal.0);
8573
let properties = physical_properties_to_value(&goal.1);
@@ -90,12 +78,12 @@ fn cir_goal_to_hir(goal: &Goal) -> hir::Goal {
9078
}
9179
}
9280

93-
/// Converts a CIR GroupId to a HIR GroupId.
81+
/// Converts a CIR [`GroupId`] to a HIR [`GroupId`](hir::GroupId).
9482
fn cir_group_id_to_hir(group_id: &GroupId) -> hir::GroupId {
9583
hir::GroupId(group_id.0)
9684
}
9785

98-
/// Generic function to convert a Vec of Children to Vec of Values.
86+
/// A generic function to convert a slice of children into a vector of [`Value`]s.
9987
fn convert_children_to_values<T, F>(children: &[Child<Arc<T>>], converter: F) -> Vec<Value>
10088
where
10189
F: Fn(&T) -> Value,
@@ -112,12 +100,12 @@ where
112100
.collect()
113101
}
114102

115-
/// Converts a slice of OperatorData to a Vec of HIR Values.
103+
/// Converts a slice of [`OperatorData`] into a vector of [`Value`]s.
116104
fn convert_operator_data_to_values(data: &[OperatorData]) -> Vec<Value> {
117105
data.iter().map(operator_data_to_value).collect()
118106
}
119107

120-
/// Converts an OperatorData to a HIR Value representation.
108+
/// Converts an [`OperatorData`] into a [`Value`].
121109
fn operator_data_to_value(data: &OperatorData) -> Value {
122110
match data {
123111
OperatorData::Int64(i) => Value(Literal(Int64(*i))),
@@ -132,7 +120,7 @@ fn operator_data_to_value(data: &OperatorData) -> Value {
132120
}
133121
}
134122

135-
/// Converts a PropertiesData to a HIR Value representation.
123+
/// Converts a [`PropertiesData`] into a [`Value`].
136124
fn properties_data_to_value(data: &PropertiesData) -> Value {
137125
match data {
138126
PropertiesData::Int64(i) => Value(Literal(Int64(*i))),

optd-core/src/bridge/into_cir.rs

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
use crate::cir::{
2-
goal::{Cost, Goal},
3-
group::GroupId,
4-
operators::{Child, Operator, OperatorData},
5-
plans::{LogicalPlan, PartialLogicalPlan, PartialPhysicalPlan},
6-
properties::{LogicalProperties, PhysicalProperties, PropertiesData},
7-
};
1+
//! Converts HIR [`Value`]s into optd's type representations (CIR).
2+
3+
use crate::cir::*;
84
use optd_dsl::analyzer::hir::{self, CoreData, Literal, Materializable, Value};
95
use std::sync::Arc;
106
use Child::*;
117
use CoreData::*;
128
use Literal::*;
139
use Materializable::*;
1410

15-
//=============================================================================
16-
// Main conversion functions
17-
//=============================================================================
18-
19-
/// Converts a HIR Value into a PartialLogicalPlan representation.
11+
/// Converts a [`Value`] into a [`PartialLogicalPlan`].
2012
///
21-
/// Transforms the DSL's HIR into the optimizer's IR for logical operators.
13+
/// # Panics
14+
///
15+
/// Panics if the [`Value`] is not a [`Logical`] variant.
2216
pub(crate) fn value_to_partial_logical(value: &Value) -> PartialLogicalPlan {
2317
match &value.0 {
2418
Logical(logical_op) => match &logical_op.0 {
@@ -35,9 +29,11 @@ pub(crate) fn value_to_partial_logical(value: &Value) -> PartialLogicalPlan {
3529
}
3630
}
3731

38-
/// Converts a HIR Value into a PartialPhysicalPlan representation.
32+
/// Converts a [`Value`] into a [`PartialPhysicalPlan`].
33+
///
34+
/// # Panics
3935
///
40-
/// Transforms the DSL's HIR into the CIR for physical operators.
36+
/// Panics if the [`Value`] is not a [`Physical`] variant.
4137
pub(crate) fn value_to_partial_physical(value: &Value) -> PartialPhysicalPlan {
4238
match &value.0 {
4339
Physical(physical_op) => match &physical_op.0 {
@@ -54,47 +50,57 @@ pub(crate) fn value_to_partial_physical(value: &Value) -> PartialPhysicalPlan {
5450
}
5551
}
5652

57-
/// Converts a HIR Value into a CIR cost.
53+
/// Converts a [`Value`] into a CIR [`Cost`].
54+
///
55+
/// # Panics
56+
///
57+
/// Panics if the [`Value`] is not a [`Literal`] variant with a [`Float64`] value.
5858
pub(crate) fn value_to_cost(value: &Value) -> Cost {
5959
match &value.0 {
6060
Literal(Float64(f)) => Cost(*f),
6161
_ => panic!("Expected Float64 literal, found: {:?}", value.0),
6262
}
6363
}
6464

65-
/// Convert HIR properties value to CIR LogicalProperties
65+
/// Converts an HIR properties [`Value`] into a CIR [`LogicalProperties`].
6666
pub(crate) fn value_to_logical_properties(properties_value: &Value) -> LogicalProperties {
6767
match &properties_value.0 {
6868
Null => LogicalProperties(None),
6969
_ => LogicalProperties(Some(value_to_properties_data(properties_value))),
7070
}
7171
}
7272

73-
/// Converts a HIR GroupId to a CIR GroupId.
73+
/// Convert an HIR properties [`Value`] into a CIR [`PhysicalProperties`].
74+
fn value_to_physical_properties(properties_value: &Value) -> PhysicalProperties {
75+
match &properties_value.0 {
76+
Null => PhysicalProperties(None),
77+
_ => PhysicalProperties(Some(value_to_properties_data(properties_value))),
78+
}
79+
}
80+
81+
/// Converts an HIR [`GroupId`](hir::GroupId) to a CIR [`GroupId`].
7482
///
75-
/// This function provides a consistent way to convert group identifiers
76-
/// from the HIR representation to the optimizer's internal representation.
83+
/// This function provides a consistent way to convert group identifiers from the HIR into the
84+
/// optimizer's internal representation (CIR).
7785
pub(crate) fn hir_group_id_to_cir(hir_group_id: &hir::GroupId) -> GroupId {
7886
GroupId(hir_group_id.0)
7987
}
8088

81-
/// Converts a HIR Goal to a CIR Goal.
82-
///
83-
/// Transforms the DSL's HIR Goal into the optimizer's IR Goal representation,
84-
/// handling both the group ID and physical properties components.
89+
/// Converts an HIR [`Goal`](hir::Goal) to a CIR [`Goal`].
8590
pub(crate) fn hir_goal_to_cir(hir_goal: &hir::Goal) -> Goal {
8691
let group_id = hir_group_id_to_cir(&hir_goal.group_id);
8792
let properties = value_to_physical_properties(&hir_goal.properties);
8893
Goal(group_id, properties)
8994
}
9095

91-
//=============================================================================
92-
// HIR to CIR conversion helpers
93-
//=============================================================================
94-
95-
/// Converts a HIR Value into a complete LogicalPlan (not a partial plan).
96+
/// Converts a [`Value`] into a fully materialized [`LogicalPlan`].
9697
///
97-
/// Used when fully materializing a logical expression for use in properties.
98+
/// We use this function when materializing a logical expression for use in properties.
99+
///
100+
/// # Panics
101+
///
102+
/// Panics if the [`Value`] is not a [`Logical`] variant or if the [`Logical`] variant is not a
103+
/// [`Materialized`] variant.
98104
fn value_to_logical(value: &Value) -> LogicalPlan {
99105
match &value.0 {
100106
Logical(logical_op) => match &logical_op.0 {
@@ -111,15 +117,8 @@ fn value_to_logical(value: &Value) -> LogicalPlan {
111117
}
112118
}
113119

114-
/// Convert HIR properties value to CIR PhysicalProperties
115-
fn value_to_physical_properties(properties_value: &Value) -> PhysicalProperties {
116-
match &properties_value.0 {
117-
Null => PhysicalProperties(None),
118-
_ => PhysicalProperties(Some(value_to_properties_data(properties_value))),
119-
}
120-
}
121-
122-
/// Converts a Vec of Values to Vec of Children for any target type.
120+
/// A generic function to convert a slice of [`Value`]s into a vector of mapped results via the
121+
/// input `converter` function.
123122
fn convert_values_to_children<T, F>(values: &[Value], converter: F) -> Vec<Child<Arc<T>>>
124123
where
125124
F: Fn(&Value) -> T,
@@ -128,25 +127,32 @@ where
128127
values
129128
.iter()
130129
.map(|value| match &value.0 {
131-
Array(elements) => {
132-
VarLength(elements.iter().map(|el| Arc::new(converter(el))).collect())
133-
}
130+
Array(elements) => VarLength(
131+
elements
132+
.iter()
133+
.map(|elem| Arc::new(converter(elem)))
134+
.collect(),
135+
),
134136
_ => Singleton(Arc::new(converter(value))),
135137
})
136138
.collect()
137139
}
138140

139-
/// Converts a slice of HIR Values to a Vec of OperatorData.
141+
/// Converts a slice of [`Value`]s into a vector of [`OperatorData`].
140142
fn convert_values_to_operator_data(values: &[Value]) -> Vec<OperatorData> {
141143
values.iter().map(value_to_operator_data).collect()
142144
}
143145

144-
/// Converts a slice of HIR Values to a Vec of PropertiesData.
146+
/// Converts a slice of [`Value`]s into a vector of [`PropertiesData`].
145147
fn convert_values_to_properties_data(values: &[Value]) -> Vec<PropertiesData> {
146148
values.iter().map(value_to_properties_data).collect()
147149
}
148150

149-
/// Converts a HIR Value to an OperatorData representation.
151+
/// Converts a [`Value`] into an [`OperatorData`] representation.
152+
///
153+
/// # Panics
154+
///
155+
/// Panics if the [`Value`] cannot be converted to [`OperatorData`], such as a [`Unit`] literal.
150156
fn value_to_operator_data(value: &Value) -> OperatorData {
151157
match &value.0 {
152158
Literal(constant) => match constant {
@@ -164,7 +170,11 @@ fn value_to_operator_data(value: &Value) -> OperatorData {
164170
}
165171
}
166172

167-
/// Converts a HIR Value to a PropertiesData representation.
173+
/// Converts a [`Value`] into a [`PropertiesData`] representation.
174+
///
175+
/// # Panics
176+
///
177+
/// Panics if the [`Value`] cannot be converted to [`PropertiesData`], such as a [`Unit`] literal.
168178
fn value_to_properties_data(value: &Value) -> PropertiesData {
169179
match &value.0 {
170180
Literal(constant) => match constant {

optd-core/src/bridge/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
//! This module provides bridge functionality between the DSL's internal representation (HIR)
2-
//! and the query optimizer's intermediate representation (Optd-IR).
1+
//! This module provides bridge functionality between the DSL's internal representation (HIR) and
2+
//! the query optimizer's intermediate representation (Optd-IR).
33
//!
44
//! The bridge consists of two main components:
5-
//! - `into_optd`: Converts HIR Value objects into Optd's PartialPlan representations
6-
//! - `from_optd`: Converts Optd's PartialPlan representations into HIR Value objects
75
//!
8-
//! These bidirectional conversions enable the DSL to interact with the query optimizer,
9-
//! allowing rule-based transformations to be applied to query plans while maintaining
10-
//! the ability to work with both representations.
6+
//! - [`from_cir`]: Converts optd's type representations (CIR) into DSL [`Value`]s (HIR).
7+
//! - [`into_cir`]: Converts HIR [`Value`]s into optd's type representations (CIR).
8+
//!
9+
//! These bidirectional conversions enable the DSL to interact with the query optimizer, allowing
10+
//! rule-based transformations to be applied to query plans while maintaining the ability to work
11+
//! with both representations.
12+
//!
13+
//! [`Value`]: optd_dsl::analyzer::hir::Value
1114
1215
pub mod from_cir;
1316
pub mod into_cir;

0 commit comments

Comments
 (0)