gqlite 1.5.1 → 1.8.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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/ext/Cargo.toml +10 -4
  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 -9
  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 +1 -1
  26. data/ext/gqlitedb/src/compiler/expression_analyser.rs +28 -20
  27. data/ext/gqlitedb/src/compiler/variables_manager.rs +97 -29
  28. data/ext/gqlitedb/src/compiler.rs +505 -225
  29. data/ext/gqlitedb/src/connection.rs +149 -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 +39 -2
  33. data/ext/gqlitedb/src/functions/math.rs +8 -3
  34. data/ext/gqlitedb/src/functions/path.rs +48 -11
  35. data/ext/gqlitedb/src/functions/value.rs +1 -1
  36. data/ext/gqlitedb/src/functions.rs +23 -7
  37. data/ext/gqlitedb/src/graph.rs +1 -9
  38. data/ext/gqlitedb/src/interpreter/evaluators.rs +968 -130
  39. data/ext/gqlitedb/src/interpreter/instructions.rs +39 -2
  40. data/ext/gqlitedb/src/lib.rs +5 -4
  41. data/ext/gqlitedb/src/planner.rs +329 -0
  42. data/ext/gqlitedb/src/prelude.rs +3 -3
  43. data/ext/gqlitedb/src/store/pgrx.rs +1 -1
  44. data/ext/gqlitedb/src/store/postgres.rs +735 -7
  45. data/ext/gqlitedb/src/store/redb/hnsw_store.rs +702 -0
  46. data/ext/gqlitedb/src/store/redb/index.rs +274 -0
  47. data/ext/gqlitedb/src/store/redb.rs +1268 -113
  48. data/ext/gqlitedb/src/store/sqlbase/sqlmetadata.rs +28 -0
  49. data/ext/gqlitedb/src/store/sqlbase/sqlstore.rs +103 -0
  50. data/ext/gqlitedb/src/store/sqlbase.rs +146 -16
  51. data/ext/gqlitedb/src/store/sqlite.rs +569 -5
  52. data/ext/gqlitedb/src/store/vector_extract.rs +56 -0
  53. data/ext/gqlitedb/src/store.rs +123 -3
  54. data/ext/gqlitedb/src/tests/compiler.rs +207 -10
  55. data/ext/gqlitedb/src/tests/connection/postgres.rs +38 -3
  56. data/ext/gqlitedb/src/tests/connection/redb.rs +23 -0
  57. data/ext/gqlitedb/src/tests/connection/sqlite.rs +31 -0
  58. data/ext/gqlitedb/src/tests/connection.rs +61 -1
  59. data/ext/gqlitedb/src/tests/evaluators.rs +162 -7
  60. data/ext/gqlitedb/src/tests/parser.rs +54 -23
  61. data/ext/gqlitedb/src/tests/planner.rs +511 -0
  62. data/ext/gqlitedb/src/tests/store/postgres.rs +7 -0
  63. data/ext/gqlitedb/src/tests/store/redb.rs +8 -0
  64. data/ext/gqlitedb/src/tests/store/sqlite.rs +8 -0
  65. data/ext/gqlitedb/src/tests/store/vector_index/postgres.rs +182 -0
  66. data/ext/gqlitedb/src/tests/store/vector_index/redb.rs +386 -0
  67. data/ext/gqlitedb/src/tests/store/vector_index/sqlite.rs +166 -0
  68. data/ext/gqlitedb/src/tests/store/vector_index.rs +2313 -0
  69. data/ext/gqlitedb/src/tests/store.rs +78 -14
  70. data/ext/gqlitedb/src/tests/templates/ast.rs +92 -16
  71. data/ext/gqlitedb/src/tests/templates/programs.rs +14 -7
  72. data/ext/gqlitedb/src/tests.rs +15 -9
  73. data/ext/gqlitedb/src/utils.rs +6 -1
  74. data/ext/gqlitedb/src/value/compare.rs +61 -3
  75. data/ext/gqlitedb/src/value.rs +136 -7
  76. data/ext/gqlitedb/templates/sql/postgres/metadata_delete.sql +1 -0
  77. data/ext/gqlitedb/templates/sql/postgres/node_select.sql +1 -1
  78. data/ext/gqlitedb/templates/sql/sqlite/metadata_delete.sql +1 -0
  79. data/ext/gqliterb/src/lib.rs +53 -8
  80. data/ext/gqlparser/Cargo.toml +25 -0
  81. data/ext/gqlparser/README.MD +9 -0
  82. data/ext/gqlparser/benches/pokec_divan.rs +34 -0
  83. data/ext/gqlparser/src/common.rs +69 -0
  84. data/ext/gqlparser/src/gqls/ast.rs +69 -0
  85. data/ext/gqlparser/src/gqls/constraint.rs +79 -0
  86. data/ext/gqlparser/src/gqls/error.rs +22 -0
  87. data/ext/gqlparser/src/gqls/parser.rs +813 -0
  88. data/ext/gqlparser/src/gqls/prelude.rs +8 -0
  89. data/ext/gqlparser/src/gqls/properties.rs +115 -0
  90. data/ext/gqlparser/src/gqls/resolve.rs +207 -0
  91. data/ext/gqlparser/src/gqls.rs +265 -0
  92. data/ext/gqlparser/src/lib.rs +7 -0
  93. data/ext/gqlparser/src/oc/ast.rs +680 -0
  94. data/ext/gqlparser/src/oc/error.rs +172 -0
  95. data/ext/gqlparser/src/oc/lexer.rs +429 -0
  96. data/ext/gqlparser/src/oc/parser/tests.rs +2284 -0
  97. data/ext/gqlparser/src/oc/parser.rs +2005 -0
  98. data/ext/gqlparser/src/oc.rs +33 -0
  99. data/ext/gqlparser/src/prelude.rs +3 -0
  100. data/ext/graphcore/Cargo.toml +1 -0
  101. data/ext/graphcore/src/error.rs +26 -0
  102. data/ext/graphcore/src/graph.rs +177 -51
  103. data/ext/graphcore/src/lib.rs +4 -2
  104. data/ext/graphcore/src/open_cypher.rs +12 -0
  105. data/ext/graphcore/src/table.rs +50 -2
  106. data/ext/graphcore/src/timestamp.rs +127 -104
  107. data/ext/graphcore/src/value/tensor.rs +739 -0
  108. data/ext/graphcore/src/value/value_map.rs +1 -1
  109. data/ext/graphcore/src/value.rs +343 -19
  110. metadata +90 -22
  111. data/ext/gqlitedb/src/parser/ast.rs +0 -604
  112. data/ext/gqlitedb/src/parser/parser_impl.rs +0 -1213
  113. data/ext/gqlitedb/src/parser.rs +0 -4
