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 +4 -4
- data/README.md +3 -4
- data/lib/redisgraph.rb +4 -4
- data/lib/redisgraph/query_result.rb +34 -25
- data/lib/redisgraph/version.rb +1 -1
- data/spec/redisgraph_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e099fdc41f5cf1db6f09c0d660cf982132901831761389cfab03c862c97b2e3e
|
4
|
+
data.tar.gz: 2ea412cb08d913081314a330f27d87aed726593293955bd9341478e18b27e9f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8339a9d8563a40dae5440d2ee289a5691abae82e78713c9333d42ef292c5e4c51dab43fe97013c861ac178e3501442c403e7393c8ac11e12bcadb003d48e7103
|
7
|
+
data.tar.gz: 0b0ef19e88ae176f3f173331964eb575f89a4c8ecd3548578ab4caf2dd3af661aee8b7616859991ac98ba434ca3d84a57d8fb8f06985d5855ca6698a400faffd
|
data/README.md
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
[](https://github.com/RedisGraph/redisgraph-rb/releases/latest)
|
4
4
|
[](https://codecov.io/gh/RedisGraph/redisgraph-rb)
|
5
5
|
|
6
|
-
|
7
6
|
# redisgraph-rb
|
7
|
+
[](https://forum.redislabs.com/c/modules/redisgraph)
|
8
|
+
[](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
|
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
|
data/lib/redisgraph.rb
CHANGED
@@ -23,7 +23,7 @@ class RedisGraph
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def invalidate
|
26
|
-
@labels = @
|
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(
|
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(
|
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(
|
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
|
76
|
+
when ValueType::NULL
|
72
77
|
return nil
|
73
|
-
when
|
78
|
+
when ValueType::STRING
|
74
79
|
:to_s
|
75
|
-
when
|
80
|
+
when ValueType::INTEGER
|
76
81
|
:to_i
|
77
|
-
when
|
82
|
+
when ValueType::BOOLEAN
|
78
83
|
# no :to_b
|
79
|
-
return val ==
|
80
|
-
when
|
84
|
+
return val == 'true'
|
85
|
+
when ValueType::DOUBLE
|
81
86
|
:to_f
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
104
|
+
if prop_index >= property_keys.length
|
96
105
|
@metadata.invalidate
|
97
106
|
property_keys = @metadata.property_keys
|
98
107
|
end
|
data/lib/redisgraph/version.rb
CHANGED
data/spec/redisgraph_spec.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|