Skip to main content

lora_compiler/
physical.rs

1use lora_analyzer::symbols::VarId;
2use lora_analyzer::{
3    ResolvedExpr, ResolvedMergeAction, ResolvedPattern, ResolvedPatternPart, ResolvedProjection,
4    ResolvedRemoveItem, ResolvedSetItem, ResolvedSortItem,
5};
6use lora_ast::{Direction, RangeLiteral};
7
8pub type PhysicalNodeId = usize;
9
10#[derive(Debug, Clone)]
11pub struct PhysicalPlan {
12    pub root: PhysicalNodeId,
13    pub nodes: Vec<PhysicalOp>,
14}
15
16#[derive(Debug, Clone)]
17pub enum PhysicalOp {
18    Argument(ArgumentExec),
19    NodeScan(NodeScanExec),
20    NodeByLabelScan(NodeByLabelScanExec),
21    Expand(ExpandExec),
22    Filter(FilterExec),
23    Projection(ProjectionExec),
24    Unwind(UnwindExec),
25    HashAggregation(HashAggregationExec),
26    Sort(SortExec),
27    Limit(LimitExec),
28    Create(CreateExec),
29    Merge(MergeExec),
30    Delete(DeleteExec),
31    Set(SetExec),
32    Remove(RemoveExec),
33    OptionalMatch(OptionalMatchExec),
34    PathBuild(PathBuildExec),
35}
36
37#[derive(Debug, Clone)]
38pub struct PathBuildExec {
39    pub input: PhysicalNodeId,
40    pub output: VarId,
41    pub node_vars: Vec<VarId>,
42    pub rel_vars: Vec<VarId>,
43    pub shortest_path_all: Option<bool>,
44}
45
46/// Left-outer-join: for each input row, runs inner sub-plan.
47/// If inner produces nothing, emits one row with nulls for new_vars.
48#[derive(Debug, Clone)]
49pub struct OptionalMatchExec {
50    pub input: PhysicalNodeId,
51    pub inner: PhysicalNodeId,
52    pub new_vars: Vec<VarId>,
53}
54
55#[derive(Debug, Clone)]
56pub struct ArgumentExec;
57
58#[derive(Debug, Clone)]
59pub struct NodeScanExec {
60    pub input: Option<PhysicalNodeId>,
61    pub var: VarId,
62}
63
64#[derive(Debug, Clone)]
65pub struct NodeByLabelScanExec {
66    pub input: Option<PhysicalNodeId>,
67    pub var: VarId,
68    /// Each inner Vec is a disjunctive group (OR). Outer Vec is conjunctive (AND).
69    pub labels: Vec<Vec<String>>,
70}
71
72#[derive(Debug, Clone)]
73pub struct ExpandExec {
74    pub input: PhysicalNodeId,
75    pub src: VarId,
76    pub rel: Option<VarId>,
77    pub dst: VarId,
78    pub types: Vec<String>,
79    pub direction: Direction,
80    pub rel_properties: Option<ResolvedExpr>,
81    pub range: Option<RangeLiteral>,
82}
83
84#[derive(Debug, Clone)]
85pub struct FilterExec {
86    pub input: PhysicalNodeId,
87    pub predicate: ResolvedExpr,
88}
89
90#[derive(Debug, Clone)]
91pub struct ProjectionExec {
92    pub input: PhysicalNodeId,
93    pub distinct: bool,
94    pub items: Vec<ResolvedProjection>,
95    pub include_existing: bool,
96}
97
98#[derive(Debug, Clone)]
99pub struct UnwindExec {
100    pub input: PhysicalNodeId,
101    pub expr: ResolvedExpr,
102    pub alias: VarId,
103}
104
105#[derive(Debug, Clone)]
106pub struct HashAggregationExec {
107    pub input: PhysicalNodeId,
108    pub group_by: Vec<ResolvedProjection>,
109    pub aggregates: Vec<ResolvedProjection>,
110}
111
112#[derive(Debug, Clone)]
113pub struct SortExec {
114    pub input: PhysicalNodeId,
115    pub items: Vec<ResolvedSortItem>,
116}
117
118#[derive(Debug, Clone)]
119pub struct LimitExec {
120    pub input: PhysicalNodeId,
121    pub skip: Option<ResolvedExpr>,
122    pub limit: Option<ResolvedExpr>,
123}
124
125#[derive(Debug, Clone)]
126pub struct CreateExec {
127    pub input: PhysicalNodeId,
128    pub pattern: ResolvedPattern,
129}
130
131#[derive(Debug, Clone)]
132pub struct MergeExec {
133    pub input: PhysicalNodeId,
134    pub pattern_part: ResolvedPatternPart,
135    pub actions: Vec<ResolvedMergeAction>,
136}
137
138#[derive(Debug, Clone)]
139pub struct DeleteExec {
140    pub input: PhysicalNodeId,
141    pub detach: bool,
142    pub expressions: Vec<ResolvedExpr>,
143}
144
145#[derive(Debug, Clone)]
146pub struct SetExec {
147    pub input: PhysicalNodeId,
148    pub items: Vec<ResolvedSetItem>,
149}
150
151#[derive(Debug, Clone)]
152pub struct RemoveExec {
153    pub input: PhysicalNodeId,
154    pub items: Vec<ResolvedRemoveItem>,
155}