gqlite 1.5.0 → 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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/ext/Cargo.toml +12 -6
  3. data/ext/db-index/Cargo.toml +29 -0
  4. data/ext/db-index/src/hnsw/error.rs +66 -0
  5. data/ext/db-index/src/hnsw/graph_store.rs +272 -0
  6. data/ext/db-index/src/hnsw/id.rs +36 -0
  7. data/ext/db-index/src/hnsw/implementation.rs +1517 -0
  8. data/ext/db-index/src/hnsw/kernels.rs +1228 -0
  9. data/ext/db-index/src/hnsw/metric.rs +244 -0
  10. data/ext/db-index/src/hnsw/scalar.rs +72 -0
  11. data/ext/db-index/src/hnsw/simple_store.rs +140 -0
  12. data/ext/db-index/src/hnsw/store.rs +472 -0
  13. data/ext/db-index/src/hnsw/vector.rs +105 -0
  14. data/ext/db-index/src/hnsw/vectors.rs +568 -0
  15. data/ext/db-index/src/hnsw.rs +42 -0
  16. data/ext/db-index/src/lib.rs +3 -0
  17. data/ext/gqlitedb/Cargo.toml +19 -8
  18. data/ext/gqlitedb/benches/common/pokec.rs +62 -2
  19. data/ext/gqlitedb/benches/pokec_divan.rs +66 -2
  20. data/ext/gqlitedb/benches/pokec_iai.rs +60 -3
  21. data/ext/gqlitedb/release.toml +2 -2
  22. data/ext/gqlitedb/src/aggregators/arithmetic.rs +3 -1
  23. data/ext/gqlitedb/src/aggregators/containers.rs +1 -1
  24. data/ext/gqlitedb/src/aggregators/stats.rs +21 -12
  25. data/ext/gqlitedb/src/capi.rs +20 -24
  26. data/ext/gqlitedb/src/compiler/expression_analyser.rs +28 -20
  27. data/ext/gqlitedb/src/compiler/variables_manager.rs +104 -38
  28. data/ext/gqlitedb/src/compiler.rs +506 -227
  29. data/ext/gqlitedb/src/connection.rs +151 -11
  30. data/ext/gqlitedb/src/consts.rs +1 -2
  31. data/ext/gqlitedb/src/error.rs +123 -61
  32. data/ext/gqlitedb/src/functions/common.rs +64 -0
  33. data/ext/gqlitedb/src/functions/containers.rs +2 -46
  34. data/ext/gqlitedb/src/functions/edge.rs +1 -1
  35. data/ext/gqlitedb/src/functions/math.rs +87 -15
  36. data/ext/gqlitedb/src/functions/node.rs +1 -1
  37. data/ext/gqlitedb/src/functions/path.rs +48 -11
  38. data/ext/gqlitedb/src/functions/scalar.rs +47 -4
  39. data/ext/gqlitedb/src/functions/string.rs +123 -1
  40. data/ext/gqlitedb/src/functions/value.rs +1 -1
  41. data/ext/gqlitedb/src/functions.rs +165 -28
  42. data/ext/gqlitedb/src/graph.rs +1 -9
  43. data/ext/gqlitedb/src/interpreter/evaluators.rs +968 -130
  44. data/ext/gqlitedb/src/interpreter/instructions.rs +39 -2
  45. data/ext/gqlitedb/src/lib.rs +5 -4
  46. data/ext/gqlitedb/src/parser/gql.pest +1 -1
  47. data/ext/gqlitedb/src/planner.rs +329 -0
  48. data/ext/gqlitedb/src/prelude.rs +3 -3
  49. data/ext/gqlitedb/src/store/pgrx.rs +1 -1
  50. data/ext/gqlitedb/src/store/postgres.rs +742 -16
  51. data/ext/gqlitedb/src/store/redb/hnsw_store.rs +702 -0
  52. data/ext/gqlitedb/src/store/redb/index.rs +274 -0
  53. data/ext/gqlitedb/src/store/redb.rs +1268 -113
  54. data/ext/gqlitedb/src/store/sqlbase/sqlmetadata.rs +28 -0
  55. data/ext/gqlitedb/src/store/sqlbase/sqlstore.rs +103 -0
  56. data/ext/gqlitedb/src/store/sqlbase.rs +146 -16
  57. data/ext/gqlitedb/src/store/sqlite.rs +576 -14
  58. data/ext/gqlitedb/src/store/vector_extract.rs +56 -0
  59. data/ext/gqlitedb/src/store.rs +140 -29
  60. data/ext/gqlitedb/src/tests/compiler.rs +207 -10
  61. data/ext/gqlitedb/src/tests/connection/postgres.rs +38 -3
  62. data/ext/gqlitedb/src/tests/connection/redb.rs +23 -0
  63. data/ext/gqlitedb/src/tests/connection/sqlite.rs +31 -0
  64. data/ext/gqlitedb/src/tests/connection.rs +61 -1
  65. data/ext/gqlitedb/src/tests/evaluators.rs +162 -7
  66. data/ext/gqlitedb/src/tests/parser.rs +54 -23
  67. data/ext/gqlitedb/src/tests/planner.rs +511 -0
  68. data/ext/gqlitedb/src/tests/store/postgres.rs +7 -0
  69. data/ext/gqlitedb/src/tests/store/redb.rs +8 -0
  70. data/ext/gqlitedb/src/tests/store/sqlite.rs +8 -0
  71. data/ext/gqlitedb/src/tests/store/vector_index/postgres.rs +182 -0
  72. data/ext/gqlitedb/src/tests/store/vector_index/redb.rs +386 -0
  73. data/ext/gqlitedb/src/tests/store/vector_index/sqlite.rs +166 -0
  74. data/ext/gqlitedb/src/tests/store/vector_index.rs +2313 -0
  75. data/ext/gqlitedb/src/tests/store.rs +78 -14
  76. data/ext/gqlitedb/src/tests/templates/ast.rs +92 -16
  77. data/ext/gqlitedb/src/tests/templates/programs.rs +14 -7
  78. data/ext/gqlitedb/src/tests.rs +15 -9
  79. data/ext/gqlitedb/src/utils.rs +6 -1
  80. data/ext/gqlitedb/src/value/compare.rs +61 -3
  81. data/ext/gqlitedb/src/value.rs +136 -7
  82. data/ext/gqlitedb/templates/sql/postgres/metadata_delete.sql +1 -0
  83. data/ext/gqlitedb/templates/sql/postgres/node_select.sql +1 -1
  84. data/ext/gqlitedb/templates/sql/sqlite/metadata_delete.sql +1 -0
  85. data/ext/gqliterb/src/lib.rs +53 -8
  86. data/ext/gqlparser/Cargo.toml +25 -0
  87. data/ext/gqlparser/README.MD +9 -0
  88. data/ext/gqlparser/benches/pokec_divan.rs +34 -0
  89. data/ext/gqlparser/src/common.rs +69 -0
  90. data/ext/gqlparser/src/gqls/ast.rs +69 -0
  91. data/ext/gqlparser/src/gqls/constraint.rs +79 -0
  92. data/ext/gqlparser/src/gqls/error.rs +22 -0
  93. data/ext/gqlparser/src/gqls/parser.rs +813 -0
  94. data/ext/gqlparser/src/gqls/prelude.rs +8 -0
  95. data/ext/gqlparser/src/gqls/properties.rs +115 -0
  96. data/ext/gqlparser/src/gqls/resolve.rs +207 -0
  97. data/ext/gqlparser/src/gqls.rs +265 -0
  98. data/ext/gqlparser/src/lib.rs +7 -0
  99. data/ext/gqlparser/src/oc/ast.rs +680 -0
  100. data/ext/gqlparser/src/oc/error.rs +172 -0
  101. data/ext/gqlparser/src/oc/lexer.rs +429 -0
  102. data/ext/gqlparser/src/oc/parser/tests.rs +2284 -0
  103. data/ext/gqlparser/src/oc/parser.rs +2005 -0
  104. data/ext/gqlparser/src/oc.rs +33 -0
  105. data/ext/gqlparser/src/prelude.rs +3 -0
  106. data/ext/graphcore/Cargo.toml +1 -0
  107. data/ext/graphcore/src/error.rs +26 -0
  108. data/ext/graphcore/src/graph.rs +177 -51
  109. data/ext/graphcore/src/lib.rs +4 -2
  110. data/ext/graphcore/src/open_cypher.rs +12 -0
  111. data/ext/graphcore/src/table.rs +50 -2
  112. data/ext/graphcore/src/timestamp.rs +127 -104
  113. data/ext/graphcore/src/value/tensor.rs +739 -0
  114. data/ext/graphcore/src/value/value_map.rs +1 -1
  115. data/ext/graphcore/src/value.rs +343 -19
  116. metadata +93 -28
  117. data/ext/gqlitedb/src/parser/ast.rs +0 -604
  118. data/ext/gqlitedb/src/parser/parser_impl.rs +0 -1213
  119. data/ext/gqlitedb/src/parser.rs +0 -4
