activecube_rs/compiler/
ir.rs1#[derive(Debug, Clone)]
3pub enum SqlValue {
4 String(String),
5 Int(i64),
6 Float(f64),
7 Bool(bool),
8}
9
10#[derive(Debug, Clone)]
12pub struct QueryIR {
13 pub cube: String,
14 pub schema: String,
15 pub table: String,
16 pub selects: Vec<SelectExpr>,
17 pub filters: FilterNode,
18 pub having: FilterNode,
19 pub group_by: Vec<String>,
20 pub order_by: Vec<OrderExpr>,
21 pub limit: u32,
22 pub offset: u32,
23 pub use_final: bool,
25}
26
27#[derive(Debug, Clone)]
28pub enum SelectExpr {
29 Column {
30 column: String,
31 alias: Option<String>,
32 },
33 Aggregate {
34 function: String,
35 column: String,
36 alias: String,
37 condition: Option<String>,
38 },
39}
40
41#[derive(Debug, Clone)]
42pub enum FilterNode {
43 And(Vec<FilterNode>),
44 Or(Vec<FilterNode>),
45 Condition {
46 column: String,
47 op: CompareOp,
48 value: SqlValue,
49 },
50 Empty,
51}
52
53#[derive(Debug, Clone)]
54pub enum CompareOp {
55 Eq,
56 Ne,
57 Gt,
58 Ge,
59 Lt,
60 Le,
61 Like,
62 In,
63 NotIn,
64 Includes,
65 IsNull,
66 IsNotNull,
67}
68
69impl CompareOp {
70 pub fn sql_op(&self) -> &'static str {
71 match self {
72 CompareOp::Eq => "=",
73 CompareOp::Ne => "!=",
74 CompareOp::Gt => ">",
75 CompareOp::Ge => ">=",
76 CompareOp::Lt => "<",
77 CompareOp::Le => "<=",
78 CompareOp::Like => "LIKE",
79 CompareOp::In => "IN",
80 CompareOp::NotIn => "NOT IN",
81 CompareOp::Includes => "LIKE",
82 CompareOp::IsNull => "IS NULL",
83 CompareOp::IsNotNull => "IS NOT NULL",
84 }
85 }
86
87 pub fn is_unary(&self) -> bool {
88 matches!(self, CompareOp::IsNull | CompareOp::IsNotNull)
89 }
90}
91
92#[derive(Debug, Clone)]
93pub struct OrderExpr {
94 pub column: String,
95 pub descending: bool,
96}
97
98impl FilterNode {
99 pub fn is_empty(&self) -> bool {
100 matches!(self, FilterNode::Empty)
101 }
102}