Skip to content

Commit 0c78b1a

Browse files
authored
new result-set structure parsing (#28)
* new result-set structure parsing * remove string mapping, introduce procedure call * node, edge equality * statistics are the last element in response * add test
1 parent c58c1b1 commit 0c78b1a

File tree

9 files changed

+508
-217
lines changed

9 files changed

+508
-217
lines changed

redisgraph/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .client import Node, Edge, Graph
1+
from node import Node
2+
from edge import Edge
3+
from graph import Graph

redisgraph/client.py

Lines changed: 0 additions & 182 deletions
This file was deleted.

redisgraph/edge.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from util import *
2+
3+
class Edge(object):
4+
"""
5+
An edge connecting two nodes.
6+
"""
7+
def __init__(self, src_node, relation, dest_node, edge_id=None, properties=None):
8+
"""
9+
Create a new edge.
10+
"""
11+
assert src_node is not None and dest_node is not None
12+
13+
self.id = edge_id
14+
self.relation = '' or relation
15+
self.properties = {} or properties
16+
self.src_node = src_node
17+
self.dest_node = dest_node
18+
19+
def toString(self):
20+
res = ""
21+
if self.properties:
22+
props = ','.join(key+':'+str(quote_string(val)) for key, val in self.properties.items())
23+
res += '{' + props + '}'
24+
25+
return res
26+
27+
def __str__(self):
28+
# Source node.
29+
res = '(' + self.src_node.alias + ')'
30+
31+
# Edge
32+
res += "-["
33+
if self.relation:
34+
res += ":" + self.relation
35+
if self.properties:
36+
props = ','.join(key+':'+str(quote_string(val)) for key, val in self.properties.items())
37+
res += '{' + props + '}'
38+
res += ']->'
39+
40+
# Dest node.
41+
res += '(' + self.dest_node.alias + ')'
42+
43+
return res
44+
45+
def __eq__(self, rhs):
46+
# Quick positive check, if both IDs are set.
47+
if self.id is not None and rhs.id is not None and self.id == rhs.id:
48+
return True
49+
50+
# Source and destination nodes should match.
51+
if self.src_node != rhs.src_node:
52+
return False
53+
54+
if self.dest_node != rhs.dest_node:
55+
return False
56+
57+
# Relation should match.
58+
if self.relation != rhs.relation:
59+
return False
60+
61+
# Quick check for number of properties.
62+
if len(self.properties) != len(rhs.properties):
63+
return False
64+
65+
# Compare properties.
66+
if self.properties != rhs.properties:
67+
return False
68+
69+
return True

0 commit comments

Comments
 (0)