kotoba_execution/execution/
physical_plan.rs1use kotoba_core::types::*;
4use kotoba_core::ir::*;
5
6type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
8
9#[derive(Debug, Clone, PartialEq)]
11pub struct Column {
12 pub name: String,
13 pub data_type: String,
14}
15
16impl Column {
17 pub fn new(name: String, data_type: String) -> Self {
18 Self { name, data_type }
19 }
20}
21
22#[derive(Debug, Clone)]
24pub struct PhysicalPlan {
25 pub root: PhysicalOp,
26 pub schema: Vec<Column>,
27}
28
29impl PhysicalPlan {
30 pub fn new(root: PhysicalOp, schema: Vec<Column>) -> Self {
31 Self { root, schema }
32 }
33}
34
35#[derive(Debug, Clone)]
37pub enum PhysicalOp {
38 Scan {
40 table: String,
41 filter: Option<Expr>,
42 projection: Vec<String>,
43 },
44 Filter {
46 input: Box<PhysicalOp>,
47 condition: Expr,
48 },
49 Projection {
51 input: Box<PhysicalOp>,
52 expressions: Vec<(Expr, String)>,
53 },
54 Sort {
56 input: Box<PhysicalOp>,
57 order_by: Vec<(String, SortDirection)>,
58 },
59 GroupBy {
61 input: Box<PhysicalOp>,
62 group_by: Vec<String>,
63 aggregates: Vec<AggregateExpr>,
64 },
65 Join {
67 left: Box<PhysicalOp>,
68 right: Box<PhysicalOp>,
69 join_type: JoinType,
70 condition: Expr,
71 },
72 Union {
74 left: Box<PhysicalOp>,
75 right: Box<PhysicalOp>,
76 },
77 Limit {
79 input: Box<PhysicalOp>,
80 limit: usize,
81 offset: usize,
82 },
83}
84
85#[derive(Debug, Clone)]
87pub enum SortDirection {
88 Asc,
89 Desc,
90}
91
92#[derive(Debug, Clone)]
94pub enum JoinType {
95 Inner,
96 Left,
97 Right,
98 Full,
99}
100
101#[derive(Debug, Clone)]
103pub struct AggregateExpr {
104 pub function: AggregateFunction,
105 pub argument: Expr,
106 pub alias: String,
107}
108
109#[derive(Debug, Clone)]
111pub enum AggregateFunction {
112 Count,
113 Sum,
114 Avg,
115 Min,
116 Max,
117 CountDistinct,
118}