gqlite 1.5.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/Cargo.toml +10 -4
- data/ext/db-index/Cargo.toml +29 -0
- data/ext/db-index/src/hnsw/error.rs +66 -0
- data/ext/db-index/src/hnsw/graph_store.rs +272 -0
- data/ext/db-index/src/hnsw/id.rs +36 -0
- data/ext/db-index/src/hnsw/implementation.rs +1517 -0
- data/ext/db-index/src/hnsw/kernels.rs +1228 -0
- data/ext/db-index/src/hnsw/metric.rs +244 -0
- data/ext/db-index/src/hnsw/scalar.rs +72 -0
- data/ext/db-index/src/hnsw/simple_store.rs +140 -0
- data/ext/db-index/src/hnsw/store.rs +472 -0
- data/ext/db-index/src/hnsw/vector.rs +105 -0
- data/ext/db-index/src/hnsw/vectors.rs +568 -0
- data/ext/db-index/src/hnsw.rs +42 -0
- data/ext/db-index/src/lib.rs +3 -0
- data/ext/gqlitedb/Cargo.toml +19 -9
- data/ext/gqlitedb/benches/common/pokec.rs +62 -2
- data/ext/gqlitedb/benches/pokec_divan.rs +66 -2
- data/ext/gqlitedb/benches/pokec_iai.rs +60 -3
- data/ext/gqlitedb/release.toml +2 -2
- data/ext/gqlitedb/src/aggregators/arithmetic.rs +3 -1
- data/ext/gqlitedb/src/aggregators/containers.rs +1 -1
- data/ext/gqlitedb/src/aggregators/stats.rs +21 -12
- data/ext/gqlitedb/src/capi.rs +1 -1
- data/ext/gqlitedb/src/compiler/expression_analyser.rs +28 -20
- data/ext/gqlitedb/src/compiler/variables_manager.rs +97 -29
- data/ext/gqlitedb/src/compiler.rs +505 -225
- data/ext/gqlitedb/src/connection.rs +149 -11
- data/ext/gqlitedb/src/consts.rs +1 -2
- data/ext/gqlitedb/src/error.rs +123 -61
- data/ext/gqlitedb/src/functions/common.rs +39 -2
- data/ext/gqlitedb/src/functions/math.rs +8 -3
- data/ext/gqlitedb/src/functions/path.rs +48 -11
- data/ext/gqlitedb/src/functions/value.rs +1 -1
- data/ext/gqlitedb/src/functions.rs +23 -7
- data/ext/gqlitedb/src/graph.rs +1 -9
- data/ext/gqlitedb/src/interpreter/evaluators.rs +968 -130
- data/ext/gqlitedb/src/interpreter/instructions.rs +39 -2
- data/ext/gqlitedb/src/lib.rs +5 -4
- data/ext/gqlitedb/src/planner.rs +329 -0
- data/ext/gqlitedb/src/prelude.rs +3 -3
- data/ext/gqlitedb/src/store/pgrx.rs +1 -1
- data/ext/gqlitedb/src/store/postgres.rs +735 -7
- data/ext/gqlitedb/src/store/redb/hnsw_store.rs +702 -0
- data/ext/gqlitedb/src/store/redb/index.rs +274 -0
- data/ext/gqlitedb/src/store/redb.rs +1268 -113
- data/ext/gqlitedb/src/store/sqlbase/sqlmetadata.rs +28 -0
- data/ext/gqlitedb/src/store/sqlbase/sqlstore.rs +103 -0
- data/ext/gqlitedb/src/store/sqlbase.rs +146 -16
- data/ext/gqlitedb/src/store/sqlite.rs +569 -5
- data/ext/gqlitedb/src/store/vector_extract.rs +56 -0
- data/ext/gqlitedb/src/store.rs +123 -3
- data/ext/gqlitedb/src/tests/compiler.rs +207 -10
- data/ext/gqlitedb/src/tests/connection/postgres.rs +38 -3
- data/ext/gqlitedb/src/tests/connection/redb.rs +23 -0
- data/ext/gqlitedb/src/tests/connection/sqlite.rs +31 -0
- data/ext/gqlitedb/src/tests/connection.rs +61 -1
- data/ext/gqlitedb/src/tests/evaluators.rs +162 -7
- data/ext/gqlitedb/src/tests/parser.rs +54 -23
- data/ext/gqlitedb/src/tests/planner.rs +511 -0
- data/ext/gqlitedb/src/tests/store/postgres.rs +7 -0
- data/ext/gqlitedb/src/tests/store/redb.rs +8 -0
- data/ext/gqlitedb/src/tests/store/sqlite.rs +8 -0
- data/ext/gqlitedb/src/tests/store/vector_index/postgres.rs +182 -0
- data/ext/gqlitedb/src/tests/store/vector_index/redb.rs +386 -0
- data/ext/gqlitedb/src/tests/store/vector_index/sqlite.rs +166 -0
- data/ext/gqlitedb/src/tests/store/vector_index.rs +2313 -0
- data/ext/gqlitedb/src/tests/store.rs +78 -14
- data/ext/gqlitedb/src/tests/templates/ast.rs +92 -16
- data/ext/gqlitedb/src/tests/templates/programs.rs +14 -7
- data/ext/gqlitedb/src/tests.rs +15 -9
- data/ext/gqlitedb/src/utils.rs +6 -1
- data/ext/gqlitedb/src/value/compare.rs +61 -3
- data/ext/gqlitedb/src/value.rs +136 -7
- data/ext/gqlitedb/templates/sql/postgres/metadata_delete.sql +1 -0
- data/ext/gqlitedb/templates/sql/postgres/node_select.sql +1 -1
- data/ext/gqlitedb/templates/sql/sqlite/metadata_delete.sql +1 -0
- data/ext/gqliterb/src/lib.rs +53 -8
- data/ext/gqlparser/Cargo.toml +25 -0
- data/ext/gqlparser/README.MD +9 -0
- data/ext/gqlparser/benches/pokec_divan.rs +34 -0
- data/ext/gqlparser/src/common.rs +69 -0
- data/ext/gqlparser/src/gqls/ast.rs +69 -0
- data/ext/gqlparser/src/gqls/constraint.rs +79 -0
- data/ext/gqlparser/src/gqls/error.rs +22 -0
- data/ext/gqlparser/src/gqls/parser.rs +813 -0
- data/ext/gqlparser/src/gqls/prelude.rs +8 -0
- data/ext/gqlparser/src/gqls/properties.rs +115 -0
- data/ext/gqlparser/src/gqls/resolve.rs +207 -0
- data/ext/gqlparser/src/gqls.rs +265 -0
- data/ext/gqlparser/src/lib.rs +7 -0
- data/ext/gqlparser/src/oc/ast.rs +680 -0
- data/ext/gqlparser/src/oc/error.rs +172 -0
- data/ext/gqlparser/src/oc/lexer.rs +429 -0
- data/ext/gqlparser/src/oc/parser/tests.rs +2284 -0
- data/ext/gqlparser/src/oc/parser.rs +2005 -0
- data/ext/gqlparser/src/oc.rs +33 -0
- data/ext/gqlparser/src/prelude.rs +3 -0
- data/ext/graphcore/Cargo.toml +1 -0
- data/ext/graphcore/src/error.rs +26 -0
- data/ext/graphcore/src/graph.rs +177 -51
- data/ext/graphcore/src/lib.rs +4 -2
- data/ext/graphcore/src/open_cypher.rs +12 -0
- data/ext/graphcore/src/table.rs +50 -2
- data/ext/graphcore/src/timestamp.rs +127 -104
- data/ext/graphcore/src/value/tensor.rs +739 -0
- data/ext/graphcore/src/value/value_map.rs +1 -1
- data/ext/graphcore/src/value.rs +343 -19
- metadata +90 -22
- data/ext/gqlitedb/src/parser/ast.rs +0 -604
- data/ext/gqlitedb/src/parser/parser_impl.rs +0 -1213
- data/ext/gqlitedb/src/parser.rs +0 -4
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
//! AST for OpenCypher queries
|
|
2
|
+
|
|
3
|
+
use std::{
|
|
4
|
+
cell::RefCell,
|
|
5
|
+
collections::{HashMap, hash_map::Entry},
|
|
6
|
+
sync::atomic::AtomicU64,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
macro_rules! create_from {
|
|
10
|
+
( $x:tt, $y:tt, $z:tt ) => {
|
|
11
|
+
impl From<$x> for $z
|
|
12
|
+
{
|
|
13
|
+
fn from(v: $x) -> $z
|
|
14
|
+
{
|
|
15
|
+
$z::$y(v)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Represent a variable name. Some variable are explicitly created by the parser, if a node/edge should be considered equal and appear in different expression.
|
|
22
|
+
/// For instance `()-[]->()-[]->()` needs the creation of a variable.
|
|
23
|
+
#[derive(Debug, Clone, Eq)]
|
|
24
|
+
pub struct VariableIdentifier
|
|
25
|
+
{
|
|
26
|
+
/// Name of the variable, only useful for debug purposes
|
|
27
|
+
pub(crate) name: String,
|
|
28
|
+
/// Unique identifier of the variable, the uniqueness is only guaranteed within a compilation unit.
|
|
29
|
+
pub(crate) id: u64,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl VariableIdentifier
|
|
33
|
+
{
|
|
34
|
+
/// Return a reference to the name
|
|
35
|
+
pub fn name(&self) -> &String
|
|
36
|
+
{
|
|
37
|
+
&self.name
|
|
38
|
+
}
|
|
39
|
+
/// Consume the variable identifier and return its name
|
|
40
|
+
pub fn take_name(self) -> String
|
|
41
|
+
{
|
|
42
|
+
self.name
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
impl PartialEq for VariableIdentifier
|
|
47
|
+
{
|
|
48
|
+
fn eq(&self, other: &Self) -> bool
|
|
49
|
+
{
|
|
50
|
+
self.id == other.id
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
impl std::hash::Hash for VariableIdentifier
|
|
55
|
+
{
|
|
56
|
+
fn hash<H: std::hash::Hasher>(&self, state: &mut H)
|
|
57
|
+
{
|
|
58
|
+
self.id.hash(state);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[derive(Default, Debug)]
|
|
63
|
+
pub struct VariableIdentifiers
|
|
64
|
+
{
|
|
65
|
+
next_id: AtomicU64,
|
|
66
|
+
identifiers: RefCell<HashMap<String, VariableIdentifier>>,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
impl VariableIdentifiers
|
|
70
|
+
{
|
|
71
|
+
fn next_id(&self) -> u64
|
|
72
|
+
{
|
|
73
|
+
self
|
|
74
|
+
.next_id
|
|
75
|
+
.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
|
|
76
|
+
}
|
|
77
|
+
pub fn create_variable_from_name(&self, name: &str) -> VariableIdentifier
|
|
78
|
+
{
|
|
79
|
+
match self.identifiers.borrow_mut().entry(name.to_string())
|
|
80
|
+
{
|
|
81
|
+
Entry::Occupied(entry) => entry.get().clone(),
|
|
82
|
+
Entry::Vacant(entry) =>
|
|
83
|
+
{
|
|
84
|
+
let vn = VariableIdentifier {
|
|
85
|
+
name: entry.key().clone(),
|
|
86
|
+
id: self.next_id(),
|
|
87
|
+
};
|
|
88
|
+
entry.insert(vn.clone());
|
|
89
|
+
vn
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
pub(super) fn create_variable_from_name_optional(
|
|
94
|
+
&self,
|
|
95
|
+
name: Option<&str>,
|
|
96
|
+
) -> Option<VariableIdentifier>
|
|
97
|
+
{
|
|
98
|
+
name.map(|name| self.create_variable_from_name(name))
|
|
99
|
+
}
|
|
100
|
+
pub(super) fn create_anonymous_variable(&self) -> VariableIdentifier
|
|
101
|
+
{
|
|
102
|
+
let id = self.next_id();
|
|
103
|
+
VariableIdentifier {
|
|
104
|
+
name: format!("anonymous_{}", id),
|
|
105
|
+
id,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// OpenCypher statement
|
|
111
|
+
#[allow(missing_docs)]
|
|
112
|
+
#[derive(Debug)]
|
|
113
|
+
pub enum Statement
|
|
114
|
+
{
|
|
115
|
+
CreateGraph(CreateGraph),
|
|
116
|
+
DropGraph(DropGraph),
|
|
117
|
+
UseGraph(UseGraph),
|
|
118
|
+
Create(Create),
|
|
119
|
+
CreateVectorIndex(CreateVectorIndex),
|
|
120
|
+
Match(Match),
|
|
121
|
+
Merge(Merge),
|
|
122
|
+
Return(Return),
|
|
123
|
+
Call(Call),
|
|
124
|
+
With(With),
|
|
125
|
+
Unwind(Unwind),
|
|
126
|
+
Delete(Delete),
|
|
127
|
+
Update(Update),
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
macro_rules! create_from_statement {
|
|
131
|
+
( $x:tt ) => {
|
|
132
|
+
create_from! { $x, $x, Statement }
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// Ordered list of statements.
|
|
137
|
+
pub type Statements = Vec<Statement>;
|
|
138
|
+
|
|
139
|
+
/// A single query, which is either a plain statement sequence or a UNION.
|
|
140
|
+
#[derive(Debug)]
|
|
141
|
+
pub enum Query
|
|
142
|
+
{
|
|
143
|
+
/// A plain sequence of statements (the existing behaviour).
|
|
144
|
+
Statements(Statements),
|
|
145
|
+
/// Two or more sub-queries combined with UNION or UNION ALL.
|
|
146
|
+
Union
|
|
147
|
+
{
|
|
148
|
+
/// Each element is one branch's statement list (the part between UNION keywords).
|
|
149
|
+
branches: Vec<Statements>,
|
|
150
|
+
/// `true` → UNION ALL (bag semantics, duplicates kept)
|
|
151
|
+
/// `false` → UNION (set semantics, duplicates removed)
|
|
152
|
+
all: bool,
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/// Ordered list of queries. A query is either a plain statement sequence or a UNION.
|
|
157
|
+
pub type Queries = Vec<Query>;
|
|
158
|
+
|
|
159
|
+
/// Statement for creating a graph.
|
|
160
|
+
#[derive(Debug)]
|
|
161
|
+
pub struct CreateGraph
|
|
162
|
+
{
|
|
163
|
+
/// Name of the graph to create.
|
|
164
|
+
pub name: String,
|
|
165
|
+
/// Indicate if it should ignore in case the graph already exists.
|
|
166
|
+
pub if_not_exists: bool,
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
create_from_statement!(CreateGraph);
|
|
170
|
+
|
|
171
|
+
/// Drop the graph.
|
|
172
|
+
#[derive(Debug)]
|
|
173
|
+
pub struct DropGraph
|
|
174
|
+
{
|
|
175
|
+
/// Name of the graph to drop.
|
|
176
|
+
pub name: String,
|
|
177
|
+
/// Indicate if it should ignore in case the graph does not exists.
|
|
178
|
+
pub if_exists: bool,
|
|
179
|
+
}
|
|
180
|
+
create_from_statement!(DropGraph);
|
|
181
|
+
|
|
182
|
+
/// Select the graph
|
|
183
|
+
#[derive(Debug)]
|
|
184
|
+
pub struct UseGraph
|
|
185
|
+
{
|
|
186
|
+
/// Name of the graph to use.
|
|
187
|
+
pub name: String,
|
|
188
|
+
}
|
|
189
|
+
create_from_statement!(UseGraph);
|
|
190
|
+
|
|
191
|
+
/// Create nodes and/or edges.
|
|
192
|
+
#[derive(Debug)]
|
|
193
|
+
pub struct Create
|
|
194
|
+
{
|
|
195
|
+
/// Pattern for creation.
|
|
196
|
+
pub patterns: Vec<Pattern>,
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
create_from_statement! {Create}
|
|
200
|
+
|
|
201
|
+
/// Search clause for vector search
|
|
202
|
+
#[derive(Debug)]
|
|
203
|
+
pub struct Search
|
|
204
|
+
{
|
|
205
|
+
/// Variable to search in the patterns
|
|
206
|
+
pub variable: VariableIdentifier,
|
|
207
|
+
/// Vector index name
|
|
208
|
+
pub index: String,
|
|
209
|
+
/// Query expression (vector or parameter)
|
|
210
|
+
pub query: Expression,
|
|
211
|
+
/// Result limit
|
|
212
|
+
pub limit: usize,
|
|
213
|
+
/// Optional score alias
|
|
214
|
+
pub score_alias: Option<VariableIdentifier>,
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/// Match query
|
|
218
|
+
#[derive(Debug)]
|
|
219
|
+
pub struct Match
|
|
220
|
+
{
|
|
221
|
+
/// Node and edge patterns
|
|
222
|
+
pub patterns: Vec<Pattern>,
|
|
223
|
+
/// Filtering where expression
|
|
224
|
+
pub where_expression: Option<Expression>,
|
|
225
|
+
/// Indicate if the results from the query are optional
|
|
226
|
+
pub optional: bool,
|
|
227
|
+
/// Optional vector search clause
|
|
228
|
+
pub search: Option<Search>,
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
create_from_statement! {Match}
|
|
232
|
+
|
|
233
|
+
/// MERGE statement.
|
|
234
|
+
#[derive(Debug)]
|
|
235
|
+
pub struct Merge
|
|
236
|
+
{
|
|
237
|
+
/// The pattern to match or create. Same shape as Create/Match patterns.
|
|
238
|
+
pub patterns: Vec<Pattern>,
|
|
239
|
+
/// SET actions applied only when the pattern was not found and was just created.
|
|
240
|
+
pub on_create: Vec<OneUpdate>,
|
|
241
|
+
/// SET actions applied only when the pattern already existed and was matched.
|
|
242
|
+
pub on_match: Vec<OneUpdate>,
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
create_from_statement! {Merge}
|
|
246
|
+
|
|
247
|
+
#[derive(Debug)]
|
|
248
|
+
pub struct Return
|
|
249
|
+
{
|
|
250
|
+
pub all: bool,
|
|
251
|
+
pub expressions: Vec<NamedExpression>,
|
|
252
|
+
pub modifiers: Modifiers,
|
|
253
|
+
pub where_expression: Option<Expression>,
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
create_from_statement! {Return}
|
|
257
|
+
|
|
258
|
+
#[derive(Debug)]
|
|
259
|
+
pub struct With
|
|
260
|
+
{
|
|
261
|
+
pub all: bool,
|
|
262
|
+
pub expressions: Vec<NamedExpression>,
|
|
263
|
+
pub modifiers: Modifiers,
|
|
264
|
+
pub where_expression: Option<Expression>,
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
create_from_statement! {With}
|
|
268
|
+
|
|
269
|
+
#[derive(Debug)]
|
|
270
|
+
pub struct Unwind
|
|
271
|
+
{
|
|
272
|
+
pub identifier: VariableIdentifier,
|
|
273
|
+
pub expression: Expression,
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
create_from_statement! {Unwind}
|
|
277
|
+
|
|
278
|
+
#[derive(Debug)]
|
|
279
|
+
pub struct Delete
|
|
280
|
+
{
|
|
281
|
+
pub detach: bool,
|
|
282
|
+
pub expressions: Vec<Expression>,
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
create_from_statement! {Delete}
|
|
286
|
+
|
|
287
|
+
#[derive(Debug)]
|
|
288
|
+
pub struct Update
|
|
289
|
+
{
|
|
290
|
+
pub updates: Vec<OneUpdate>,
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
create_from_statement! {Update}
|
|
294
|
+
|
|
295
|
+
#[derive(Debug)]
|
|
296
|
+
pub struct Call
|
|
297
|
+
{
|
|
298
|
+
pub name: String,
|
|
299
|
+
pub arguments: Vec<Expression>,
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
create_from_statement! {Call}
|
|
303
|
+
|
|
304
|
+
/// Metric for vector distance calculation
|
|
305
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
306
|
+
pub enum Metric
|
|
307
|
+
{
|
|
308
|
+
/// Cosine similarity
|
|
309
|
+
Cosine,
|
|
310
|
+
/// L2 (Euclidean) distance
|
|
311
|
+
L2,
|
|
312
|
+
/// Dot product
|
|
313
|
+
DotProduct,
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/// Create vector index statement
|
|
317
|
+
#[derive(Debug)]
|
|
318
|
+
pub struct CreateVectorIndex
|
|
319
|
+
{
|
|
320
|
+
/// Index name
|
|
321
|
+
pub name: String,
|
|
322
|
+
/// Label (without colon)
|
|
323
|
+
pub label: String,
|
|
324
|
+
/// Property name
|
|
325
|
+
pub property: String,
|
|
326
|
+
/// Vector dimension
|
|
327
|
+
pub dimension: Option<usize>,
|
|
328
|
+
/// Distance metric
|
|
329
|
+
pub metric: Option<Metric>,
|
|
330
|
+
/// If not exists
|
|
331
|
+
pub if_not_exists: bool,
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
create_from_statement! {CreateVectorIndex}
|
|
335
|
+
|
|
336
|
+
// Set/remove Statements
|
|
337
|
+
|
|
338
|
+
#[derive(Debug)]
|
|
339
|
+
pub enum OneUpdate
|
|
340
|
+
{
|
|
341
|
+
SetProperty(UpdateProperty),
|
|
342
|
+
AddProperty(UpdateProperty),
|
|
343
|
+
RemoveProperty(RemoveProperty),
|
|
344
|
+
AddLabels(AddRemoveLabels),
|
|
345
|
+
RemoveLabels(AddRemoveLabels),
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
#[derive(Debug)]
|
|
349
|
+
pub struct UpdateProperty
|
|
350
|
+
{
|
|
351
|
+
pub target: VariableIdentifier,
|
|
352
|
+
pub path: Vec<String>,
|
|
353
|
+
pub expression: Expression,
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
#[derive(Debug)]
|
|
357
|
+
pub struct RemoveProperty
|
|
358
|
+
{
|
|
359
|
+
pub target: VariableIdentifier,
|
|
360
|
+
pub path: Vec<String>,
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
#[derive(Debug)]
|
|
364
|
+
pub struct AddRemoveLabels
|
|
365
|
+
{
|
|
366
|
+
pub target: VariableIdentifier,
|
|
367
|
+
pub labels: Vec<String>,
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Modifiers
|
|
371
|
+
|
|
372
|
+
#[derive(Debug)]
|
|
373
|
+
pub struct OrderBy
|
|
374
|
+
{
|
|
375
|
+
pub expressions: Vec<OrderByExpression>,
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
#[derive(Default, Debug)]
|
|
379
|
+
pub struct Modifiers
|
|
380
|
+
{
|
|
381
|
+
pub skip: Option<Expression>,
|
|
382
|
+
pub limit: Option<Expression>,
|
|
383
|
+
pub order_by: Option<OrderBy>,
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Expressions
|
|
387
|
+
|
|
388
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
389
|
+
#[allow(clippy::large_enum_variant)]
|
|
390
|
+
pub enum Expression
|
|
391
|
+
{
|
|
392
|
+
Array(Array),
|
|
393
|
+
FunctionCall(FunctionCall),
|
|
394
|
+
Map(Map),
|
|
395
|
+
IndexAccess(Box<IndexAccess>),
|
|
396
|
+
RangeAccess(Box<RangeAccess>),
|
|
397
|
+
MemberAccess(Box<MemberAccess>),
|
|
398
|
+
Parameter(Parameter),
|
|
399
|
+
Value(Value),
|
|
400
|
+
Variable(Variable),
|
|
401
|
+
|
|
402
|
+
LogicalAnd(Box<LogicalAnd>),
|
|
403
|
+
LogicalOr(Box<LogicalOr>),
|
|
404
|
+
LogicalXor(Box<LogicalXor>),
|
|
405
|
+
RelationalEqual(Box<RelationalEqual>),
|
|
406
|
+
RelationalDifferent(Box<RelationalDifferent>),
|
|
407
|
+
RelationalInferior(Box<RelationalInferior>),
|
|
408
|
+
RelationalSuperior(Box<RelationalSuperior>),
|
|
409
|
+
RelationalInferiorEqual(Box<RelationalInferiorEqual>),
|
|
410
|
+
RelationalSuperiorEqual(Box<RelationalSuperiorEqual>),
|
|
411
|
+
RelationalIn(Box<RelationalIn>),
|
|
412
|
+
RelationalNotIn(Box<RelationalNotIn>),
|
|
413
|
+
|
|
414
|
+
Addition(Box<Addition>),
|
|
415
|
+
Subtraction(Box<Subtraction>),
|
|
416
|
+
Multiplication(Box<Multiplication>),
|
|
417
|
+
Division(Box<Division>),
|
|
418
|
+
Modulo(Box<Modulo>),
|
|
419
|
+
Exponent(Box<Exponent>),
|
|
420
|
+
|
|
421
|
+
Negation(Box<Negation>),
|
|
422
|
+
LogicalNegation(Box<LogicalNegation>),
|
|
423
|
+
IsNull(Box<IsNull>),
|
|
424
|
+
IsNotNull(Box<IsNotNull>),
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// Order By Expression
|
|
428
|
+
|
|
429
|
+
#[derive(Debug)]
|
|
430
|
+
pub struct OrderByExpression
|
|
431
|
+
{
|
|
432
|
+
pub asc: bool,
|
|
433
|
+
pub expression: Expression,
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Values: CreatePatterns
|
|
437
|
+
|
|
438
|
+
#[derive(Debug)]
|
|
439
|
+
pub enum Pattern
|
|
440
|
+
{
|
|
441
|
+
Node(NodePattern),
|
|
442
|
+
Edge(EdgePattern),
|
|
443
|
+
Path(PathPattern),
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
macro_rules! create_from_pattern {
|
|
447
|
+
( $x:tt, $y:tt ) => {
|
|
448
|
+
create_from! { $x, $y, Pattern }
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
#[derive(Debug, Clone)]
|
|
453
|
+
pub struct NodePattern
|
|
454
|
+
{
|
|
455
|
+
pub variable: Option<VariableIdentifier>,
|
|
456
|
+
pub labels: LabelExpression,
|
|
457
|
+
pub properties: Option<Expression>,
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
create_from_pattern! {NodePattern, Node}
|
|
461
|
+
|
|
462
|
+
#[derive(Debug, Clone)]
|
|
463
|
+
pub struct EdgePattern
|
|
464
|
+
{
|
|
465
|
+
pub variable: Option<VariableIdentifier>,
|
|
466
|
+
pub source: NodePattern,
|
|
467
|
+
pub destination: NodePattern,
|
|
468
|
+
pub directivity: graphcore::EdgeDirectivity,
|
|
469
|
+
pub labels: LabelExpression,
|
|
470
|
+
pub properties: Option<Expression>,
|
|
471
|
+
/// Indicates the range for a recursive match.
|
|
472
|
+
pub recursive_range: Option<std::ops::Range<usize>>,
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
create_from_pattern! {EdgePattern, Edge}
|
|
476
|
+
|
|
477
|
+
#[derive(Debug, Clone)]
|
|
478
|
+
pub struct PathPattern
|
|
479
|
+
{
|
|
480
|
+
pub variable: VariableIdentifier,
|
|
481
|
+
pub edge: EdgePattern,
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
create_from_pattern! {PathPattern, Path}
|
|
485
|
+
|
|
486
|
+
// Label Expression
|
|
487
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
488
|
+
pub enum LabelExpression
|
|
489
|
+
{
|
|
490
|
+
#[allow(dead_code)]
|
|
491
|
+
Not(Box<LabelExpression>),
|
|
492
|
+
And(Vec<LabelExpression>),
|
|
493
|
+
Or(Vec<LabelExpression>),
|
|
494
|
+
String(String),
|
|
495
|
+
None,
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
impl LabelExpression
|
|
499
|
+
{
|
|
500
|
+
/// Return true if all labels should match, i.e. if it is an `and` expression.
|
|
501
|
+
pub fn is_all_inclusive(&self) -> bool
|
|
502
|
+
{
|
|
503
|
+
match self
|
|
504
|
+
{
|
|
505
|
+
LabelExpression::None => true,
|
|
506
|
+
LabelExpression::And(exprs) => !exprs.iter().any(|f| !f.is_all_inclusive()),
|
|
507
|
+
LabelExpression::Or(_) => false,
|
|
508
|
+
LabelExpression::String(_) => true,
|
|
509
|
+
LabelExpression::Not(_) => false,
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
/// Return true if it is an empty label expression.
|
|
513
|
+
pub fn is_none(&self) -> bool
|
|
514
|
+
{
|
|
515
|
+
matches!(self, LabelExpression::None)
|
|
516
|
+
}
|
|
517
|
+
/// Return true if it is a string expression.
|
|
518
|
+
pub fn is_string(&self) -> bool
|
|
519
|
+
{
|
|
520
|
+
matches!(self, LabelExpression::String(_))
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Expressions
|
|
525
|
+
|
|
526
|
+
macro_rules! create_from_expr {
|
|
527
|
+
( $x:tt ) => {
|
|
528
|
+
impl From<$x> for Expression
|
|
529
|
+
{
|
|
530
|
+
fn from(v: $x) -> Expression
|
|
531
|
+
{
|
|
532
|
+
Expression::$x(v)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
macro_rules! create_from_boxed_expr {
|
|
539
|
+
( $x:tt ) => {
|
|
540
|
+
impl From<$x> for Expression
|
|
541
|
+
{
|
|
542
|
+
fn from(v: $x) -> Expression
|
|
543
|
+
{
|
|
544
|
+
Expression::$x(Box::new(v))
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
#[derive(Debug, Clone)]
|
|
551
|
+
pub struct NamedExpression
|
|
552
|
+
{
|
|
553
|
+
pub identifier: VariableIdentifier,
|
|
554
|
+
pub expression: Expression,
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
558
|
+
pub struct Parameter
|
|
559
|
+
{
|
|
560
|
+
pub name: String,
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
564
|
+
pub struct Variable
|
|
565
|
+
{
|
|
566
|
+
pub identifier: VariableIdentifier,
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
create_from_expr! {Variable}
|
|
570
|
+
|
|
571
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
572
|
+
pub struct MemberAccess
|
|
573
|
+
{
|
|
574
|
+
pub left: Expression,
|
|
575
|
+
pub path: Vec<String>,
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
create_from_boxed_expr! {MemberAccess}
|
|
579
|
+
|
|
580
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
581
|
+
pub struct IndexAccess
|
|
582
|
+
{
|
|
583
|
+
pub left: Expression,
|
|
584
|
+
pub index: Expression,
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
create_from_boxed_expr! {IndexAccess}
|
|
588
|
+
|
|
589
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
590
|
+
pub struct RangeAccess
|
|
591
|
+
{
|
|
592
|
+
pub left: Expression,
|
|
593
|
+
pub start: Option<Expression>,
|
|
594
|
+
pub end: Option<Expression>,
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
create_from_boxed_expr! {RangeAccess}
|
|
598
|
+
|
|
599
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
600
|
+
pub struct FunctionCall
|
|
601
|
+
{
|
|
602
|
+
pub name: String,
|
|
603
|
+
pub arguments: Vec<Expression>,
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
create_from_expr! {FunctionCall}
|
|
607
|
+
|
|
608
|
+
macro_rules! create_binary_op {
|
|
609
|
+
( $x:tt ) => {
|
|
610
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
611
|
+
pub struct $x
|
|
612
|
+
{
|
|
613
|
+
pub left: Expression,
|
|
614
|
+
pub right: Expression,
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
create_from_boxed_expr! { $x }
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
create_binary_op! {LogicalAnd}
|
|
622
|
+
create_binary_op! {LogicalOr}
|
|
623
|
+
create_binary_op! {LogicalXor}
|
|
624
|
+
create_binary_op! {RelationalEqual}
|
|
625
|
+
create_binary_op! {RelationalDifferent}
|
|
626
|
+
create_binary_op! {RelationalInferior}
|
|
627
|
+
create_binary_op! {RelationalSuperior}
|
|
628
|
+
create_binary_op! {RelationalInferiorEqual}
|
|
629
|
+
create_binary_op! {RelationalSuperiorEqual}
|
|
630
|
+
create_binary_op! {RelationalIn}
|
|
631
|
+
create_binary_op! {RelationalNotIn}
|
|
632
|
+
|
|
633
|
+
create_binary_op! {Addition}
|
|
634
|
+
create_binary_op! {Subtraction}
|
|
635
|
+
create_binary_op! {Multiplication}
|
|
636
|
+
create_binary_op! {Division}
|
|
637
|
+
create_binary_op! {Modulo}
|
|
638
|
+
create_binary_op! {Exponent}
|
|
639
|
+
|
|
640
|
+
macro_rules! create_unary_op {
|
|
641
|
+
( $x:tt ) => {
|
|
642
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
643
|
+
pub struct $x
|
|
644
|
+
{
|
|
645
|
+
pub value: Expression,
|
|
646
|
+
}
|
|
647
|
+
create_from_boxed_expr! { $x }
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
create_unary_op! {LogicalNegation}
|
|
652
|
+
create_unary_op! {Negation}
|
|
653
|
+
create_unary_op! {IsNull}
|
|
654
|
+
create_unary_op! {IsNotNull}
|
|
655
|
+
|
|
656
|
+
// Values
|
|
657
|
+
|
|
658
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
659
|
+
pub struct Value
|
|
660
|
+
{
|
|
661
|
+
pub value: graphcore::Value,
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
create_from_expr! {Value}
|
|
665
|
+
|
|
666
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
667
|
+
pub struct Map
|
|
668
|
+
{
|
|
669
|
+
pub map: Vec<(String, Expression)>,
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
create_from_expr! {Map}
|
|
673
|
+
|
|
674
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
675
|
+
pub struct Array
|
|
676
|
+
{
|
|
677
|
+
pub array: Vec<Expression>,
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
create_from_expr! {Array}
|