Skip to content

Commit 21d01ae

Browse files
authored
feat(cost-model): Initial framework of compute cost migration (#31)
* First draft of migration * add storage part * 1. add compute_cost 2. add todo documentation 3. improve type like tableid 4. CMSL->S
1 parent db8829d commit 21d01ae

File tree

20 files changed

+4389
-0
lines changed

20 files changed

+4389
-0
lines changed

optd-cost-model/Cargo.lock

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

optd-cost-model/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "optd-cost-model"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
optd-persistent = { path = "../optd-persistent", version = "0.1" }
8+
serde = { version = "1.0", features = ["derive"] }
9+
arrow-schema = "53.2.0"
10+
datafusion-expr = "32.0.0"
11+
ordered-float = "4.0"
12+
chrono = "0.4"
13+

optd-cost-model/src/common/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod nodes;
2+
pub mod predicates;
3+
pub mod types;
4+
pub mod values;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
use std::sync::Arc;
2+
3+
use arrow_schema::DataType;
4+
5+
use super::{
6+
predicates::{
7+
bin_op_pred::BinOpType, constant_pred::ConstantType, func_pred::FuncType,
8+
log_op_pred::LogOpType, sort_order_pred::SortOrderType, un_op_pred::UnOpType,
9+
},
10+
values::Value,
11+
};
12+
13+
/// TODO: documentation
14+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
15+
pub enum JoinType {
16+
Inner = 1,
17+
FullOuter,
18+
LeftOuter,
19+
RightOuter,
20+
Cross,
21+
LeftSemi,
22+
RightSemi,
23+
LeftAnti,
24+
RightAnti,
25+
}
26+
27+
/// TODO: documentation
28+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
29+
pub enum PhysicalNodeType {
30+
PhysicalProjection,
31+
PhysicalFilter,
32+
PhysicalScan,
33+
PhysicalSort,
34+
PhysicalAgg,
35+
PhysicalHashJoin(JoinType),
36+
PhysicalNestedLoopJoin(JoinType),
37+
PhysicalEmptyRelation,
38+
PhysicalLimit,
39+
}
40+
41+
impl std::fmt::Display for PhysicalNodeType {
42+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
write!(f, "{:?}", self)
44+
}
45+
}
46+
47+
/// TODO: documentation
48+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
49+
pub enum PredicateType {
50+
List,
51+
Constant(ConstantType),
52+
AttributeRef,
53+
ExternAttributeRef,
54+
UnOp(UnOpType),
55+
BinOp(BinOpType),
56+
LogOp(LogOpType),
57+
Func(FuncType),
58+
SortOrder(SortOrderType),
59+
Between,
60+
Cast,
61+
Like,
62+
DataType(DataType),
63+
InList,
64+
}
65+
66+
impl std::fmt::Display for PredicateType {
67+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68+
write!(f, "{:?}", self)
69+
}
70+
}
71+
72+
pub type ArcPredicateNode = Arc<PredicateNode>;
73+
74+
/// TODO: documentation
75+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
76+
pub struct PredicateNode {
77+
/// A generic predicate node type
78+
pub typ: PredicateType,
79+
/// Child predicate nodes, always materialized
80+
pub children: Vec<PredicateNode>,
81+
/// Data associated with the predicate, if any
82+
pub data: Option<Value>,
83+
}
84+
85+
impl std::fmt::Display for PredicateNode {
86+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87+
write!(f, "({}", self.typ)?;
88+
for child in &self.children {
89+
write!(f, " {}", child)?;
90+
}
91+
if let Some(data) = &self.data {
92+
write!(f, " {}", data)?;
93+
}
94+
write!(f, ")")
95+
}
96+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/// TODO: documentation
2+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
3+
pub enum BinOpType {
4+
// numerical
5+
Add,
6+
Sub,
7+
Mul,
8+
Div,
9+
Mod,
10+
11+
// comparison
12+
Eq,
13+
Neq,
14+
Gt,
15+
Lt,
16+
Geq,
17+
Leq,
18+
}
19+
20+
impl std::fmt::Display for BinOpType {
21+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22+
write!(f, "{:?}", self)
23+
}
24+
}
25+
26+
impl BinOpType {
27+
pub fn is_numerical(&self) -> bool {
28+
matches!(
29+
self,
30+
Self::Add | Self::Sub | Self::Mul | Self::Div | Self::Mod
31+
)
32+
}
33+
34+
pub fn is_comparison(&self) -> bool {
35+
matches!(
36+
self,
37+
Self::Eq | Self::Neq | Self::Gt | Self::Lt | Self::Geq | Self::Leq
38+
)
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// TODO: documentation
4+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
5+
pub enum ConstantType {
6+
Bool,
7+
Utf8String,
8+
UInt8,
9+
UInt16,
10+
UInt32,
11+
UInt64,
12+
Int8,
13+
Int16,
14+
Int32,
15+
Int64,
16+
Float64,
17+
Date,
18+
IntervalMonthDateNano,
19+
Decimal,
20+
Binary,
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// TODO: documentation
2+
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
3+
pub enum FuncType {
4+
Scalar(datafusion_expr::BuiltinScalarFunction),
5+
Agg(datafusion_expr::AggregateFunction),
6+
Case,
7+
}
8+
9+
impl std::fmt::Display for FuncType {
10+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11+
write!(f, "{:?}", self)
12+
}
13+
}
14+
15+
impl FuncType {
16+
pub fn new_scalar(func_id: datafusion_expr::BuiltinScalarFunction) -> Self {
17+
FuncType::Scalar(func_id)
18+
}
19+
20+
pub fn new_agg(func_id: datafusion_expr::AggregateFunction) -> Self {
21+
FuncType::Agg(func_id)
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::fmt::Display;
2+
3+
/// TODO: documentation
4+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
5+
pub enum LogOpType {
6+
And,
7+
Or,
8+
}
9+
10+
impl Display for LogOpType {
11+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12+
write!(f, "{:?}", self)
13+
}
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod bin_op_pred;
2+
pub mod constant_pred;
3+
pub mod func_pred;
4+
pub mod log_op_pred;
5+
pub mod sort_order_pred;
6+
pub mod un_op_pred;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::fmt::Display;
2+
3+
/// TODO: documentation
4+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
5+
pub enum SortOrderType {
6+
Asc,
7+
Desc,
8+
}
9+
10+
impl Display for SortOrderType {
11+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12+
write!(f, "{:?}", self)
13+
}
14+
}

0 commit comments

Comments
 (0)