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,13 +1,14 @@
1
1
  use std::collections::HashMap;
2
2
 
3
- use crate::prelude::*;
3
+ use gqlparser::oc::ast;
4
+
5
+ use crate::{planner::LogicalPlan, prelude::*};
4
6
 
5
7
  use compiler::expression_analyser::{self, ExpressionType};
6
- use parser::ast;
7
8
 
8
9
  fn unknown_variable_error(name: &ast::VariableIdentifier) -> ErrorType
9
10
  {
10
- InternalError::UnknownVariable {
11
+ CompileTimeError::UndefinedVariable {
11
12
  name: name.name().clone(),
12
13
  }
13
14
  .into()
@@ -77,7 +78,8 @@ impl Variable
77
78
  labels: ast::LabelExpression::None,
78
79
  properties: None,
79
80
  },
80
- directivity: crate::graph::EdgeDirectivity::Directed,
81
+ directivity: graphcore::EdgeDirectivity::Directed,
82
+ recursive_range: None,
81
83
  }),
82
84
  variable_type: ExpressionType::Edge,
83
85
  col_id,
@@ -253,7 +255,7 @@ impl VariablesManager
253
255
  }
254
256
  }
255
257
  _ => Err(
256
- InternalError::ExpectedNode {
258
+ CompileTimeError::ExpectedNode {
257
259
  context: "validate_node",
258
260
  }
259
261
  .into(),
@@ -358,7 +360,7 @@ impl VariablesManager
358
360
  }
359
361
  }
360
362
  _ => Err(
361
- InternalError::ExpectedNode {
363
+ CompileTimeError::ExpectedNode {
362
364
  context: "is_valid_existing_node",
363
365
  }
364
366
  .into(),
@@ -413,7 +415,7 @@ impl VariablesManager
413
415
  }
414
416
  }
