1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use crate::engine::exec::{
DeleteByKey, Eval, ExecStatement, Filter, FindPkByIndex, GetByKey, Guard, NestedMerge, Project,
QueryPk, ReadModifyWrite, SetVar, UpdateByKey,
};
use std::fmt;
pub(crate) enum Action {
/// Delete a record by the primary key
DeleteByKey(DeleteByKey),
/// Evaluate a function in memory
Eval(Eval),
/// Execute a statement
ExecStatement(Box<ExecStatement>),
/// Filter a value stream
Filter(Filter),
FindPkByIndex(FindPkByIndex),
/// Execute `Operation::GetByKey` using key input
GetByKey(GetByKey),
/// Conditionally pass through or suppress a data stream
Guard(Guard),
/// Combines parent and child data into nested structures.
///
/// Loads all batch data upfront, then recursively processes each row by filtering
/// and merging child data at all nesting levels, finally projecting each row with
/// its nested children into the final result.
NestedMerge(NestedMerge),
/// Take the contents of a variable and project it one or more times to a
/// specified variable.
Project(Project),
/// Query records by primary key
QueryPk(QueryPk),
/// Perform an atomic operation in multiple steps
ReadModifyWrite(Box<ReadModifyWrite>),
/// Set a variable to a const
SetVar(SetVar),
/// Update a record by the primary key
UpdateByKey(UpdateByKey),
}
impl Action {
/// Returns the action variant name for logging.
pub(crate) fn name(&self) -> &'static str {
match self {
Action::DeleteByKey(_) => "delete_by_key",
Action::Eval(_) => "eval",
Action::ExecStatement(_) => "exec_statement",
Action::Filter(_) => "filter",
Action::FindPkByIndex(_) => "find_pk_by_index",
Action::GetByKey(_) => "get_by_key",
Action::Guard(_) => "guard",
Action::NestedMerge(_) => "nested_merge",
Action::Project(_) => "project",
Action::QueryPk(_) => "query_pk",
Action::ReadModifyWrite(_) => "read_modify_write",
Action::SetVar(_) => "set_var",
Action::UpdateByKey(_) => "update_by_key",
}
}
/// Returns true if this action issues a database operation.
///
/// Used to determine whether a plan needs to be wrapped in a transaction.
/// In-memory actions (Filter, Project, NestedMerge, SetVar, Eval) return false.
pub(crate) fn is_db_op(&self) -> bool {
match self {
Action::DeleteByKey(_)
| Action::ExecStatement(_)
| Action::FindPkByIndex(_)
| Action::GetByKey(_)
| Action::QueryPk(_)
| Action::ReadModifyWrite(_)
| Action::UpdateByKey(_) => true,
Action::Eval(_)
| Action::Filter(_)
| Action::Guard(_)
| Action::NestedMerge(_)
| Action::Project(_)
| Action::SetVar(_) => false,
}
}
}
impl fmt::Debug for Action {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DeleteByKey(a) => a.fmt(f),
Self::Eval(a) => a.fmt(f),
Self::ExecStatement(a) => a.fmt(f),
Self::Filter(a) => a.fmt(f),
Self::FindPkByIndex(a) => a.fmt(f),
Self::GetByKey(a) => a.fmt(f),
Self::Guard(a) => a.fmt(f),
Self::NestedMerge(a) => a.fmt(f),
Self::QueryPk(a) => a.fmt(f),
Self::ReadModifyWrite(a) => a.fmt(f),
Self::Project(a) => a.fmt(f),
Self::SetVar(a) => a.fmt(f),
Self::UpdateByKey(a) => a.fmt(f),
}
}
}