redisgraph 2.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 732b9f9b3c2faa832739c1be5ef607e5f84621351244a604c9addd4b54957410
4
- data.tar.gz: 37374c73ca02f5e59b29bba44b77405b460a743fca092fc6172cf67a46a3dc53
3
+ metadata.gz: e099fdc41f5cf1db6f09c0d660cf982132901831761389cfab03c862c97b2e3e
4
+ data.tar.gz: 2ea412cb08d913081314a330f27d87aed726593293955bd9341478e18b27e9f4
5
5
  SHA512:
6
- metadata.gz: 1e79f75391e9c6160f60ec6dfa053804011e17441f64368badfb6974412c40b548f06e8c050d0364722681dc98bb093b41d1f664684c04548d9c5ca6f490e1e6
7
- data.tar.gz: fb4e0d21066b7331f9f149e96b4bb02d1987ddce2d5ad4b02c710734f8b9bbae1a250dbd7aa2de07598fbfe79de3e004fff51b37ef42006f91eea71e5816f729
6
+ metadata.gz: 8339a9d8563a40dae5440d2ee289a5691abae82e78713c9333d42ef292c5e4c51dab43fe97013c861ac178e3501442c403e7393c8ac11e12bcadb003d48e7103
7
+ data.tar.gz: 0b0ef19e88ae176f3f173331964eb575f89a4c8ecd3548578ab4caf2dd3af661aee8b7616859991ac98ba434ca3d84a57d8fb8f06985d5855ca6698a400faffd
data/README.md CHANGED
@@ -3,15 +3,14 @@
3
3
  [![GitHub issues](https://img.shields.io/github/release/RedisGraph/redisgraph-rb.svg)](https://github.com/RedisGraph/redisgraph-rb/releases/latest)
4
4
  [![Codecov](https://codecov.io/gh/RedisGraph/redisgraph-rb/branch/master/graph/badge.svg)](https://codecov.io/gh/RedisGraph/redisgraph-rb)
5
5
 
6
-
7
6
  # redisgraph-rb
7
+ [![Forum](https://img.shields.io/badge/Forum-RedisGraph-blue)](https://forum.redislabs.com/c/modules/redisgraph)
8
+ [![Gitter](https://badges.gitter.im/RedisLabs/RedisGraph.svg)](https://gitter.im/RedisLabs/RedisGraph?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
8
9
 
9
10
  `redisgraph-rb` is a Ruby gem client for the [RedisGraph](https://github.com/RedisLabsModules/RedisGraph) module. It relies on `redis-rb` for Redis connection management and provides support for graph QUERY, EXPLAIN, and DELETE commands.
10
11
 
11
12
  ## RedisGraph compatibility
12
- `redisgraph-rb` is currently compatible with RedisGraph versions >= 1.99 (module version: 19900)
13
-
14
- The result set structure introduced by RedisGraph 2.0 requires some modifications to this client. If you are interested in using this client with the latest RedisGraph, please inform us by commenting on [the corresponding issue](https://github.com/RedisGraph/redisgraph-rb/issues/1)!
13
+ The current version of `redisgraph-rb` is compatible with RedisGraph versions >= 1.99 (module version: 19900).
15
14
 
16
15
  ### Previous Version
17
16
  For RedisGraph versions >= 1.0 and < 2.0 (ie module version: 10202), instead use and refer to
@@ -23,7 +23,7 @@ class RedisGraph
23
23
  end
24
24
 
25
25
  def invalidate
26
- @labels = @property_key = @relationship_types
26
+ @labels = @property_keys = @relationship_types = nil
27
27
  end
28
28
 
29
29
  def labels
@@ -57,7 +57,7 @@ class RedisGraph
57
57
 
58
58
  # Execute a command and return its parsed result
59
59
  def query(command)
60
- resp = @connection.call("GRAPH.QUERY", @graphname, command, '--compact')
60
+ resp = @connection.call('GRAPH.QUERY', @graphname, command, '--compact')
61
61
  QueryResult.new(resp,
62
62
  metadata: @metadata)
63
63
  rescue Redis::CommandError => e
@@ -66,14 +66,14 @@ class RedisGraph
66
66
 
67
67
  # Return the execution plan for a given command
68
68
  def explain(command)
69
- @connection.call("GRAPH.EXPLAIN", @graphname, command)
69
+ @connection.call('GRAPH.EXPLAIN', @graphname, command)
70
70
  rescue Redis::CommandError => e
71
71
  raise ExplainError, e
72
72
  end
73
73
 
74
74
  # Delete the graph and all associated keys
75
75
  def delete
76
- @connection.call("GRAPH.DELETE", @graphname)
76
+ @connection.call('GRAPH.DELETE', @graphname)
77
77
  rescue Redis::CommandError => e
78
78
  raise DeleteError, e
79
79
  end
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Data types that can be returned in result sets
4
+ module ValueType
5
+ UNKNOWN = 0
6
+ NULL = 1
7
+ STRING = 2
8
+ INTEGER = 3
9
+ BOOLEAN = 4
10
+ DOUBLE = 5
11
+ ARRAY = 6
12
+ EDGE = 7
13
+ NODE = 8
14
+ PATH = 9 # TODO: not yet implemented
15
+ end
16
+
1
17
  class QueryResult
2
18
  attr_accessor :columns
3
19
  attr_accessor :resultset
@@ -21,6 +37,8 @@ class QueryResult
21
37
  end
22
38
 
23
39
  def print_resultset
40
+ return unless columns
41
+
24
42
  pretty = Terminal::Table.new headings: columns do |t|
25
43
  resultset.each { |record| t << record }
26
44
  end
@@ -33,7 +51,6 @@ class QueryResult
33
51
 
34
52
  # Any non-empty result set will have multiple rows (arrays)
35
53
 
36
-
37
54
  # First row is header describing the returned records, corresponding
38
55
  # precisely in order and naming to the RETURN clause of the query.
39
56
  header = response[0]
@@ -47,19 +64,7 @@ class QueryResult
47
64
  header.reduce([]) do |agg, (type, _it)|
48
65
  i += 1
49
66
  el = row[i]
50
-
51
- case type
52
- when 1 # scalar
53
- agg << map_scalar(el[0], el[1])
54
- when 2 # node
55
- props = el[2]
56
- agg << props.sort_by { |prop| prop[0] }.map { |prop| map_prop(prop) }
57
- when 3 # relation
58
- props = el[4]
59
- agg << props.sort_by { |prop| prop[0] }.map { |prop| map_prop(prop) }
60
- end
61
-
62
- agg
67
+ agg << map_scalar(el[0], el[1])
63
68
  end
64
69
  end
65
70
 
@@ -68,21 +73,25 @@ class QueryResult
68
73
 
69
74
  def map_scalar(type, val)
70
75
  map_func = case type
71
- when 1 # null
76
+ when ValueType::NULL
72
77
  return nil
73
- when 2 # string
78
+ when ValueType::STRING
74
79
  :to_s
75
- when 3 # integer
80
+ when ValueType::INTEGER
76
81
  :to_i
77
- when 4 # boolean
82
+ when ValueType::BOOLEAN
78
83
  # no :to_b
79
- return val == "true"
80
- when 5 # double
84
+ return val == 'true'
85
+ when ValueType::DOUBLE
81
86
  :to_f
82
- # TODO: when in the distro packages and docker images,
83
- # the following _should_ work
84
- # when 6 # array
85
- # val.map { |it| map_scalar(it[0], it[1]) }
87
+ when ValueType::ARRAY
88
+ return val.map { |it| map_scalar(it[0], it[1]) }
89
+ when ValueType::EDGE
90
+ props = val[4]
91
+ return props.sort_by { |prop| prop[0] }.map { |prop| map_prop(prop) }
92
+ when ValueType::NODE
93
+ props = val[2]
94
+ return props.sort_by { |prop| prop[0] }.map { |prop| map_prop(prop) }
86
95
  end
87
96
  val.send(map_func)
88
97
  end
@@ -92,7 +101,7 @@ class QueryResult
92
101
 
93
102
  property_keys = @metadata.property_keys
94
103
  prop_index = prop[0]
95
- if prop_index > property_keys.length
104
+ if prop_index >= property_keys.length
96
105
  @metadata.invalidate
97
106
  property_keys = @metadata.property_keys
98
107
  end
@@ -1,3 +1,3 @@
1
1
  class RedisGraph
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
@@ -76,4 +76,20 @@ describe RedisGraph do
76
76
  expect(res.resultset).to eq([["src1", [{"name"=>"dest1"}, {"color"=>"magenta"}], [{"weight"=>7.8}]]])
77
77
  end
78
78
  end
79
+
80
+ context "update" do
81
+ it "should support adding new properties" do
82
+ q = """MATCH (a {name: 'src1'}) SET a.newval = true"""
83
+ plan = @r.explain(q)
84
+ expect(plan.detect { |row| row.include?("Update") }).to_not be_nil
85
+ res = @r.query(q)
86
+ expect(res.stats[:properties_set]).to eq(1)
87
+ end
88
+
89
+ it "should print property strings correctly after updates" do
90
+ q = """MATCH (a {name: 'src1'}) RETURN a"""
91
+ res = @r.query(q)
92
+ expect(res.resultset).to eq([[[{"name"=>"src1"}, {"color"=>"cyan"}, {"newval"=>TRUE}]]])
93
+ end
94
+ end
79
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redisgraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redis Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-12 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis