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,412 @@
|
|
1
|
+
use std::{collections::HashMap, fmt::Debug, sync::Arc};
|
2
|
+
|
3
|
+
mod containers;
|
4
|
+
mod edge;
|
5
|
+
mod math;
|
6
|
+
mod node;
|
7
|
+
mod path;
|
8
|
+
mod scalar;
|
9
|
+
mod string;
|
10
|
+
mod value;
|
11
|
+
|
12
|
+
pub(crate) type FResult<T> = std::result::Result<T, error::RunTimeError>;
|
13
|
+
|
14
|
+
use crate::prelude::*;
|
15
|
+
use ccutils::sync::ArcRwLock;
|
16
|
+
use compiler::expression_analyser::ExpressionType;
|
17
|
+
|
18
|
+
pub(crate) trait FunctionTypeTrait
|
19
|
+
{
|
20
|
+
fn result_type() -> ExpressionType;
|
21
|
+
}
|
22
|
+
|
23
|
+
impl FunctionTypeTrait for crate::value::Value
|
24
|
+
{
|
25
|
+
fn result_type() -> ExpressionType
|
26
|
+
{
|
27
|
+
ExpressionType::Variant
|
28
|
+
}
|
29
|
+
}
|
30
|
+
impl FunctionTypeTrait for bool
|
31
|
+
{
|
32
|
+
fn result_type() -> ExpressionType
|
33
|
+
{
|
34
|
+
ExpressionType::Boolean
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
impl FunctionTypeTrait for String
|
39
|
+
{
|
40
|
+
fn result_type() -> ExpressionType
|
41
|
+
{
|
42
|
+
ExpressionType::String
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
impl FunctionTypeTrait for i64
|
47
|
+
{
|
48
|
+
fn result_type() -> ExpressionType
|
49
|
+
{
|
50
|
+
ExpressionType::Integer
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
impl FunctionTypeTrait for f64
|
55
|
+
{
|
56
|
+
fn result_type() -> ExpressionType
|
57
|
+
{
|
58
|
+
ExpressionType::Float
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
impl<T> FunctionTypeTrait for Vec<T>
|
63
|
+
{
|
64
|
+
fn result_type() -> ExpressionType
|
65
|
+
{
|
66
|
+
ExpressionType::Array
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
impl<T> FunctionTypeTrait for HashMap<String, T>
|
71
|
+
{
|
72
|
+
fn result_type() -> ExpressionType
|
73
|
+
{
|
74
|
+
ExpressionType::Map
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
impl FunctionTypeTrait for crate::value::ValueMap
|
79
|
+
{
|
80
|
+
fn result_type() -> ExpressionType
|
81
|
+
{
|
82
|
+
ExpressionType::Map
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
// _____ _ _ _____ _ _
|
87
|
+
// | ___| _ _ __ ___| |_(_) ___ _ _|_ _| __ __ _(_) |_
|
88
|
+
// | |_ | | | | '_ \ / __| __| |/ _ \| '_ \| || '__/ _` | | __|
|
89
|
+
// | _|| |_| | | | | (__| |_| | (_) | | | | || | | (_| | | |_
|
90
|
+
// |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|_||_| \__,_|_|\__|
|
91
|
+
|
92
|
+
pub(crate) trait FunctionTrait: Debug + Sync + Send
|
93
|
+
{
|
94
|
+
fn call(&self, arguments: Vec<crate::value::Value>) -> Result<crate::value::Value>;
|
95
|
+
fn validate_arguments(&self, arguments: Vec<ExpressionType>) -> Result<ExpressionType>;
|
96
|
+
fn is_deterministic(&self) -> bool;
|
97
|
+
}
|
98
|
+
|
99
|
+
// _____ _ _
|
100
|
+
// | ___| _ _ __ ___| |_(_) ___ _ __
|
101
|
+
// | |_ | | | | '_ \ / __| __| |/ _ \| '_ \
|
102
|
+
// | _|| |_| | | | | (__| |_| | (_) | | | |
|
103
|
+
// |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|
|
104
|
+
|
105
|
+
pub(crate) type Function = Arc<Box<dyn FunctionTrait>>;
|
106
|
+
|
107
|
+
// __ __
|
108
|
+
// | \/ | __ _ _ __ __ _ __ _ ___ _ __
|
109
|
+
// | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
|
110
|
+
// | | | | (_| | | | | (_| | (_| | __/ |
|
111
|
+
// |_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
|
112
|
+
// |___/
|
113
|
+
|
114
|
+
#[derive(Debug)]
|
115
|
+
struct ManagerInner
|
116
|
+
{
|
117
|
+
functions: HashMap<String, Function>,
|
118
|
+
aggregators: HashMap<String, aggregators::Aggregator>,
|
119
|
+
}
|
120
|
+
|
121
|
+
#[derive(Debug, Clone)]
|
122
|
+
pub(crate) struct Manager
|
123
|
+
{
|
124
|
+
inner: ArcRwLock<ManagerInner>,
|
125
|
+
}
|
126
|
+
|
127
|
+
ccutils::assert_impl_all!(Manager: Sync, Send);
|
128
|
+
|
129
|
+
impl Manager
|
130
|
+
{
|
131
|
+
pub(crate) fn new() -> Self
|
132
|
+
{
|
133
|
+
Self {
|
134
|
+
inner: ManagerInner {
|
135
|
+
functions: HashMap::from([
|
136
|
+
containers::Head::new(),
|
137
|
+
containers::Keys::new(),
|
138
|
+
containers::Range::new(),
|
139
|
+
containers::Size::new(),
|
140
|
+
edge::Type::new(),
|
141
|
+
math::Ceil::new(),
|
142
|
+
math::Floor::new(),
|
143
|
+
math::Rand::new(),
|
144
|
+
node::Labels::new(),
|
145
|
+
path::Length::new(),
|
146
|
+
scalar::Coalesce::new(),
|
147
|
+
scalar::Properties::new(),
|
148
|
+
scalar::ToInteger::new(),
|
149
|
+
string::ToString::new(),
|
150
|
+
value::HasLabel::new(),
|
151
|
+
value::HasLabels::new(),
|
152
|
+
]),
|
153
|
+
aggregators: aggregators::init_aggregators(),
|
154
|
+
}
|
155
|
+
.into(),
|
156
|
+
}
|
157
|
+
}
|
158
|
+
pub(crate) fn get_function<E: error::GenericErrors>(
|
159
|
+
&self,
|
160
|
+
name: impl Into<String>,
|
161
|
+
) -> Result<Function>
|
162
|
+
{
|
163
|
+
let name = name.into();
|
164
|
+
Ok(
|
165
|
+
self
|
166
|
+
.inner
|
167
|
+
.read()?
|
168
|
+
.functions
|
169
|
+
.get(&name)
|
170
|
+
.ok_or_else(|| E::unknown_function(name).into())?
|
171
|
+
.clone(),
|
172
|
+
)
|
173
|
+
}
|
174
|
+
pub(crate) fn get_aggregator<E: error::GenericErrors>(
|
175
|
+
&self,
|
176
|
+
name: impl Into<String>,
|
177
|
+
) -> Result<aggregators::Aggregator>
|
178
|
+
{
|
179
|
+
let name = name.into();
|
180
|
+
Ok(
|
181
|
+
self
|
182
|
+
.inner
|
183
|
+
.read()?
|
184
|
+
.aggregators
|
185
|
+
.get(&name)
|
186
|
+
.ok_or_else(|| E::unknown_function(name).into())?
|
187
|
+
.clone(),
|
188
|
+
)
|
189
|
+
}
|
190
|
+
pub(crate) fn is_deterministic(&self, name: impl Into<String>) -> Result<bool>
|
191
|
+
{
|
192
|
+
let name = name.into();
|
193
|
+
let fun = self.get_function::<crate::error::CompileTimeError>(name.clone());
|
194
|
+
match fun
|
195
|
+
{
|
196
|
+
Ok(fun) => Ok(fun.is_deterministic()),
|
197
|
+
Err(_) =>
|
198
|
+
{
|
199
|
+
self.get_aggregator::<crate::error::CompileTimeError>(name)?;
|
200
|
+
Ok(false)
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
pub(crate) fn is_aggregate(&self, name: &String) -> Result<bool>
|
205
|
+
{
|
206
|
+
Ok(self.inner.read()?.aggregators.contains_key(name))
|
207
|
+
}
|
208
|
+
|
209
|
+
pub(crate) fn validate_arguments(
|
210
|
+
&self,
|
211
|
+
name: impl Into<String>,
|
212
|
+
arguments: Vec<ExpressionType>,
|
213
|
+
) -> Result<ExpressionType>
|
214
|
+
{
|
215
|
+
let name = name.into();
|
216
|
+
let fun = self.get_function::<crate::error::CompileTimeError>(name.clone());
|
217
|
+
match fun
|
218
|
+
{
|
219
|
+
Ok(fun) => fun.validate_arguments(arguments),
|
220
|
+
Err(_) => self
|
221
|
+
.get_aggregator::<crate::error::CompileTimeError>(name)?
|
222
|
+
.validate_arguments(arguments),
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
macro_rules! make_function_argument {
|
228
|
+
($function_name: ident, $arguments: ident, $index: expr, $arg_type: ty) => {
|
229
|
+
$arguments[$index]
|
230
|
+
.try_into_ref()
|
231
|
+
.map_err(|_| RunTimeError::InvalidArgument {
|
232
|
+
function_name: stringify!($function_name),
|
233
|
+
index: $index,
|
234
|
+
expected_type: stringify!($arg_type),
|
235
|
+
value: format!("{:?}", $arguments[$index]),
|
236
|
+
})?
|
237
|
+
};
|
238
|
+
}
|
239
|
+
|
240
|
+
macro_rules! make_function_call {
|
241
|
+
($function_name: ident, $function: expr, $arguments: ident, $arg_type_0: ty, ) => {
|
242
|
+
$function($crate::functions::make_function_argument!(
|
243
|
+
$function_name,
|
244
|
+
$arguments,
|
245
|
+
0,
|
246
|
+
$arg_type_0
|
247
|
+
))
|
248
|
+
};
|
249
|
+
($function_name: ident, $function: expr, $arguments: ident, $arg_type_0: ty, $arg_type_1: ty, ) => {
|
250
|
+
$function(
|
251
|
+
$crate::functions::make_function_argument!($function_name, $arguments, 0, $arg_type_0),
|
252
|
+
$crate::functions::make_function_argument!($function_name, $arguments, 1, $arg_type_1),
|
253
|
+
)
|
254
|
+
};
|
255
|
+
($function_name: ident, $function: expr, $arguments: ident, ) => {
|
256
|
+
$function()
|
257
|
+
};
|
258
|
+
}
|
259
|
+
|
260
|
+
macro_rules! count_arguments {
|
261
|
+
($count: expr, ) => {
|
262
|
+
$count
|
263
|
+
};
|
264
|
+
($count: expr, $arg_type_0: ty, $( $arg_type: ty , )*) => {
|
265
|
+
$crate::functions::count_arguments!($count + 1, $( $arg_type, )*)
|
266
|
+
};
|
267
|
+
($( $arg_type: ty $(,)? )* ) => {
|
268
|
+
$crate::functions::count_arguments!(0, $( $arg_type, )*)
|
269
|
+
};
|
270
|
+
}
|
271
|
+
|
272
|
+
macro_rules! count_patterns {
|
273
|
+
($count: expr, ) => {
|
274
|
+
$count
|
275
|
+
};
|
276
|
+
($count: expr, $arg_type_0: pat, $( $arg_pat: pat , )*) => {
|
277
|
+
$crate::functions::count_patterns!($count + 1, $( $arg_pat, )*)
|
278
|
+
};
|
279
|
+
($( $arg_pat: pat $(,)? )* ) => {
|
280
|
+
$crate::functions::count_patterns!(0, $( $arg_pat, )*)
|
281
|
+
};
|
282
|
+
}
|
283
|
+
|
284
|
+
#[rustfmt::skip]
|
285
|
+
macro_rules! default_validate_ {
|
286
|
+
($function_name: ident, $ret_type: ty) => {
|
287
|
+
|_: Vec<$crate::compiler::expression_analyser::ExpressionType>|
|
288
|
+
-> crate::Result<$crate::compiler::expression_analyser::ExpressionType>
|
289
|
+
{
|
290
|
+
// TODO
|
291
|
+
Ok(<$ret_type>::result_type())
|
292
|
+
}
|
293
|
+
};
|
294
|
+
}
|
295
|
+
|
296
|
+
#[rustfmt::skip]
|
297
|
+
macro_rules! validate_args_ {
|
298
|
+
($function_name: ident, $ret_type: ty, $( $expression_type: pat ),* ) => {
|
299
|
+
|args: Vec<$crate::compiler::expression_analyser::ExpressionType>|
|
300
|
+
-> crate::Result<$crate::compiler::expression_analyser::ExpressionType>
|
301
|
+
{
|
302
|
+
const ARG_COUNT: usize = $crate::functions::count_patterns!($( $expression_type,)*);
|
303
|
+
if args.len() != ARG_COUNT
|
304
|
+
{
|
305
|
+
Err(crate::error::CompileTimeError::InvalidNumberOfArguments {
|
306
|
+
function_name: stringify!($function_name),
|
307
|
+
got: args.len(),
|
308
|
+
expected: ARG_COUNT
|
309
|
+
})?;
|
310
|
+
}
|
311
|
+
let mut it = args.into_iter();
|
312
|
+
$(
|
313
|
+
match it.next().unwrap()
|
314
|
+
{
|
315
|
+
$expression_type | ExpressionType::Variant =>
|
316
|
+
Ok(<$ret_type>::result_type()),
|
317
|
+
_ => Err(crate::error::CompileTimeError::InvalidArgumentType.into())
|
318
|
+
}
|
319
|
+
)*
|
320
|
+
}
|
321
|
+
};
|
322
|
+
}
|
323
|
+
|
324
|
+
macro_rules! declare_function_ {
|
325
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, $allow_null: expr, $validator: block ) => {
|
326
|
+
impl $type_name
|
327
|
+
{
|
328
|
+
pub(super) fn new() -> (String, crate::functions::Function)
|
329
|
+
{
|
330
|
+
(
|
331
|
+
stringify!($function_name).to_string(),
|
332
|
+
std::sync::Arc::new(Box::new(Self {})),
|
333
|
+
)
|
334
|
+
}
|
335
|
+
}
|
336
|
+
impl crate::functions::FunctionTrait for $type_name
|
337
|
+
{
|
338
|
+
fn call(&self, arguments: Vec<crate::value::Value>) -> crate::Result<crate::value::Value>
|
339
|
+
{
|
340
|
+
const ARG_COUNT: usize = $crate::functions::count_arguments!($( $arg_type,)*);
|
341
|
+
if arguments.len() == ARG_COUNT
|
342
|
+
{
|
343
|
+
if !$allow_null && ARG_COUNT > 0 && arguments.iter().all(|x| x.is_null())
|
344
|
+
{
|
345
|
+
return Ok(crate::value::Value::Null)
|
346
|
+
}
|
347
|
+
#[allow(unused_imports)]
|
348
|
+
use crate::value::ValueTryIntoRef;
|
349
|
+
Ok(
|
350
|
+
$crate::functions::make_function_call!($function_name, Self::$f_name, arguments, $( $arg_type,)*)
|
351
|
+
.map(|r| -> crate::value::Value { r.into() })?,
|
352
|
+
)
|
353
|
+
}
|
354
|
+
else
|
355
|
+
{
|
356
|
+
Err(RunTimeError::InvalidNumberOfArguments { function_name: stringify!($function_name), got: arguments.len(), expected: ARG_COUNT }.into())
|
357
|
+
}
|
358
|
+
}
|
359
|
+
fn validate_arguments(
|
360
|
+
&self,
|
361
|
+
args: Vec<$crate::compiler::expression_analyser::ExpressionType>,
|
362
|
+
) -> crate::Result<$crate::compiler::expression_analyser::ExpressionType>
|
363
|
+
{
|
364
|
+
let val_fn = $validator;
|
365
|
+
val_fn(args)
|
366
|
+
}
|
367
|
+
fn is_deterministic(&self) -> bool
|
368
|
+
{
|
369
|
+
true
|
370
|
+
}
|
371
|
+
}
|
372
|
+
};
|
373
|
+
}
|
374
|
+
|
375
|
+
macro_rules! declare_function {
|
376
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty ) => {
|
377
|
+
$crate::functions::declare_function_!($function_name, $type_name,
|
378
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type, false,
|
379
|
+
{$crate::functions::default_validate_!($function_name, $ret_type)} );
|
380
|
+
};
|
381
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, accept_null ) => {
|
382
|
+
$crate::functions::declare_function_!($function_name, $type_name,
|
383
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type, true,
|
384
|
+
{$crate::functions::default_validate_!($function_name, $ret_type)} );
|
385
|
+
};
|
386
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, validate_args( $( $expression_types: pat ),+ ) ) => {
|
387
|
+
$crate::functions::declare_function_!($function_name, $type_name,
|
388
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type, false,
|
389
|
+
{$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )} );
|
390
|
+
};
|
391
|
+
($function_name: ident, $type_name: ty, custom_trait ) => {
|
392
|
+
impl $type_name
|
393
|
+
{
|
394
|
+
pub(super) fn new() -> (String, crate::functions::Function)
|
395
|
+
{
|
396
|
+
(
|
397
|
+
stringify!($function_name).to_string(),
|
398
|
+
std::sync::Arc::new(Box::new(Self {})),
|
399
|
+
)
|
400
|
+
}
|
401
|
+
}
|
402
|
+
};
|
403
|
+
}
|
404
|
+
|
405
|
+
pub(crate) use count_arguments;
|
406
|
+
pub(crate) use count_patterns;
|
407
|
+
pub(crate) use declare_function;
|
408
|
+
pub(crate) use declare_function_;
|
409
|
+
pub(crate) use default_validate_;
|
410
|
+
pub(crate) use make_function_argument;
|
411
|
+
pub(crate) use make_function_call;
|
412
|
+
pub(crate) use validate_args_;
|
@@ -0,0 +1,268 @@
|
|
1
|
+
use serde::{Deserialize, Serialize};
|
2
|
+
use std::borrow::Borrow;
|
3
|
+
|
4
|
+
use crate::prelude::*;
|
5
|
+
|
6
|
+
#[derive(Debug, Clone, Copy)]
|
7
|
+
pub(crate) enum EdgeDirectivity
|
8
|
+
{
|
9
|
+
Undirected,
|
10
|
+
Directed,
|
11
|
+
}
|
12
|
+
|
13
|
+
#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
|
14
|
+
pub struct Key
|
15
|
+
{
|
16
|
+
pub(crate) uuid: u128,
|
17
|
+
}
|
18
|
+
|
19
|
+
impl Serialize for Key
|
20
|
+
{
|
21
|
+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
22
|
+
where
|
23
|
+
S: serde::Serializer,
|
24
|
+
{
|
25
|
+
serializer.serialize_u128(self.uuid)
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
impl<'de> Deserialize<'de> for Key
|
30
|
+
{
|
31
|
+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
32
|
+
where
|
33
|
+
D: serde::Deserializer<'de>,
|
34
|
+
{
|
35
|
+
Ok(Self {
|
36
|
+
uuid: u128::deserialize(deserializer)?,
|
37
|
+
})
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
impl Default for Key
|
42
|
+
{
|
43
|
+
fn default() -> Self
|
44
|
+
{
|
45
|
+
Key {
|
46
|
+
uuid: uuid::Uuid::new_v4().as_u128(),
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
impl From<&Key> for u128
|
52
|
+
{
|
53
|
+
fn from(value: &Key) -> Self
|
54
|
+
{
|
55
|
+
value.uuid
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
impl From<Key> for u128
|
60
|
+
{
|
61
|
+
fn from(value: Key) -> Self
|
62
|
+
{
|
63
|
+
value.uuid
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
/// Represent a Node in the graph
|
68
|
+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone, Hash)]
|
69
|
+
#[serde(tag = "type", rename = "node")]
|
70
|
+
pub struct Node
|
71
|
+
{
|
72
|
+
/// uuid for the Node.
|
73
|
+
pub(crate) key: Key,
|
74
|
+
/// Vector of labels.
|
75
|
+
pub(crate) labels: Vec<String>,
|
76
|
+
/// Properties.
|
77
|
+
pub(crate) properties: value::ValueMap,
|
78
|
+
}
|
79
|
+
|
80
|
+
impl Node
|
81
|
+
{
|
82
|
+
/// uuid for the Node.
|
83
|
+
pub fn key(&self) -> Key
|
84
|
+
{
|
85
|
+
self.key
|
86
|
+
}
|
87
|
+
/// Vector of labels.
|
88
|
+
pub fn labels(&self) -> &Vec<String>
|
89
|
+
{
|
90
|
+
&self.labels
|
91
|
+
}
|
92
|
+
/// Properties.
|
93
|
+
pub fn properties(&self) -> &value::ValueMap
|
94
|
+
{
|
95
|
+
&self.properties
|
96
|
+
}
|
97
|
+
/// Unpack Node in key, labels and properties.
|
98
|
+
pub fn unpack(self) -> (Key, Vec<String>, value::ValueMap)
|
99
|
+
{
|
100
|
+
(self.key, self.labels, self.properties)
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
impl std::fmt::Display for Node
|
105
|
+
{
|
106
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
107
|
+
{
|
108
|
+
if self.labels.is_empty()
|
109
|
+
{
|
110
|
+
write!(f, "(")?;
|
111
|
+
}
|
112
|
+
else
|
113
|
+
{
|
114
|
+
write!(f, "(:{} ", self.labels.join(":"))?;
|
115
|
+
}
|
116
|
+
write!(f, "{}", self.properties.borrow())?;
|
117
|
+
write!(f, ")")
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
/// Directed edge of the graph.
|
122
|
+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone, Hash)]
|
123
|
+
#[serde(tag = "type", rename = "edge")]
|
124
|
+
pub struct Edge
|
125
|
+
{
|
126
|
+
/// uuid for the Edge.
|
127
|
+
pub(crate) key: Key,
|
128
|
+
#[serde(skip_serializing)]
|
129
|
+
/// source node for the Edge, this property is used internally by the engine, but is not exported in query results, and not part of the public API.
|
130
|
+
pub(crate) source: Node,
|
131
|
+
/// destination node for the Edge, this property is used internally by the engine, but is not exported in query results, and not part of the public API.
|
132
|
+
#[serde(skip_serializing)]
|
133
|
+
pub(crate) destination: Node,
|
134
|
+
/// Labels for the Edge.
|
135
|
+
pub(crate) labels: Vec<String>,
|
136
|
+
/// Properties for the Edge.
|
137
|
+
pub(crate) properties: value::ValueMap,
|
138
|
+
}
|
139
|
+
|
140
|
+
impl Edge
|
141
|
+
{
|
142
|
+
/// uuid for the Node.
|
143
|
+
pub fn key(&self) -> Key
|
144
|
+
{
|
145
|
+
self.key
|
146
|
+
}
|
147
|
+
/// Vector of labels.
|
148
|
+
pub fn labels(&self) -> &Vec<String>
|
149
|
+
{
|
150
|
+
&self.labels
|
151
|
+
}
|
152
|
+
/// Properties.
|
153
|
+
pub fn properties(&self) -> &value::ValueMap
|
154
|
+
{
|
155
|
+
&self.properties
|
156
|
+
}
|
157
|
+
/// Unpack Edge in key, labels and properties.
|
158
|
+
pub fn unpack(self) -> (Key, Vec<String>, value::ValueMap)
|
159
|
+
{
|
160
|
+
(self.key, self.labels, self.properties)
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
impl std::fmt::Display for Edge
|
165
|
+
{
|
166
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
167
|
+
{
|
168
|
+
write!(f, "[:{} ", self.labels.join(":"))?;
|
169
|
+
write!(f, "{}", self.properties.borrow())?;
|
170
|
+
write!(f, "])")
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
impl Into<Path> for Edge
|
175
|
+
{
|
176
|
+
fn into(self) -> Path
|
177
|
+
{
|
178
|
+
Path {
|
179
|
+
key: self.key,
|
180
|
+
source: self.source,
|
181
|
+
destination: self.destination,
|
182
|
+
labels: self.labels,
|
183
|
+
properties: self.properties,
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
/// Path in the graph.
|
189
|
+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone, Hash)]
|
190
|
+
#[serde(tag = "type", rename = "path")]
|
191
|
+
pub struct Path
|
192
|
+
{
|
193
|
+
/// uuid for the path.
|
194
|
+
pub(crate) key: Key,
|
195
|
+
/// source node for the path.
|
196
|
+
pub(crate) source: Node,
|
197
|
+
/// destination node for the path.
|
198
|
+
pub(crate) destination: Node,
|
199
|
+
/// Labels for the path.
|
200
|
+
pub(crate) labels: Vec<String>,
|
201
|
+
/// Properties for the path.
|
202
|
+
pub(crate) properties: value::ValueMap,
|
203
|
+
}
|
204
|
+
|
205
|
+
impl Path
|
206
|
+
{
|
207
|
+
/// uuid for the Node.
|
208
|
+
pub fn key(&self) -> Key
|
209
|
+
{
|
210
|
+
self.key
|
211
|
+
}
|
212
|
+
/// uuid for the Node.
|
213
|
+
pub fn source(&self) -> &Node
|
214
|
+
{
|
215
|
+
&self.source
|
216
|
+
}
|
217
|
+
/// uuid for the Node.
|
218
|
+
pub fn destination(&self) -> &Node
|
219
|
+
{
|
220
|
+
&self.destination
|
221
|
+
}
|
222
|
+
/// Vector of labels.
|
223
|
+
pub fn labels(&self) -> &Vec<String>
|
224
|
+
{
|
225
|
+
&self.labels
|
226
|
+
}
|
227
|
+
/// Properties.
|
228
|
+
pub fn properties(&self) -> &value::ValueMap
|
229
|
+
{
|
230
|
+
&self.properties
|
231
|
+
}
|
232
|
+
/// Unpack Node in key, labels and properties.
|
233
|
+
pub fn unpack(self) -> (Key, Node, Vec<String>, value::ValueMap, Node)
|
234
|
+
{
|
235
|
+
(
|
236
|
+
self.key,
|
237
|
+
self.source,
|
238
|
+
self.labels,
|
239
|
+
self.properties,
|
240
|
+
self.destination,
|
241
|
+
)
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
impl std::fmt::Display for Path
|
246
|
+
{
|
247
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
248
|
+
{
|
249
|
+
write!(f, "{}-[:{} ", self.source, self.labels.join(":"))?;
|
250
|
+
write!(f, "{}", self.properties.borrow())?;
|
251
|
+
write!(f, "])->{}", self.destination)
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
#[cfg(test)]
|
256
|
+
macro_rules! labels {
|
257
|
+
// match a list of expressions separated by comma:
|
258
|
+
($($str:expr),*) => (
|
259
|
+
{
|
260
|
+
// create a Vec with this list of expressions,
|
261
|
+
// calling String::from on each:
|
262
|
+
vec![$(String::from($str),)*] as Vec<String>
|
263
|
+
}
|
264
|
+
);
|
265
|
+
}
|
266
|
+
|
267
|
+
#[cfg(test)]
|
268
|
+
pub(crate) use labels;
|