@@ -20,7 +20,8 @@ impl super::FunctionTrait for Length
20
20
  {
21
21
  value::Value::Array(arr) => Ok((arr.len() as i64).into()),
22
22
  value::Value::Map(obj) => Ok((obj.len() as i64).into()),
23
- value::Value::Path(..) => Ok(1.into()),
23
+ value::Value::SinglePath(_) => Ok((1_i64).into()),
24
+ value::Value::Path(path) => Ok((path.elements_count() as i64).into()),
24
25
  _ => Err(
25
26
  RunTimeError::InvalidArgument {
26
27
  function_name: "length",
@@ -49,27 +50,63 @@ pub(super) struct Nodes {}
49
50
 
50
51
  impl Nodes
51
52
  {
52
- fn call_impl(path: graph::Path) -> FResult<Vec<graph::Node>>
53
+ fn call_impl(path: value::Value) -> FResult<Vec<graph::Node>>
53
54
  {
54
- Ok(vec![path.source().clone(), path.destination().clone()])
55
+ match path
56
+ {
57
+ value::Value::SinglePath(p) =>
58
+ {
59
+ let (node, _, destination) = p.unpack();
60
+ Ok(vec![node, destination])
61
+ }
62
+ value::Value::Path(p) =>
63
+ {
64
+ let (source, elements) = p.unpack();
65
+ Ok(
66
+ std::iter::once(source)
67
+ .chain(elements.into_iter().map(|(_, node)| node))
68
+ .collect(),
69
+ )
70
+ }
71
+ o => Err(RunTimeError::InvalidArgument {
72
+ function_name: "nodes",
73
+ index: 0,
74
+ expected_type: "path",
75
+ value: format!("{:?}", o),
76
+ }),
77
+ }
55
78
  }
56
79
  }
57
80
 
58
- super::declare_function!(nodes, Nodes, call_impl(crate::graph::Path) -> Vec<graph::Node>);
81
+ super::declare_function!(nodes, Nodes, call_impl(value::Value) -> Vec<graph::Node>);
59
82
 
60
83
  #[derive(Debug, Default)]
61
84
  pub(super) struct Edges {}
62
85
 
63
86
  impl Edges
64
87
  {
65
- fn call_impl(path: graph::Path) -> FResult<Vec<graph::Edge>>
88
+ fn call_impl(path: value::Value) -> FResult<Vec<graph::Edge>>
66
89
  {
67
- Ok(vec![graph::Edge::new(
68
- path.key(),
69
- path.labels().clone(),
70
- path.properties().clone(),
71
- )])
90
+ match path
91
+ {
92
+ value::Value::SinglePath(p) =>
93
+ {
94
+ let (_, edge, _) = p.unpack();
95
+ Ok(vec![edge])
96
+ }
97
+ value::Value::Path(p) =>
98
+ {
99
+ let (_, elements) = p.unpack();
100
+ Ok(elements.into_iter().map(|(edge, _)| edge).collect())
101
+ }
102
+ o => Err(RunTimeError::InvalidArgument {
103
+ function_name: "edges",
104
+ index: 0,
105
+ expected_type: "path",
106
+ value: format!("{:?}", o),
107
+ }),
108
+ }
72
109
  }
73
110
  }
74
111
 
75
- super::declare_function!(edges, Edges, call_impl(crate::graph::Path) -> Vec<graph::Edge>);
112
+ super::declare_function!(edges, Edges, call_impl(value::Value) -> Vec<graph::Edge>);
@@ -79,7 +79,7 @@ impl super::FunctionTrait for HasLabels
79
79
  value: format!("{:?}", label),
80
80
  }
81
81
  .into(),
82
- )
82
+ );
83
83
  }
