Skip to main content

omnigraph_compiler/ir/
mod.rs

1pub(crate) mod lower;
2
3use std::collections::HashMap;
4
5use crate::query::ast::{AggFunc, CompOp, Literal, Param};
6use crate::types::Direction;
7
8#[derive(Debug, Clone)]
9pub struct QueryIR {
10    pub name: String,
11    pub params: Vec<Param>,
12    pub pipeline: Vec<IROp>,
13    pub return_exprs: Vec<IRProjection>,
14    pub order_by: Vec<IROrdering>,
15    pub limit: Option<u64>,
16}
17
18#[derive(Debug, Clone)]
19pub struct MutationIR {
20    pub name: String,
21    pub params: Vec<Param>,
22    pub ops: Vec<MutationOpIR>,
23}
24
25#[derive(Debug, Clone)]
26pub enum MutationOpIR {
27    Insert {
28        type_name: String,
29        assignments: Vec<IRAssignment>,
30    },
31    Update {
32        type_name: String,
33        assignments: Vec<IRAssignment>,
34        predicate: IRMutationPredicate,
35    },
36    Delete {
37        type_name: String,
38        predicate: IRMutationPredicate,
39    },
40}
41
42#[derive(Debug, Clone)]
43pub struct IRAssignment {
44    pub property: String,
45    pub value: IRExpr,
46}
47
48#[derive(Debug, Clone)]
49pub struct IRMutationPredicate {
50    pub property: String,
51    pub op: CompOp,
52    pub value: IRExpr,
53}
54
55/// Resolved runtime parameters: param name → literal value.
56pub type ParamMap = HashMap<String, Literal>;
57
58#[derive(Debug, Clone)]
59pub enum IROp {
60    NodeScan {
61        variable: String,
62        type_name: String,
63        filters: Vec<IRFilter>,
64    },
65    Expand {
66        src_var: String,
67        dst_var: String,
68        edge_type: String,
69        direction: Direction,
70        dst_type: String,
71        min_hops: u32,
72        max_hops: Option<u32>,
73        /// Filters from a deferred destination binding, pushed into the
74        /// Expand so the executor can apply them during hydration (Lance
75        /// SQL pushdown) rather than as a separate post-expand pass.
76        dst_filters: Vec<IRFilter>,
77    },
78    Filter(IRFilter),
79    AntiJoin {
80        /// The outer variable whose id is used for the join key
81        outer_var: String,
82        /// The inner pipeline that produces rows to anti-join against
83        inner: Vec<IROp>,
84    },
85}
86
87#[derive(Debug, Clone)]
88pub struct IRFilter {
89    pub left: IRExpr,
90    pub op: CompOp,
91    pub right: IRExpr,
92}
93
94#[derive(Debug, Clone)]
95pub enum IRExpr {
96    PropAccess {
97        variable: String,
98        property: String,
99    },
100    Nearest {
101        variable: String,
102        property: String,
103        query: Box<IRExpr>,
104    },
105    Search {
106        field: Box<IRExpr>,
107        query: Box<IRExpr>,
108    },
109    Fuzzy {
110        field: Box<IRExpr>,
111        query: Box<IRExpr>,
112        max_edits: Option<Box<IRExpr>>,
113    },
114    MatchText {
115        field: Box<IRExpr>,
116        query: Box<IRExpr>,
117    },
118    Bm25 {
119        field: Box<IRExpr>,
120        query: Box<IRExpr>,
121    },
122    Rrf {
123        primary: Box<IRExpr>,
124        secondary: Box<IRExpr>,
125        k: Option<Box<IRExpr>>,
126    },
127    Variable(String),
128    Param(String),
129    Literal(Literal),
130    Aggregate {
131        func: AggFunc,
132        arg: Box<IRExpr>,
133    },
134    AliasRef(String),
135}
136
137#[derive(Debug, Clone)]
138pub struct IRProjection {
139    pub expr: IRExpr,
140    pub alias: Option<String>,
141}
142
143#[derive(Debug, Clone)]
144pub struct IROrdering {
145    pub expr: IRExpr,
146    pub descending: bool,
147}