415
417
  _ => Err(
416
- InternalError::ExpectedEdge {
418
+ CompileTimeError::ExpectedEdge {
417
419
  context: "is_valid_existing_edge",
418
420
  }
419
421
  .into(),
@@ -459,7 +461,7 @@ impl VariablesManager
459
461
  fn analyse_edge_path(
460
462
  &mut self,
461
463
  path_variable: Option<ast::VariableIdentifier>,
462
- edge: &crate::parser::ast::EdgePattern,
464
+ edge: &gqlparser::oc::ast::EdgePattern,
463
465
  is_create: bool,
464
466
  ) -> Result<()>
465
467
  {
@@ -538,7 +540,7 @@ impl VariablesManager
538
540
  self.variables = new_variables;
539
541
  Ok(())
540
542
  }
541
- pub(crate) fn analyse(&mut self, statement: &ast::Statement) -> Result<()>
543
+ pub(crate) fn analyse(&mut self, logical_plan: &LogicalPlan) -> Result<()>
542
544
  {
543
545
  if self.variables.iter().any(|(_, var)| !var.is_set)
544
546
  {
@@ -559,58 +561,122 @@ impl VariablesManager
559
561
  .into(),
560
562
  );
561
563
  }
562
- match statement
564
+ match logical_plan
563
565
  {
564
- ast::Statement::CreateGraph(..) =>
566
+ LogicalPlan::CreateGraph { .. } =>
565
567
  {}
566
- ast::Statement::DropGraph(..) =>
568
+ LogicalPlan::DropGraph { .. } =>
567
569
  {}
568
- ast::Statement::UseGraph(..) =>
570
+ LogicalPlan::UseGraph { .. } =>
569
571
  {}
570
- ast::Statement::Create(create) =>
572
+ LogicalPlan::Create { patterns } =>
571
573
  {
572
- for pattern in create.patterns.iter()
574
+ for pattern in patterns.iter()
573
575
  {
574
576
  if let ast::Pattern::Node(n) = &pattern
577
+ && self.has_variable(&n.variable)
575
578
  {
576
- if self.has_variable(&n.variable)
577
- {
578
- return Err(
579
- CompileTimeError::VariableAlreadyBound {
580
- name: n.variable.clone().unwrap().name().clone(),
581
- }
582
- .into(),
583
- );
584
- }
579
+ return Err(
580
+ CompileTimeError::VariableAlreadyBound {
581
+ name: n.variable.clone().unwrap().name().clone(),
582
+ }
583
+ .into(),
584
+ );
585
585
  }
586
586
  self.analyse_pattern(pattern, true)?;
587
587
  }
588
588
  }
589
- ast::Statement::Match(match_statement) =>
589
+ LogicalPlan::NodeScan { patterns, .. } =>
590
590
  {
591
- for pattern in match_statement.patterns.iter()
591
+ for pattern in patterns.iter()
592
592
  {
593
593
  self.analyse_pattern(pattern, false)?;
594
594
  }
595
595
  }
596
- ast::Statement::Return(..) =>
597
- {}
598
- ast::Statement::Call(..) =>
596
+ LogicalPlan::Filter { source, .. }
597
+ | LogicalPlan::Sort { source, .. }
598
+ | LogicalPlan::Skip { source, .. }
599
+ | LogicalPlan::Limit { source, .. } => self.analyse(source.as_ref())?,
600
+ LogicalPlan::Projection { .. } =>
599
601
  {}
600
- ast::Statement::With(..) =>
602
+ LogicalPlan::Call { .. } =>
601
603
  {}
602
- ast::Statement::Unwind(unwind) =>
604
+ LogicalPlan::Unwind { identifier, .. } =>
603
605
  {
604
- self.declare_variable(
605
- &unwind.identifier.to_owned(),
606
- expression_analyser::ExpressionType::Variant,
607
- )?;
608
- self.mark_variables_as_set(&unwind.identifier)?;
606
+ self.declare_variable(identifier, expression_analyser::ExpressionType::Variant)?;
607
+ self.mark_variables_as_set(identifier)?;
609
608
  }
610
- ast::Statement::Delete(..) =>
609
+ LogicalPlan::Delete { .. } =>
611
610
  {}
612
- ast::Statement::Update(..) =>
611
+ LogicalPlan::Update { .. } =>
613
612
  {}
613
+ LogicalPlan::Merge { patterns, .. } =>
614
+ {
615
+ for pattern in patterns.iter()
616
+ {
617
+ match pattern
618
+ {
619
+ ast::Pattern::Node(n) =>
620
+ {
621
+ if self.has_variable(&n.variable)
622
+ {
623
+ return Err(
624
+ CompileTimeError::VariableAlreadyBound {
625
+ name: n.variable.as_ref().unwrap().name().clone(),
626
+ }
627
+ .into(),
628
+ );
629
+ }
630
+ }
631
+ ast::Pattern::Edge(e) =>
632
+ {
633
+ if self.has_variable(&e.variable)
634
+ {
635
+ return Err(
636
+ CompileTimeError::VariableAlreadyBound {
637
+ name: e.variable.as_ref().unwrap().name().clone(),
638
+ }
639
+ .into(),
640
+ );
641
+ }
642
+ }
643
+ ast::Pattern::Path(p) =>
644
+ {
645
+ if self.has_variable(&Some(p.variable.clone()))
646
+ {
647
+ return Err(
648
+ CompileTimeError::VariableAlreadyBound {
649
+ name: p.variable.name().clone(),
650
+ }
651
+ .into(),
652
+ );
653
+ }
654
+ }
655
+ }
656
+ self.analyse_pattern(pattern, false)?;
657
+ }
658
+ }
659
+ LogicalPlan::VectorSearch {
660
+ result_var,
661
+ score_var,
662
+ ..
663
+ } =>
664
+ {
665
+ // Declare the result variable as a Node
666
+ self.declare_variable(result_var, expression_analyser::ExpressionType::Node)?;
667
+ self.mark_variables_as_set(result_var)?;
668
+
669
+ // Declare the score variable if present
670
+ if let Some(score_var_id) = score_var
671
+ {
672
+ self.declare_variable(score_var_id, expression_analyser::ExpressionType::Float)?;
673
+ self.mark_variables_as_set(score_var_id)?;
674
+ }
675
+ }
676
+ LogicalPlan::CreateVectorIndex { .. } =>
677
+ {
678
+ // Schema operation - no variable analysis needed
679
+ }
614
680
  }
615
681
  Ok(())
616
682
  }