84
84
  }
85
85
  }
@@ -219,6 +219,8 @@ impl Manager
219
219
  .clone(),
220
220
  )
221
221
  }
222
+ // It has future use in the compiler to optimize constant expressions
223
+ #[allow(dead_code)]
222
224
  pub(crate) fn is_deterministic(&self, name: impl Into<String>) -> Result<bool>
223
225
  {
224
226
  let name = name.into();
@@ -377,7 +379,7 @@ macro_rules! validate_args_ {
377
379
  }
378
380
 
379
381
  macro_rules! declare_function_ {
380
- ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, $null_handling: block, $validator: block , $default_args: 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 ) => {
381
383
  impl $type_name
382
384
  {
383
385
  pub(super) fn create() -> (String, crate::functions::Function)
@@ -422,7 +424,7 @@ macro_rules! declare_function_ {
422
424
  }
423
425
  fn is_deterministic(&self) -> bool
424
426
  {
425
- true
427
+ $deterministic
426
428
  }
427
429
  }
428
430
  };
@@ -490,7 +492,17 @@ macro_rules! declare_function {
490
492
  $f_name ( $( $arg_type, )* ) -> $ret_type,
491
493
  {$crate::functions::no_null_handling_!()},
492
494
  {$crate::functions::default_validate_!($function_name, $ret_type)},
493
- {$crate::functions::no_default_args_!()}
495
+ {$crate::functions::no_default_args_!()},
496
+ true
497
+ );
498
+ };
499
+ ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, non_deterministic ) => {
500
+ $crate::functions::declare_function_!($function_name, $type_name,
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
494
506
  );
495
507
  };
496
508
  ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, null_handling( $( $null_mode: ident ),+ ) ) => {
@@ -498,7 +510,8 @@ macro_rules! declare_function {
498
510
  $f_name ( $( $arg_type, )* ) -> $ret_type,
499
511
  {$crate::functions::null_handling_!($($null_mode),+)},
500
512
  {$crate::functions::default_validate_!($function_name, $ret_type)},
501
- {$crate::functions::no_default_args_!()}
513
+ {$crate::functions::no_default_args_!()},
514
+ true
502
515
  );
503
516
  };
504
517
  ($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, validate_args( $( $expression_types: pat ),+ ) ) => {
@@ -506,7 +519,8 @@ macro_rules! declare_function {
506
519
  $f_name ( $( $arg_type, )* ) -> $ret_type,
507
520
  {$crate::functions::no_null_handling_!()},
508
521
  {$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )},
509
- {$crate::functions::no_default_args_!()}
522
+ {$crate::functions::no_default_args_!()},
523
+ true
510
524
  );
511
525
  };
512
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 ),+ ) ) => {
@@ -514,7 +528,8 @@ macro_rules! declare_function {
514
528
  $f_name ( $( $arg_type, )* ) -> $ret_type,
515
529
  {$crate::functions::null_handling_!($($null_mode),+)},
516
530
  {$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )},
517
- {$crate::functions::no_default_args_!()}
531
+ {$crate::functions::no_default_args_!()},
532
+ true
518
533
  );
519
534
  };
520
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 ),+ ) ) => {
@@ -522,7 +537,8 @@ macro_rules! declare_function {
522
537
  $f_name ( $( $arg_type, )* ) -> $ret_type,
523
538
  {$crate::functions::null_handling_!($($null_mode),+)},
524
539
  {$crate::functions::validate_args_!($function_name, $required, $ret_type, $( $expression_types ),+ )},
525
- {$crate::functions::default_args_!( $required, $($default_args),+)}
540
+ {$crate::functions::default_args_!( $required, $($default_args),+)},
541
+ true
526
542
  );
527
543
  };
528
544
  ($function_name: ident, $type_name: ty, custom_trait ) => {
@@ -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
- }