cypher-dsl 0.1.0.alpha.1 → 0.1.0.alpha.3

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +67 -1
  3. data/README.md +66 -4
  4. data/lib/cypher_dsl/clauses/load_csv.rb +8 -2
  5. data/lib/cypher_dsl/clauses/match.rb +2 -2
  6. data/lib/cypher_dsl/clauses/raw.rb +9 -0
  7. data/lib/cypher_dsl/clauses.rb +11 -0
  8. data/lib/cypher_dsl/comparison.rb +6 -0
  9. data/lib/cypher_dsl/condition.rb +1 -1
  10. data/lib/cypher_dsl/count_expression.rb +7 -3
  11. data/lib/cypher_dsl/cypher.rb +80 -19
  12. data/lib/cypher_dsl/expression.rb +3 -0
  13. data/lib/cypher_dsl/function_invocation.rb +7 -0
  14. data/lib/cypher_dsl/functions.rb +11 -1
  15. data/lib/cypher_dsl/has_label_condition.rb +1 -1
  16. data/lib/cypher_dsl/hint.rb +71 -0
  17. data/lib/cypher_dsl/label_operation.rb +11 -3
  18. data/lib/cypher_dsl/labels.rb +66 -0
  19. data/lib/cypher_dsl/literal.rb +24 -2
  20. data/lib/cypher_dsl/named_path.rb +6 -3
  21. data/lib/cypher_dsl/node.rb +15 -4
  22. data/lib/cypher_dsl/property.rb +9 -2
  23. data/lib/cypher_dsl/property_exists_condition.rb +15 -0
  24. data/lib/cypher_dsl/raw_expression.rb +76 -3
  25. data/lib/cypher_dsl/relationship.rb +8 -1
  26. data/lib/cypher_dsl/relationship_chain.rb +3 -0
  27. data/lib/cypher_dsl/renderer/configuration.rb +61 -4
  28. data/lib/cypher_dsl/renderer/dialect.rb +24 -7
  29. data/lib/cypher_dsl/renderer/escaper.rb +10 -7
  30. data/lib/cypher_dsl/renderer/generated_name_resolver.rb +110 -0
  31. data/lib/cypher_dsl/renderer/name_resolver.rb +35 -0
  32. data/lib/cypher_dsl/renderer/visitor/conditions.rb +74 -0
  33. data/lib/cypher_dsl/renderer/visitor/expressions.rb +40 -40
  34. data/lib/cypher_dsl/renderer/visitor/label_rendering.rb +84 -0
  35. data/lib/cypher_dsl/renderer/visitor/patterns.rb +18 -29
  36. data/lib/cypher_dsl/renderer/visitor.rb +106 -29
  37. data/lib/cypher_dsl/renderer.rb +11 -5
  38. data/lib/cypher_dsl/search.rb +91 -0
  39. data/lib/cypher_dsl/standalone_call.rb +0 -6
  40. data/lib/cypher_dsl/statement.rb +4 -0
  41. data/lib/cypher_dsl/statement_builder.rb +81 -15
  42. data/lib/cypher_dsl/statement_catalog.rb +40 -6
  43. data/lib/cypher_dsl/subquery_with.rb +1 -0
  44. data/lib/cypher_dsl/symbolic_name.rb +1 -1
  45. data/lib/cypher_dsl/using_periodic_commit.rb +11 -0
  46. data/lib/cypher_dsl/vector_literal.rb +41 -0
  47. data/lib/cypher_dsl/version.rb +1 -1
  48. metadata +13 -3
  49. data/lib/cypher_dsl/label_expression.rb +0 -40
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CypherDSL
4
+ # `vector([1, 2, 3], 3, INTEGER NOT NULL)`: a typed vector literal. The Java
5
+ # overloads per primitive array become an optional type: `:integer8`,
6
+ # `:integer16`, `:integer32`, `:integer` (default for integers), `:float32`
7
+ # and `:float` (default for floats).
8
+ class VectorLiteral
9
+ include Expression
10
+
11
+ TYPES = { integer8: 'INTEGER8', integer16: 'INTEGER16', integer32: 'INTEGER32', integer: 'INTEGER',
12
+ float32: 'FLOAT32', float: 'FLOAT' }.freeze
13
+ FLOAT_TYPES = %i[float32 float].freeze
14
+ MAX_SIZE = 4096
15
+
16
+ attr_reader :content, :type
17
+
18
+ def self.of(elements, type = nil)
19
+ raise ArgumentError, 'Vector elements must not be literal null' if elements.nil?
20
+
21
+ size = elements.size
22
+ unless (1..MAX_SIZE).cover?(size)
23
+ raise ArgumentError,
24
+ "'#{size}' is not a valid value. Must be a number in the range 1 to #{MAX_SIZE} (GQL 42N31)"
25
+ end
26
+
27
+ new(elements, type || (elements.all?(Integer) ? :integer : :float))
28
+ end
29
+
30
+ def initialize(content, type)
31
+ raise ArgumentError, "Unknown vector type #{type.inspect}" unless TYPES.key?(type)
32
+
33
+ @type = type
34
+ @content = (FLOAT_TYPES.include?(type) ? content.map(&:to_f) : content.map(&:to_i)).freeze
35
+ freeze
36
+ end
37
+
38
+ # The literal as Cypher text; it does not depend on any rendering option.
39
+ def as_string = "vector([#{content.join(', ')}], #{content.size}, #{TYPES[type]} NOT NULL)"
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CypherDSL
4
- VERSION = '0.1.0.alpha.1'
4
+ VERSION = '0.1.0.alpha.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cypher-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha.1
4
+ version: 0.1.0.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heinrich Klobuczek
@@ -50,6 +50,7 @@ files:
50
50
  - lib/cypher_dsl/clauses/match.rb