@@ -1,5 +1,6 @@
1
1
  use std::{collections::HashMap, fmt::Debug, sync::Arc};
2
2
 
3
+ mod common;
3
4
  mod containers;
4
5
  mod edge;
5
6
  mod math;
@@ -140,24 +141,48 @@ impl Manager
140
141
  Self {
141
142
  inner: ManagerInner {
142
143
  functions: HashMap::from([
144
+ common::Size::create(),
143
145
  containers::Head::create(),
144
146
  containers::Keys::create(),
145
147
  containers::Range::create(),
146
- containers::Size::create(),
147
148
  edge::Type::create(),
149
+ math::Acos::create(),
150
+ math::Asin::create(),
151
+ math::Atan::create(),
152
+ math::Atan2::create(),
148
153
  math::Ceil::create(),
154
+ math::Cos::create(),
155
+ math::Cot::create(),
156
+ math::Degrees::create(),
157
+ math::E::create(),
158
+ math::Exp::create(),
149
159
  math::Floor::create(),
160
+ math::Log::create(),
161
+ math::Log10::create(),
162
+ math::Pi::create(),
163
+ math::Radians::create(),
150
164
  math::Rand::create(),
165
+ math::Sin::create(),
166
+ math::Tan::create(),
151
167
  node::Labels::create(),
152
168
  path::Length::create(),
153
169
  path::Nodes::create(),
154
170
  path::Edges::create(),
171
+ scalar::Abs::create(),
155
172
  scalar::Coalesce::create(),
156
173
  scalar::Id::create(),
157
174
  scalar::Properties::create(),
158
175
  scalar::ToBoolean::create(),
159
176
  scalar::ToFloat::create(),
160
177
  scalar::ToInteger::create(),
178
+ string::LTrim::create(),
179
+ string::RTrim::create(),
180
+ string::Trim::create(),
181
+ string::ToLower::create(),
182
+ string::ToUpper::create(),
183
+ string::Reverse::create(),
184
+ string::Split::create(),
185
+ string::Substring::create(),
161
186
  string::ToString::create(),
162
187
  value::HasLabel::create(),
163
188
  value::HasLabels::create(),
@@ -194,6 +219,8 @@ impl Manager
194
219
  .clone(),
195
220
  )
196
221
  }
222
+ // It has future use in the compiler to optimize constant expressions
223
+ #[allow(dead_code)]
197
224
  pub(crate) fn is_deterministic(&self, name: impl Into<String>) -> Result<bool>
198
225
  {
199
226
  let name = name.into();
@@ -264,6 +291,14 @@ macro_rules! make_function_call {
264
291
  $crate::functions::make_function_argument!($function_name, arguments_iter, 1, $arg_type_1),
265
292
  )
266
293
  }};
294
+ ($function_name: ident, $function: expr, $arguments: ident, $arg_type_0: ty, $arg_type_1: ty, $arg_type_2: ty, ) => {{
295
+ let mut arguments_iter = $arguments.into_iter();
296
+ $function(
297
+ $crate::functions::make_function_argument!($function_name, arguments_iter, 0, $arg_type_0),
298
+ $crate::functions::make_function_argument!($function_name, arguments_iter, 1, $arg_type_1),
299
+ $crate::functions::make_function_argument!($function_name, arguments_iter, 2, $arg_type_2),
300
+ )
301
+ }};
267
302
  ($function_name: ident, $function: expr, $arguments: ident, ) => {
268
303
  $function()
269
304
  };
@@ -308,34 +343,43 @@ macro_rules! default_validate_ {
308
343
 
309
344
  #[rustfmt::skip]
310
345
  macro_rules! validate_args_ {
311
- ($function_name: ident, $ret_type: ty, $( $expression_type: pat ),* ) => {
346
+ ($function_name: ident, $min_arg_count: expr, $ret_type: ty, $( $expression_type: pat ),* ) => {
312
347
  |args: Vec<$crate::compiler::expression_analyser::ExpressionType>|
313
348
  -> crate::Result<$crate::compiler::expression_analyser::ExpressionType>
314
349
  {
315
- const ARG_COUNT: usize = $crate::functions::count_patterns!($( $expression_type,)*);
316
- if args.len() != ARG_COUNT
350
+ const MAX_ARG_COUNT: usize = $crate::functions::count_patterns!($( $expression_type,)*);
351
+ if args.len() > MAX_ARG_COUNT && args.len() < $min_arg_count
317
352
  {
318
353
  Err(crate::error::CompileTimeError::InvalidNumberOfArguments {
319
354
  function_name: stringify!($function_name),
320
355
  got: args.len(),
321
- expected: ARG_COUNT
356
+ expected: $min_arg_count
322
357
  })?;
323
358
  }
324
359
  let mut it = args.into_iter();
325
360
  $(
326
- match it.next().unwrap()
361
+ if let Some(val) = it.next()
327
362
  {
328
- $expression_type | ExpressionType::Variant =>
329
- Ok(<$ret_type>::result_type()),
330
- _ => Err(crate::error::CompileTimeError::InvalidArgumentType.into())
363
+ match val
364
+ {
365
+ $expression_type | ExpressionType::Variant => {}
366
+ _ => return Err(crate::error::CompileTimeError::InvalidArgumentType.into())
367
+ }
331
368
  }
332
369
  )*
370
+ Ok(<$ret_type>::result_type())
371
+ }
372
+ };
373
+ ($function_name: ident, $ret_type: ty, $( $expression_type: pat ),* ) => {
374
+ {
375
+ const MIN_ARG_COUNT: usize = $crate::functions::count_patterns!($( $expression_type,)*);
376
+ $crate::functions::validate_args_!($function_name, MIN_ARG_COUNT, $ret_type, $( $expression_type ),* )
333
377
  }
334
378
  };
335
379
  }
336
380
 
337
381
  macro_rules! declare_function_ {
338
- ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, $allow_null: expr, $validator: block ) => {
382
+ ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, $null_handling: block, $validator: block , $default_args: block, $deterministic: expr ) => {
339
383
  impl $type_name
340
384
  {
341
385
  pub(super) fn create() -> (String, crate::functions::Function)
@@ -348,12 +392,13 @@ macro_rules! declare_function_ {
348
392
  }
349
393
  impl crate::functions::FunctionTrait for $type_name
350
394
  {
351
- fn call(&self, arguments: Vec<crate::value::Value>) -> crate::Result<crate::value::Value>
395
+ fn call(&self, mut arguments: Vec<crate::value::Value>) -> crate::Result<crate::value::Value>
352
396
  {
353
397
  const ARG_COUNT: usize = $crate::functions::count_arguments!($( $arg_type,)*);
398
+ ($default_args)(&mut arguments);
354
399
  if arguments.len() == ARG_COUNT
355
400
  {
356
- if !$allow_null && ARG_COUNT > 0 && arguments.iter().all(|x| x.is_null())
401
+ if $null_handling(&arguments)
357
402
  {
358
403
  return Ok(crate::value::Value::Null)
359
404
  }
@@ -379,27 +424,122 @@ macro_rules! declare_function_ {
379
424
  }
380
425
  fn is_deterministic(&self) -> bool
381
426
  {
382
- true
427
+ $deterministic
383
428
  }
384
429
  }
385
430
  };
386
431
  }
387
432
 
433
+ macro_rules! no_null_handling_ {
434
+ () => {
435
+ |_args: &Vec<graphcore::Value>| false
436
+ };
437
+ }
438
+
439
+ macro_rules! null_handling_once_ {
440
+ (null_returns_null, $iter: expr) => {
441
+ if $iter.next().map_or(true, |x| x.is_null())
442
+ {
443
+ return true;
444
+ }
445
+ };
446
+ (ignore, $iter: expr) => {
447
+ let _ = $iter.next();
448
+ };
449
+ }
450
+
451
+ macro_rules! null_handling_ {
452
+ ( $( $null_mode: ident ),+ ) => {
453
+ |args: &Vec<graphcore::Value>| -> bool {
454
+ let mut iter = args.iter();
455
+ $( crate::functions::null_handling_once_!($null_mode, iter); )+
456
+ false
457
+ }
458
+ }
459
+ }
460
+
461
+ macro_rules! no_default_args_ {
462
+ () => {
463
+ |_args: &mut Vec<graphcore::Value>| {}
464
+ };
465
+ }
466
+
467
+ macro_rules! default_args_ {
468
+ ( $required: expr, $( $default_arg: expr ),+ ) => {
469
+ |args: &mut Vec<graphcore::Value>| {
470
+ if args.len() < $required
471
+ {
472
+ return;
473
+ }
474
+ let mut current_idx = $required;
475
+ $(
476
+ if current_idx >= args.len()
477
+ {
478
+ args.push(($default_arg).into());
479
+ }
480
+ #[allow(unused_assignments)]
481
+ {
482
+ current_idx += 1;
483
+ }
484
+ )+
485
+ }
486
+ }
487
+ }
488
+
388
489
  macro_rules! declare_function {
389
490
  ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty ) => {
390
491
  $crate::functions::declare_function_!($function_name, $type_name,
391
- $f_name ( $( $arg_type, )* ) -> $ret_type, false,
392
- {$crate::functions::default_validate_!($function_name, $ret_type)} );
492
+ $f_name ( $( $arg_type, )* ) -> $ret_type,
493
+ {$crate::functions::no_null_handling_!()},
494
+ {$crate::functions::default_validate_!($function_name, $ret_type)},
495
+ {$crate::functions::no_default_args_!()},
496
+ true
497
+ );
393
498
  };
394
- ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, accept_null ) => {
499
+ ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, non_deterministic ) => {
395
500
  $crate::functions::declare_function_!($function_name, $type_name,
396
- $f_name ( $( $arg_type, )* ) -> $ret_type, true,
397
- {$crate::functions::default_validate_!($function_name, $ret_type)} );
501
+ $f_name ( $( $arg_type, )* ) -> $ret_type,
502
+ {$crate::functions::no_null_handling_!()},
503
+ {$crate::functions::default_validate_!($function_name, $ret_type)},
504
+ {$crate::functions::no_default_args_!()},
505
+ false
506
+ );
507
+ };
508
+ ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, null_handling( $( $null_mode: ident ),+ ) ) => {
509
+ $crate::functions::declare_function_!($function_name, $type_name,
510
+ $f_name ( $( $arg_type, )* ) -> $ret_type,
511
+ {$crate::functions::null_handling_!($($null_mode),+)},
512
+ {$crate::functions::default_validate_!($function_name, $ret_type)},
513
+ {$crate::functions::no_default_args_!()},
514
+ true
515
+ );
398
516
  };
399
517
  ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, validate_args( $( $expression_types: pat ),+ ) ) => {
400
518
  $crate::functions::declare_function_!($function_name, $type_name,
401
- $f_name ( $( $arg_type, )* ) -> $ret_type, false,
402
- {$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )} );
519
+ $f_name ( $( $arg_type, )* ) -> $ret_type,
520
+ {$crate::functions::no_null_handling_!()},
521
+ {$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )},
522
+ {$crate::functions::no_default_args_!()},
523
+ true
524
+ );
525
+ };
526
+ ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, null_handling( $( $null_mode: ident ),+ ), validate_args( $( $expression_types: pat ),+ ) ) => {
527
+ $crate::functions::declare_function_!($function_name, $type_name,
528
+ $f_name ( $( $arg_type, )* ) -> $ret_type,
529
+ {$crate::functions::null_handling_!($($null_mode),+)},
530
+ {$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )},
531
+ {$crate::functions::no_default_args_!()},
532
+ true
533
+ );
534
+ };
535
+ ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, null_handling( $( $null_mode: ident ),+ ), validate_args( $( $expression_types: pat ),+ ), default_args( $required: expr, $( $default_args: expr ),+ ) ) => {
536
+ $crate::functions::declare_function_!($function_name, $type_name,
537
+ $f_name ( $( $arg_type, )* ) -> $ret_type,
538
+ {$crate::functions::null_handling_!($($null_mode),+)},
539
+ {$crate::functions::validate_args_!($function_name, $required, $ret_type, $( $expression_types ),+ )},
540
+ {$crate::functions::default_args_!( $required, $($default_args),+)},
541
+ true
542
+ );
403
543
  };
