kotoba_execution/execution/
physical_plan.rs

1//! 物理プラン定義
2
3use kotoba_core::types::*;
4use kotoba_core::ir::*;
5
6// Use std::result::Result instead of kotoba_core::types::Result to avoid conflicts
7type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
8
9/// カラム情報
10#[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/// 物理プラン
23#[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/// 物理演算子
36#[derive(Debug, Clone)]
37pub enum PhysicalOp {
38    /// スキャン操作
39    Scan {
40        table: String,
41        filter: Option<Expr>,
42        projection: Vec<String>,
43    },
44    /// フィルター操作
45    Filter {
46        input: Box<PhysicalOp>,
47        condition: Expr,
48    },
49    /// 射影操作
50    Projection {
51        input: Box<PhysicalOp>,
52        expressions: Vec<(Expr, String)>,
53    },
54    /// ソート操作
55    Sort {
56        input: Box<PhysicalOp>,
57        order_by: Vec<(String, SortDirection)>,
58    },
59    /// グループ化操作
60    GroupBy {
61        input: Box<PhysicalOp>,
62        group_by: Vec<String>,
63        aggregates: Vec<AggregateExpr>,
64    },
65    /// ジョイン操作
66    Join {
67        left: Box<PhysicalOp>,
68        right: Box<PhysicalOp>,
69        join_type: JoinType,
70        condition: Expr,
71    },
72    /// ユニオン操作
73    Union {
74        left: Box<PhysicalOp>,
75        right: Box<PhysicalOp>,
76    },
77    /// リミット操作
78    Limit {
79        input: Box<PhysicalOp>,
80        limit: usize,
81        offset: usize,
82    },
83}
84
85/// ソート方向
86#[derive(Debug, Clone)]
87pub enum SortDirection {
88    Asc,
89    Desc,
90}
91
92/// ジョインタイプ
93#[derive(Debug, Clone)]
94pub enum JoinType {
95    Inner,
96    Left,
97    Right,
98    Full,
99}
100
101/// 集約式
102#[derive(Debug, Clone)]
103pub struct AggregateExpr {
104    pub function: AggregateFunction,
105    pub argument: Expr,
106    pub alias: String,
107}
108
109/// 集約関数
110#[derive(Debug, Clone)]
111pub enum AggregateFunction {
112    Count,
113    Sum,
114    Avg,
115    Min,
116    Max,
117    CountDistinct,
118}