51
51
  - lib/cypher_dsl/clauses/merge.rb
52
52
  - lib/cypher_dsl/clauses/order.rb
53
+ - lib/cypher_dsl/clauses/raw.rb
53
54
  - lib/cypher_dsl/clauses/raw_return.rb
54
55
  - lib/cypher_dsl/clauses/remove.rb
55
56
  - lib/cypher_dsl/clauses/return.rb
@@ -71,8 +72,9 @@ files:
71
72
  - lib/cypher_dsl/function_invocation.rb
72
73
  - lib/cypher_dsl/functions.rb
73
74
  - lib/cypher_dsl/has_label_condition.rb
74
- - lib/cypher_dsl/label_expression.rb
75
+ - lib/cypher_dsl/hint.rb
75
76
  - lib/cypher_dsl/label_operation.rb
77
+ - lib/cypher_dsl/labels.rb
76
78
  - lib/cypher_dsl/list_comprehension.rb
77
79
  - lib/cypher_dsl/list_expression.rb
78
80
  - lib/cypher_dsl/list_operator.rb
@@ -89,6 +91,7 @@ files:
89
91
  - lib/cypher_dsl/pattern_comprehension.rb
90
92
  - lib/cypher_dsl/pattern_expression.rb
91
93
  - lib/cypher_dsl/property.rb
94
+ - lib/cypher_dsl/property_exists_condition.rb
92
95
  - lib/cypher_dsl/quantified_path_pattern.rb
93
96
  - lib/cypher_dsl/raw_expression.rb
94
97
  - lib/cypher_dsl/reduction.rb
@@ -99,9 +102,14 @@ files:
99
102
  - lib/cypher_dsl/renderer/configuration.rb
100
103
  - lib/cypher_dsl/renderer/dialect.rb
101
104
  - lib/cypher_dsl/renderer/escaper.rb
105
+ - lib/cypher_dsl/renderer/generated_name_resolver.rb
106
+ - lib/cypher_dsl/renderer/name_resolver.rb
102
107
  - lib/cypher_dsl/renderer/visitor.rb
108
+ - lib/cypher_dsl/renderer/visitor/conditions.rb
103
109
  - lib/cypher_dsl/renderer/visitor/expressions.rb
110
+ - lib/cypher_dsl/renderer/visitor/label_rendering.rb
104
111
  - lib/cypher_dsl/renderer/visitor/patterns.rb
112
+ - lib/cypher_dsl/search.rb
105
113
  - lib/cypher_dsl/sort_item.rb
106
114
  - lib/cypher_dsl/standalone_call.rb
107
115
  - lib/cypher_dsl/statement.rb
@@ -111,6 +119,8 @@ files:
111
119
  - lib/cypher_dsl/symbolic_name.rb
112
120
  - lib/cypher_dsl/unary_operation.rb
113
121
  - lib/cypher_dsl/union_query.rb
122
+ - lib/cypher_dsl/using_periodic_commit.rb
123
+ - lib/cypher_dsl/vector_literal.rb
114
124
  - lib/cypher_dsl/version.rb
115
125
  homepage: https://github.com/neo4jrb/cypher-dsl
116
126
  licenses:
@@ -134,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
144
  - !ruby/object:Gem::Version
135
145
  version: '0'
136
146
  requirements: []
137
- rubygems_version: 4.0.20
147
+ rubygems_version: 4.0.3
138
148
  specification_version: 4
139
149
  summary: A Ruby DSL (builder) for the Cypher query language
140
150
  test_files: []
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CypherDSL
4
- # A label expression as in `(n:A|B)`, `(n:A&!B)` or `(n:(A|B)&C)`; built from
5
- # {Labels.exactly} and combined with {#or}, {#and} and {#negate}.
6
- class LabelExpression
7
- TYPES = %i[leaf conjunction disjunction negation].freeze
8
-
9
- attr_reader :type, :value, :operands
10
-
11
- def self.exactly(name) = new(:leaf, name.to_s, [])
12
-
13
- def initialize(type, value, operands)
14
- raise ArgumentError, "Unknown label expression type #{type.inspect}" unless TYPES.include?(type)
15
-
16
- @type = type
17
- @value = value
18
- @operands = operands.freeze
19
- freeze
20
- end
21
-
22
- def or(other) = LabelExpression.new(:disjunction, nil, [self, coerce(other)])
23
- def and(other) = LabelExpression.new(:conjunction, nil, [self, coerce(other)])
24
- def negate = LabelExpression.new(:negation, nil, [self])
25
- alias not negate
26
-
27
- def leaf? = type == :leaf
28
-
29
- private
30
-
31
- def coerce(other) = other.is_a?(LabelExpression) ? other : LabelExpression.exactly(other)
32
- end
33
-
34
- # Factory for label expressions: `Labels.exactly('A').or('B')`.
35
- module Labels
36
- module_function
37
-
38
- def exactly(name) = LabelExpression.exactly(name)
39
- end
40
- end