404
544
  ($function_name: ident, $type_name: ty, custom_trait ) => {
405
545
  impl $type_name
@@ -415,11 +555,8 @@ macro_rules! declare_function {
415
555
  };
416
556
  }
417
557
 
418
- pub(crate) use count_arguments;
419
- pub(crate) use count_patterns;
420
- pub(crate) use declare_function;
421
- pub(crate) use declare_function_;
422
- pub(crate) use default_validate_;
423
- pub(crate) use make_function_argument;
424
- pub(crate) use make_function_call;
425
- pub(crate) use validate_args_;
558
+ pub(crate) use {
559
+ count_arguments, count_patterns, declare_function, declare_function_, default_args_,
560
+ default_validate_, make_function_argument, make_function_call, no_default_args_,
561
+ no_null_handling_, null_handling_, null_handling_once_, validate_args_,
562
+ };
@@ -1,11 +1,3 @@
1
- pub(crate) use graphcore::SinglePath;
2
- pub use graphcore::{Edge, Key, Node, SinglePath as Path};
1
+ pub use graphcore::{Edge, Key, Node, Path, SinglePath};
3
2
 
4
3
  pub use graphcore::labels;
5
-
6
- #[derive(Debug, Clone, Copy)]
7
- pub(crate) enum EdgeDirectivity
8
- {
9
- Undirected,
10
- Directed,
11
- }