Skip to content

Commit

Permalink
feat: DSL Engine and HIR (#34)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
AlSchlo authored Feb 28, 2025
1 parent 8056a4b commit fc0e77e
Show file tree
Hide file tree
Showing 87 changed files with 3,292 additions and 1,897 deletions.
14 changes: 11 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion optd-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ proc-macro2.workspace = true
sqlx = { version = "0.8", features = [ "sqlite", "runtime-tokio", "migrate" ] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1", features = ["raw_value"] }
dotenvy = "0.15"
dotenvy = "0.15"
ordered-float = { version = "5.0.0", features = ["serde"] }
9 changes: 5 additions & 4 deletions optd-core/src/cascades/expressions.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
//! Types for logical and physical expressions in the optimizer.
use crate::operators::relational::logical::LogicalOperator;
use crate::operators::relational::physical::PhysicalOperator;
use crate::operators::scalar::ScalarOperator;
use crate::{operators::relational::logical::LogicalOperator, values::OptdValue};
use serde::Deserialize;

use super::goal::GoalId;
use super::groups::{RelationalGroupId, ScalarGroupId};
use super::ir::OperatorData;

/// A logical expression in the memo table.
pub type LogicalExpression = LogicalOperator<OptdValue, RelationalGroupId, ScalarGroupId>;
pub type LogicalExpression = LogicalOperator<OperatorData, RelationalGroupId, ScalarGroupId>;

/// A physical expression in the memo table.
pub type PhysicalExpression = PhysicalOperator<OptdValue, GoalId, ScalarGroupId>;
pub type PhysicalExpression = PhysicalOperator<OperatorData, GoalId, ScalarGroupId>;

/// A scalar expression in the memo table.
pub type ScalarExpression = ScalarOperator<OptdValue, ScalarGroupId>;
pub type ScalarExpression = ScalarOperator<OperatorData, ScalarGroupId>;

/// A unique identifier for a logical expression in the memo table.
#[repr(transparent)]
Expand Down
74 changes: 74 additions & 0 deletions optd-core/src/cascades/ir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use super::groups::{RelationalGroupId, ScalarGroupId};
use ordered_float::OrderedFloat;
use serde::{Deserialize, Serialize};

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub enum OperatorData {
Int64(i64),
Float64(OrderedFloat<f64>),
String(String),
Bool(bool),
Struct(String, Vec<OperatorData>),
Array(Vec<OperatorData>),
}

impl OperatorData {
pub fn as_str(&self) -> Option<&str> {
match self {
OperatorData::String(s) => Some(s),
_ => None,
}
}

pub fn as_bool(&self) -> Option<bool> {
match self {
OperatorData::Bool(b) => Some(*b),
_ => None,
}
}

pub fn as_i64(&self) -> Option<i64> {
match self {
OperatorData::Int64(i) => Some(*i),
_ => None,
}
}
}

#[derive(Clone, Debug, PartialEq)]
pub enum Children<T> {
Singleton(T),
VarLength(Vec<T>),
}

#[derive(Clone, Debug, PartialEq)]
pub enum PartialLogicalPlan {
PartialMaterialized {
tag: String,
data: Vec<OperatorData>,
relational_children: Vec<Children<PartialLogicalPlan>>,
scalar_children: Vec<Children<PartialScalarPlan>>,
},
UnMaterialized(RelationalGroupId),
}

#[derive(Clone, Debug, PartialEq)]
pub enum PartialScalarPlan {
PartialMaterialized {
tag: String,
data: Vec<OperatorData>,
scalar_children: Vec<Children<PartialScalarPlan>>,
},
UnMaterialized(ScalarGroupId),
}

#[derive(Clone, Debug, PartialEq)]
pub enum PartialPhysicalPlan {
PartialMaterialized {
tag: String,
data: Vec<OperatorData>,
relational_children: Vec<Children<PartialPhysicalPlan>>,
scalar_children: Vec<Children<PartialScalarPlan>>,
},
UnMaterialized(RelationalGroupId),
}
1 change: 1 addition & 0 deletions optd-core/src/cascades/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod expressions;
pub mod goal;
pub mod groups;
pub mod ir;
pub mod memo;
pub mod properties;

Expand Down
4 changes: 2 additions & 2 deletions optd-core/src/cascades/properties/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use crate::values::OptdValue;
use crate::cascades::ir::OperatorData;

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Default)]
pub struct PhysicalProperties {
Expand All @@ -11,5 +11,5 @@ pub struct PhysicalProperties {
pub struct SortProperty {
/// Each tuple is a column index, direction pair.
/// e.g. vec![(0, Asc), (1, Desc)]
pub sort_orders: Vec<(OptdValue, OptdValue)>,
pub sort_orders: Vec<(OperatorData, OperatorData)>,
}
32 changes: 0 additions & 32 deletions optd-core/src/engine/actions/analyzers/logical.rs

This file was deleted.

10 changes: 0 additions & 10 deletions optd-core/src/engine/actions/analyzers/mod.rs

This file was deleted.

29 changes: 0 additions & 29 deletions optd-core/src/engine/actions/analyzers/scalar.rs

This file was deleted.

51 changes: 0 additions & 51 deletions optd-core/src/engine/actions/mod.rs

This file was deleted.

38 changes: 0 additions & 38 deletions optd-core/src/engine/actions/transformers/logical.rs

This file was deleted.

11 changes: 0 additions & 11 deletions optd-core/src/engine/actions/transformers/mod.rs

This file was deleted.

30 changes: 0 additions & 30 deletions optd-core/src/engine/actions/transformers/scalar.rs

This file was deleted.

Loading

0 comments on commit fc0e77e

Please sign in to comment.