gqlite 1.2.0 → 1.2.2
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/gqliterb/.cargo/config.toml +2 -0
- data/ext/gqliterb/Cargo.lock +133 -123
- data/ext/gqliterb/Cargo.toml +3 -6
- data/ext/gqliterb/src/lib.rs +2 -2
- data/ext/gqliterb/vendor/gqlitedb/Cargo.lock +2060 -0
- data/ext/gqliterb/vendor/gqlitedb/Cargo.toml +132 -0
- data/ext/gqliterb/vendor/gqlitedb/askama.toml +3 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/common/mod.rs +25 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/common/pokec.rs +185 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/pokec_divan.rs +137 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/pokec_iai.rs +122 -0
- data/ext/gqliterb/vendor/gqlitedb/release.toml +7 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/arithmetic.rs +96 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/containers.rs +33 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/count.rs +35 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/stats.rs +168 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators.rs +74 -0
- data/ext/gqliterb/vendor/gqlitedb/src/capi.rs +236 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler/expression_analyser.rs +427 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler/variables_manager.rs +620 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler.rs +1106 -0
- data/ext/gqliterb/vendor/gqlitedb/src/connection.rs +208 -0
- data/ext/gqliterb/vendor/gqlitedb/src/consts.rs +10 -0
- data/ext/gqliterb/vendor/gqlitedb/src/error.rs +621 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/containers.rs +115 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/edge.rs +20 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/math.rs +44 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/node.rs +16 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/path.rs +48 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/scalar.rs +86 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/string.rs +28 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/value.rs +99 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions.rs +412 -0
- data/ext/gqliterb/vendor/gqlitedb/src/graph.rs +268 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/evaluators.rs +1788 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/instructions.rs +262 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/mod.rs +4 -0
- data/ext/gqliterb/vendor/gqlitedb/src/lib.rs +42 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/ast.rs +625 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/gql.pest +191 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/parser.rs +1153 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser.rs +4 -0
- data/ext/gqliterb/vendor/gqlitedb/src/prelude.rs +8 -0
- data/ext/gqliterb/vendor/gqlitedb/src/serialize_with.rs +94 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/pgql.rs +121 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/redb.rs +1250 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/sqlite.rs +994 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store.rs +432 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/compiler.rs +92 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/evaluators.rs +227 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/parser.rs +81 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store/redb.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store/sqlite.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store.rs +462 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/ast.rs +356 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/programs.rs +455 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates.rs +2 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/utils.rs +28 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/compare.rs +212 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/contains.rs +47 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/value_map.rs +298 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value.rs +559 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value_table.rs +616 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/call_stats.sql +22 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_count_for_node.sql +3 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_create.sql +6 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete_by_nodes.sql +2 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_select.sql +139 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_update.sql +4 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_create.sql +16 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_delete.sql +3 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_create_table.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_get.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_set.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_create.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_delete.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_select.sql +42 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_update.sql +4 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/table_exists.sql +5 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_from_1_01.sql +2 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_graph_from_1_01.sql +65 -0
- metadata +82 -2
@@ -0,0 +1,432 @@
|
|
1
|
+
#[cfg(feature = "_pgql")]
|
2
|
+
pub(crate) mod pgql;
|
3
|
+
#[cfg(feature = "redb")]
|
4
|
+
pub(crate) mod redb;
|
5
|
+
#[cfg(feature = "sqlite")]
|
6
|
+
pub(crate) mod sqlite;
|
7
|
+
|
8
|
+
#[cfg(feature = "_pgql")]
|
9
|
+
pub(crate) use pgql::Store;
|
10
|
+
|
11
|
+
use crate::prelude::*;
|
12
|
+
|
13
|
+
// ____ _ _ _ _ _
|
14
|
+
// / ___|| |_ __ _| |_(_)___| |_(_) ___ ___
|
15
|
+
// \___ \| __/ _` | __| / __| __| |/ __/ __|
|
16
|
+
// ___) | || (_| | |_| \__ \ |_| | (__\__ \
|
17
|
+
// |____/ \__\__,_|\__|_|___/\__|_|\___|___/
|
18
|
+
|
19
|
+
pub(crate) struct Statistics
|
20
|
+
{
|
21
|
+
pub nodes_count: usize,
|
22
|
+
pub edges_count: usize,
|
23
|
+
pub labels_nodes_count: usize,
|
24
|
+
pub properties_count: usize,
|
25
|
+
}
|
26
|
+
|
27
|
+
pub(crate) trait ReadTransaction
|
28
|
+
{
|
29
|
+
fn discard(self) -> Result<()>;
|
30
|
+
}
|
31
|
+
|
32
|
+
pub(crate) trait WriteTransaction: ReadTransaction
|
33
|
+
{
|
34
|
+
// Commit.
|
35
|
+
fn commit(self) -> Result<()>;
|
36
|
+
}
|
37
|
+
|
38
|
+
/// Box that holds a Read or a Write transaction for a store.
|
39
|
+
pub(crate) enum TransactionBox<TRead, TWrite>
|
40
|
+
where
|
41
|
+
TRead: ReadTransaction,
|
42
|
+
TWrite: WriteTransaction,
|
43
|
+
{
|
44
|
+
Read(TRead),
|
45
|
+
Write(TWrite),
|
46
|
+
}
|
47
|
+
|
48
|
+
impl<TRead, TWrite> TransactionBox<TRead, TWrite>
|
49
|
+
where
|
50
|
+
TRead: ReadTransaction,
|
51
|
+
TWrite: WriteTransaction,
|
52
|
+
{
|
53
|
+
pub(crate) fn from_read(read: TRead) -> Self
|
54
|
+
{
|
55
|
+
Self::Read(read)
|
56
|
+
}
|
57
|
+
pub(crate) fn from_write(write: TWrite) -> Self
|
58
|
+
{
|
59
|
+
Self::Write(write)
|
60
|
+
}
|
61
|
+
pub(crate) fn try_into_write(&mut self) -> Result<&mut TWrite>
|
62
|
+
{
|
63
|
+
match self
|
64
|
+
{
|
65
|
+
Self::Read(_) => Err(InternalError::NotWriteTransaction.into()),
|
66
|
+
Self::Write(write) => Ok(write),
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
/// Trait that represent a box that can contain a read or write transaction for a store.
|
72
|
+
pub(crate) trait TransactionBoxable
|
73
|
+
{
|
74
|
+
type ReadTransaction: ReadTransaction;
|
75
|
+
type WriteTransaction: WriteTransaction;
|
76
|
+
|
77
|
+
fn close(self) -> Result<()>;
|
78
|
+
}
|
79
|
+
|
80
|
+
impl<TRead, TWrite> TransactionBoxable for TransactionBox<TRead, TWrite>
|
81
|
+
where
|
82
|
+
TRead: ReadTransaction,
|
83
|
+
TWrite: WriteTransaction,
|
84
|
+
{
|
85
|
+
type ReadTransaction = TRead;
|
86
|
+
type WriteTransaction = TWrite;
|
87
|
+
|
88
|
+
fn close(self) -> Result<()>
|
89
|
+
{
|
90
|
+
match self
|
91
|
+
{
|
92
|
+
Self::Read(read) => read.discard(),
|
93
|
+
Self::Write(write) => write.commit(),
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
// ____ _
|
99
|
+
// / ___|| |_ ___ _ __ ___
|
100
|
+
// \___ \| __/ _ \| '__/ _ \
|
101
|
+
// ___) | || (_) | | | __/
|
102
|
+
// |____/ \__\___/|_| \___|
|
103
|
+
|
104
|
+
pub(crate) trait Store
|
105
|
+
{
|
106
|
+
type TransactionBox: TransactionBoxable;
|
107
|
+
fn begin_read(&self) -> Result<Self::TransactionBox>;
|
108
|
+
fn begin_write(&self) -> Result<Self::TransactionBox>;
|
109
|
+
/// List the graphs
|
110
|
+
fn graphs_list(&self, transaction: &mut Self::TransactionBox) -> Result<Vec<String>>;
|
111
|
+
/// Create a new graph
|
112
|
+
fn create_graph(
|
113
|
+
&self,
|
114
|
+
transaction: &mut Self::TransactionBox,
|
115
|
+
name: &String,
|
116
|
+
_ignore_if_exists: bool,
|
117
|
+
) -> Result<()>;
|
118
|
+
/// Delete a graph
|
119
|
+
fn delete_graph(&self, transaction: &mut Self::TransactionBox, name: &String) -> Result<()>;
|
120
|
+
/// Create nodes and add them to a graph
|
121
|
+
fn create_nodes<'a, T: Iterator<Item = &'a crate::graph::Node>>(
|
122
|
+
&self,
|
123
|
+
transaction: &mut Self::TransactionBox,
|
124
|
+
graph_name: &String,
|
125
|
+
nodes_iter: T,
|
126
|
+
) -> Result<()>;
|
127
|
+
/// Create nodes and add them to a graph
|
128
|
+
fn update_node(
|
129
|
+
&self,
|
130
|
+
transaction: &mut Self::TransactionBox,
|
131
|
+
graph_name: &String,
|
132
|
+
node: &graph::Node,
|
133
|
+
) -> Result<()>;
|
134
|
+
/// Delete nodes according to a given query
|
135
|
+
fn delete_nodes(
|
136
|
+
&self,
|
137
|
+
transaction: &mut Self::TransactionBox,
|
138
|
+
graph_name: &String,
|
139
|
+
query: SelectNodeQuery,
|
140
|
+
detach: bool,
|
141
|
+
) -> Result<()>;
|
142
|
+
/// Select nodes according to a given query
|
143
|
+
fn select_nodes(
|
144
|
+
&self,
|
145
|
+
transaction: &mut Self::TransactionBox,
|
146
|
+
graph_name: &String,
|
147
|
+
query: SelectNodeQuery,
|
148
|
+
) -> Result<Vec<crate::graph::Node>>;
|
149
|
+
/// Add edge
|
150
|
+
fn create_edges<'a, T: Iterator<Item = &'a crate::graph::Edge>>(
|
151
|
+
&self,
|
152
|
+
transaction: &mut Self::TransactionBox,
|
153
|
+
graph_name: &String,
|
154
|
+
edges_iter: T,
|
155
|
+
) -> Result<()>;
|
156
|
+
fn update_edge(
|
157
|
+
&self,
|
158
|
+
transaction: &mut Self::TransactionBox,
|
159
|
+
graph_name: &String,
|
160
|
+
edge: &graph::Edge,
|
161
|
+
) -> Result<()>;
|
162
|
+
/// Delete nodes according to a given query
|
163
|
+
fn delete_edges(
|
164
|
+
&self,
|
165
|
+
transaction: &mut Self::TransactionBox,
|
166
|
+
graph_name: &String,
|
167
|
+
query: SelectEdgeQuery,
|
168
|
+
directivity: graph::EdgeDirectivity,
|
169
|
+
) -> Result<()>;
|
170
|
+
/// Select edges
|
171
|
+
fn select_edges(
|
172
|
+
&self,
|
173
|
+
transaction: &mut Self::TransactionBox,
|
174
|
+
graph_name: &String,
|
175
|
+
query: SelectEdgeQuery,
|
176
|
+
directivity: graph::EdgeDirectivity,
|
177
|
+
) -> Result<Vec<EdgeResult>>;
|
178
|
+
/// Compute store statistics
|
179
|
+
fn compute_statistics(&self, transaction: &mut Self::TransactionBox) -> Result<Statistics>;
|
180
|
+
}
|
181
|
+
|
182
|
+
// _____ _ ____ _ _
|
183
|
+
// | ____|__| | __ _ ___| _ \ ___ ___ _ _| | |_
|
184
|
+
// | _| / _` |/ _` |/ _ \ |_) / _ \/ __| | | | | __|
|
185
|
+
// | |__| (_| | (_| | __/ _ < __/\__ \ |_| | | |_
|
186
|
+
// |_____\__,_|\__, |\___|_| \_\___||___/\__,_|_|\__|
|
187
|
+
// |___/
|
188
|
+
|
189
|
+
pub(crate) struct EdgeResult
|
190
|
+
{
|
191
|
+
pub(crate) edge: graph::Edge,
|
192
|
+
pub(crate) reversed: bool,
|
193
|
+
}
|
194
|
+
|
195
|
+
// ____ _ _ _ _ _ ___
|
196
|
+
// / ___| ___| | ___ ___| |_| \ | | ___ __| | ___ / _ \ _ _ ___ _ __ _ _
|
197
|
+
// \___ \ / _ \ |/ _ \/ __| __| \| |/ _ \ / _` |/ _ \ | | | | | |/ _ \ '__| | | |
|
198
|
+
// ___) | __/ | __/ (__| |_| |\ | (_) | (_| | __/ |_| | |_| | __/ | | |_| |
|
199
|
+
// |____/ \___|_|\___|\___|\__|_| \_|\___/ \__,_|\___|\__\_\\__,_|\___|_| \__, |
|
200
|
+
// |___/
|
201
|
+
|
202
|
+
#[derive(Debug, Clone)]
|
203
|
+
pub(crate) struct SelectNodeQuery
|
204
|
+
{
|
205
|
+
keys: Option<Vec<graph::Key>>,
|
206
|
+
labels: Option<Vec<String>>,
|
207
|
+
properties: Option<value::ValueMap>,
|
208
|
+
select_all: bool,
|
209
|
+
}
|
210
|
+
|
211
|
+
impl SelectNodeQuery
|
212
|
+
{
|
213
|
+
fn is_select_all(&self) -> bool
|
214
|
+
{
|
215
|
+
self.select_all
|
216
|
+
}
|
217
|
+
fn is_select_none(&self) -> bool
|
218
|
+
{
|
219
|
+
self.keys.is_none() && self.labels.is_none() && self.properties.is_none() && !self.select_all
|
220
|
+
}
|
221
|
+
pub(crate) fn is_select_only_keys(&self) -> bool
|
222
|
+
{
|
223
|
+
self.labels.is_none() && self.properties.is_none() && !self.select_all
|
224
|
+
}
|
225
|
+
pub(crate) fn select_all() -> Self
|
226
|
+
{
|
227
|
+
Self {
|
228
|
+
keys: None,
|
229
|
+
labels: None,
|
230
|
+
properties: None,
|
231
|
+
select_all: true,
|
232
|
+
}
|
233
|
+
}
|
234
|
+
pub(crate) fn select_none() -> Self
|
235
|
+
{
|
236
|
+
Self {
|
237
|
+
keys: None,
|
238
|
+
labels: None,
|
239
|
+
properties: None,
|
240
|
+
select_all: false,
|
241
|
+
}
|
242
|
+
}
|
243
|
+
#[allow(unused)]
|
244
|
+
pub(crate) fn select_keys(keys: impl Into<Vec<graph::Key>>) -> Self
|
245
|
+
{
|
246
|
+
Self {
|
247
|
+
keys: Some(keys.into()),
|
248
|
+
labels: None,
|
249
|
+
properties: None,
|
250
|
+
select_all: false,
|
251
|
+
}
|
252
|
+
}
|
253
|
+
pub(crate) fn select_labels(labels: impl Into<Vec<String>>) -> Self
|
254
|
+
{
|
255
|
+
Self {
|
256
|
+
keys: None,
|
257
|
+
labels: Some(labels.into()),
|
258
|
+
properties: None,
|
259
|
+
select_all: false,
|
260
|
+
}
|
261
|
+
}
|
262
|
+
pub(crate) fn select_labels_properties(
|
263
|
+
labels: impl Into<Vec<String>>,
|
264
|
+
properties: value::ValueMap,
|
265
|
+
) -> Self
|
266
|
+
{
|
267
|
+
Self {
|
268
|
+
keys: None,
|
269
|
+
labels: Some(labels.into()),
|
270
|
+
properties: Some(properties),
|
271
|
+
select_all: false,
|
272
|
+
}
|
273
|
+
}
|
274
|
+
pub(crate) fn is_match(&self, node: &graph::Node) -> bool
|
275
|
+
{
|
276
|
+
if self.select_all
|
277
|
+
{
|
278
|
+
return true;
|
279
|
+
}
|
280
|
+
if let Some(keys) = &self.keys
|
281
|
+
{
|
282
|
+
if !keys.iter().any(|x| node.key == *x)
|
283
|
+
{
|
284
|
+
return false;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
if let Some(labels) = &self.labels
|
288
|
+
{
|
289
|
+
if !labels.iter().all(|x| node.labels.contains(x))
|
290
|
+
{
|
291
|
+
return false;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
if let Some(properties) = &self.properties
|
295
|
+
{
|
296
|
+
if !properties
|
297
|
+
.iter()
|
298
|
+
.all(|(k, v)| node.properties.get(k) == Some(v))
|
299
|
+
{
|
300
|
+
return false;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
return true;
|
304
|
+
}
|
305
|
+
}
|
306
|
+
|
307
|
+
// ____ _ _ _____ _ ___
|
308
|
+
// / ___| ___| | ___ ___| |_| ____|__| | __ _ ___ / _ \ _ _ ___ _ __ _ _
|
309
|
+
// \___ \ / _ \ |/ _ \/ __| __| _| / _` |/ _` |/ _ \ | | | | | |/ _ \ '__| | | |
|
310
|
+
// ___) | __/ | __/ (__| |_| |__| (_| | (_| | __/ |_| | |_| | __/ | | |_| |
|
311
|
+
// |____/ \___|_|\___|\___|\__|_____\__,_|\__, |\___|\__\_\\__,_|\___|_| \__, |
|
312
|
+
// |___/ |___/
|
313
|
+
|
314
|
+
#[derive(Debug, Clone)]
|
315
|
+
pub(crate) struct SelectEdgeQuery
|
316
|
+
{
|
317
|
+
keys: Option<Vec<graph::Key>>,
|
318
|
+
labels: Option<Vec<String>>,
|
319
|
+
properties: Option<value::ValueMap>,
|
320
|
+
source: SelectNodeQuery,
|
321
|
+
destination: SelectNodeQuery,
|
322
|
+
}
|
323
|
+
|
324
|
+
impl SelectEdgeQuery
|
325
|
+
{
|
326
|
+
pub(crate) fn is_select_only_keys(&self) -> bool
|
327
|
+
{
|
328
|
+
self.keys.is_some()
|
329
|
+
&& self.labels.is_none()
|
330
|
+
&& self.properties.is_none()
|
331
|
+
&& self.source.select_all
|
332
|
+
&& self.destination.select_all
|
333
|
+
}
|
334
|
+
|
335
|
+
pub(crate) fn select_all() -> Self
|
336
|
+
{
|
337
|
+
Self {
|
338
|
+
keys: None,
|
339
|
+
labels: None,
|
340
|
+
properties: None,
|
341
|
+
source: SelectNodeQuery::select_all(),
|
342
|
+
destination: SelectNodeQuery::select_all(),
|
343
|
+
}
|
344
|
+
}
|
345
|
+
pub(crate) fn select_none() -> Self
|
346
|
+
{
|
347
|
+
Self {
|
348
|
+
keys: None,
|
349
|
+
labels: None,
|
350
|
+
properties: None,
|
351
|
+
source: SelectNodeQuery::select_none(),
|
352
|
+
destination: SelectNodeQuery::select_none(),
|
353
|
+
}
|
354
|
+
}
|
355
|
+
#[allow(unused)]
|
356
|
+
pub(crate) fn select_keys(keys: impl Into<Vec<graph::Key>>) -> Self
|
357
|
+
{
|
358
|
+
Self {
|
359
|
+
keys: Some(keys.into()),
|
360
|
+
labels: None,
|
361
|
+
properties: None,
|
362
|
+
source: SelectNodeQuery::select_all(),
|
363
|
+
destination: SelectNodeQuery::select_all(),
|
364
|
+
}
|
365
|
+
}
|
366
|
+
pub(crate) fn select_source_keys(source_query: SelectNodeQuery) -> Self
|
367
|
+
{
|
368
|
+
Self {
|
369
|
+
keys: None,
|
370
|
+
labels: None,
|
371
|
+
properties: None,
|
372
|
+
source: source_query,
|
373
|
+
destination: SelectNodeQuery::select_all(),
|
374
|
+
}
|
375
|
+
}
|
376
|
+
pub(crate) fn select_source_destination_keys(
|
377
|
+
source_query: SelectNodeQuery,
|
378
|
+
keys: impl Into<Vec<graph::Key>>,
|
379
|
+
destination_query: SelectNodeQuery,
|
380
|
+
) -> Self
|
381
|
+
{
|
382
|
+
Self {
|
383
|
+
keys: Some(keys.into()),
|
384
|
+
labels: None,
|
385
|
+
properties: None,
|
386
|
+
source: source_query,
|
387
|
+
destination: destination_query,
|
388
|
+
}
|
389
|
+
}
|
390
|
+
pub(crate) fn select_source_destination_labels_properties(
|
391
|
+
source_query: SelectNodeQuery,
|
392
|
+
labels: impl Into<Vec<String>>,
|
393
|
+
properties: value::ValueMap,
|
394
|
+
destination_query: SelectNodeQuery,
|
395
|
+
) -> Self
|
396
|
+
{
|
397
|
+
Self {
|
398
|
+
keys: None,
|
399
|
+
labels: Some(labels.into()),
|
400
|
+
properties: Some(properties),
|
401
|
+
source: source_query,
|
402
|
+
destination: destination_query,
|
403
|
+
}
|
404
|
+
}
|
405
|
+
pub(crate) fn is_match(&self, edge: &graph::Edge) -> bool
|
406
|
+
{
|
407
|
+
if let Some(keys) = &self.keys
|
408
|
+
{
|
409
|
+
if !keys.iter().any(|x| edge.key == *x)
|
410
|
+
{
|
411
|
+
return false;
|
412
|
+
}
|
413
|
+
}
|
414
|
+
if let Some(labels) = &self.labels
|
415
|
+
{
|
416
|
+
if !labels.iter().all(|x| edge.labels.contains(x))
|
417
|
+
{
|
418
|
+
return false;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
if let Some(properties) = &self.properties
|
422
|
+
{
|
423
|
+
if !properties
|
424
|
+
.iter()
|
425
|
+
.all(|(k, v)| edge.properties.get(k) == Some(v))
|
426
|
+
{
|
427
|
+
return false;
|
428
|
+
}
|
429
|
+
}
|
430
|
+
return self.source.is_match(&edge.source) && self.destination.is_match(&edge.destination);
|
431
|
+
}
|
432
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
use crate::{
|
2
|
+
compiler::compile,
|
3
|
+
interpreter::Program,
|
4
|
+
prelude::*,
|
5
|
+
tests::templates::{ast, programs},
|
6
|
+
};
|
7
|
+
|
8
|
+
fn compare_program(actual: Program, expected: Program)
|
9
|
+
{
|
10
|
+
assert_eq!(format!("{:?}", actual), format!("{:?}", expected));
|
11
|
+
}
|
12
|
+
|
13
|
+
#[test]
|
14
|
+
fn test_compile_simple_create_node()
|
15
|
+
{
|
16
|
+
let function_manager = functions::Manager::new();
|
17
|
+
|
18
|
+
let program = compile(&function_manager, ast::simple_create_node()).unwrap();
|
19
|
+
compare_program(program, programs::simple_create())
|
20
|
+
}
|
21
|
+
|
22
|
+
#[test]
|
23
|
+
fn test_compile_create_named_node()
|
24
|
+
{
|
25
|
+
let function_manager = functions::Manager::new();
|
26
|
+
|
27
|
+
let program = compile(&function_manager, ast::create_named_node()).unwrap();
|
28
|
+
compare_program(program, programs::create_named_node())
|
29
|
+
}
|
30
|
+
|
31
|
+
#[test]
|
32
|
+
fn test_compile_create_named_node_double_return()
|
33
|
+
{
|
34
|
+
let function_manager = functions::Manager::new();
|
35
|
+
|
36
|
+
let program = compile(&function_manager, ast::create_named_node_double_return()).unwrap();
|
37
|
+
compare_program(program, programs::create_named_node_double_return())
|
38
|
+
}
|
39
|
+
|
40
|
+
#[test]
|
41
|
+
fn test_compile_double_with_return()
|
42
|
+
{
|
43
|
+
let function_manager = functions::Manager::new();
|
44
|
+
|
45
|
+
let program = compile(&function_manager, ast::double_with_return()).unwrap();
|
46
|
+
compare_program(program, programs::double_with_return())
|
47
|
+
}
|
48
|
+
|
49
|
+
#[test]
|
50
|
+
fn test_compile_unwind()
|
51
|
+
{
|
52
|
+
let function_manager = functions::Manager::new();
|
53
|
+
|
54
|
+
let program = compile(&function_manager, ast::unwind()).unwrap();
|
55
|
+
compare_program(program, programs::unwind())
|
56
|
+
}
|
57
|
+
|
58
|
+
#[test]
|
59
|
+
fn test_compile_match_loop()
|
60
|
+
{
|
61
|
+
let function_manager = functions::Manager::new();
|
62
|
+
|
63
|
+
let program = compile(&function_manager, ast::match_loop()).unwrap();
|
64
|
+
compare_program(program, programs::match_loop())
|
65
|
+
}
|
66
|
+
|
67
|
+
#[test]
|
68
|
+
fn test_compile_optional_match()
|
69
|
+
{
|
70
|
+
let function_manager = functions::Manager::new();
|
71
|
+
|
72
|
+
let program = compile(&function_manager, ast::optional_match()).unwrap();
|
73
|
+
compare_program(program, programs::optional_match())
|
74
|
+
}
|
75
|
+
|
76
|
+
#[test]
|
77
|
+
fn test_compile_match_count()
|
78
|
+
{
|
79
|
+
let function_manager = functions::Manager::new();
|
80
|
+
|
81
|
+
let program = compile(&function_manager, ast::match_count()).unwrap();
|
82
|
+
compare_program(program, programs::match_count(&function_manager))
|
83
|
+
}
|
84
|
+
|
85
|
+
#[test]
|
86
|
+
fn test_compile_aggregation()
|
87
|
+
{
|
88
|
+
let function_manager = functions::Manager::new();
|
89
|
+
|
90
|
+
let program = compile(&function_manager, ast::aggregation()).unwrap();
|
91
|
+
compare_program(program, programs::aggregation(&function_manager))
|
92
|
+
}
|