Skip to content

Commit c4ab846

Browse files
committed
First draft of migration
1 parent db8829d commit c4ab846

File tree

19 files changed

+4307
-0
lines changed

19 files changed

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

0 commit comments

Comments
 (0)