Skip to content

Commit fc0e77e

Browse files
authored
feat: DSL Engine and HIR (#34)
# OPTD Engine Implementation This PR implements the OPTD engine that serves as the interface between the DSL and the optimizer driver. The engine provides the essential APIs for rule application, cost model integration, and catalog access that drive the exploration process. It enables efficient query plan transformations while managing the complexity of multiple possible transformation paths.
1 parent 8056a4b commit fc0e77e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3292
-1897
lines changed

Cargo.lock

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

optd-core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ proc-macro2.workspace = true
1414
sqlx = { version = "0.8", features = [ "sqlite", "runtime-tokio", "migrate" ] }
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = { version = "1", features = ["raw_value"] }
17-
dotenvy = "0.15"
17+
dotenvy = "0.15"
18+
ordered-float = { version = "5.0.0", features = ["serde"] }

optd-core/src/cascades/expressions.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
//! Types for logical and physical expressions in the optimizer.
22
3+
use crate::operators::relational::logical::LogicalOperator;
34
use crate::operators::relational::physical::PhysicalOperator;
45
use crate::operators::scalar::ScalarOperator;
5-
use crate::{operators::relational::logical::LogicalOperator, values::OptdValue};
66
use serde::Deserialize;
77

88
use super::goal::GoalId;
99
use super::groups::{RelationalGroupId, ScalarGroupId};
10+
use super::ir::OperatorData;
1011

1112
/// A logical expression in the memo table.
12-
pub type LogicalExpression = LogicalOperator<OptdValue, RelationalGroupId, ScalarGroupId>;
13+
pub type LogicalExpression = LogicalOperator<OperatorData, RelationalGroupId, ScalarGroupId>;
1314

1415
/// A physical expression in the memo table.
15-
pub type PhysicalExpression = PhysicalOperator<OptdValue, GoalId, ScalarGroupId>;
16+
pub type PhysicalExpression = PhysicalOperator<OperatorData, GoalId, ScalarGroupId>;
1617

1718
/// A scalar expression in the memo table.
18-
pub type ScalarExpression = ScalarOperator<OptdValue, ScalarGroupId>;
19+
pub type ScalarExpression = ScalarOperator<OperatorData, ScalarGroupId>;
1920

2021
/// A unique identifier for a logical expression in the memo table.
2122
#[repr(transparent)]

optd-core/src/cascades/ir.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use super::groups::{RelationalGroupId, ScalarGroupId};
2+
use ordered_float::OrderedFloat;
3+
use serde::{Deserialize, Serialize};
4+
5+
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
6+
pub enum OperatorData {
7+
Int64(i64),
8+
Float64(OrderedFloat<f64>),
9+
String(String),
10+
Bool(bool),
11+
Struct(String, Vec<OperatorData>),
12+
Array(Vec<OperatorData>),
13+
}
14+
15+
impl OperatorData {
16+
pub fn as_str(&self) -> Option<&str> {
17+
match self {
18+
OperatorData::String(s) => Some(s),
19+
_ => None,
20+
}
21+
}
22+
23+
pub fn as_bool(&self) -> Option<bool> {
24+
match self {
25+
OperatorData::Bool(b) => Some(*b),
26+
_ => None,
27+
}
28+
}
29+
30+
pub fn as_i64(&self) -> Option<i64> {
31+
match self {
32+
OperatorData::Int64(i) => Some(*i),
33+
_ => None,
34+
}
35+
}
36+
}
37+
38+
#[derive(Clone, Debug, PartialEq)]
39+
pub enum Children<T> {
40+
Singleton(T),
41+
VarLength(Vec<T>),
42+
}
43+
44+
#[derive(Clone, Debug, PartialEq)]
45+
pub enum PartialLogicalPlan {
46+
PartialMaterialized {
47+
tag: String,
48+
data: Vec<OperatorData>,
49+
relational_children: Vec<Children<PartialLogicalPlan>>,
50+
scalar_children: Vec<Children<PartialScalarPlan>>,
51+
},
52+
UnMaterialized(RelationalGroupId),
53+
}
54+
55+
#[derive(Clone, Debug, PartialEq)]
56+
pub enum PartialScalarPlan {
57+
PartialMaterialized {
58+
tag: String,
59+
data: Vec<OperatorData>,
60+
scalar_children: Vec<Children<PartialScalarPlan>>,
61+
},
62+
UnMaterialized(ScalarGroupId),
63+
}
64+
65+
#[derive(Clone, Debug, PartialEq)]
66+
pub enum PartialPhysicalPlan {
67+
PartialMaterialized {
68+
tag: String,
69+
data: Vec<OperatorData>,
70+
relational_children: Vec<Children<PartialPhysicalPlan>>,
71+
scalar_children: Vec<Children<PartialScalarPlan>>,
72+
},
73+
UnMaterialized(RelationalGroupId),
74+
}

optd-core/src/cascades/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod expressions;
22
pub mod goal;
33
pub mod groups;
4+
pub mod ir;
45
pub mod memo;
56
pub mod properties;
67

optd-core/src/cascades/properties/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::values::OptdValue;
3+
use crate::cascades::ir::OperatorData;
44

55
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Default)]
66
pub struct PhysicalProperties {
@@ -11,5 +11,5 @@ pub struct PhysicalProperties {
1111
pub struct SortProperty {
1212
/// Each tuple is a column index, direction pair.
1313
/// e.g. vec![(0, Asc), (1, Desc)]
14-
pub sort_orders: Vec<(OptdValue, OptdValue)>,
14+
pub sort_orders: Vec<(OperatorData, OperatorData)>,
1515
}

optd-core/src/engine/actions/analyzers/logical.rs

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

optd-core/src/engine/actions/analyzers/mod.rs

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

optd-core/src/engine/actions/analyzers/scalar.rs

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

optd-core/src/engine/actions/mod.rs

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

0 commit comments

Comments
 (0)