Skip to content

Commit 78123b4

Browse files
Don't attempt to decode NULL graph entities (#69)
* Don't attempt to decode NULL graph entities * Remove unnecessary logic from parse_path * Add test for null graph entities
1 parent be46c8a commit 78123b4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

redisgraph/query_result.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def parse_entity_properties(self, props):
104104
return properties
105105

106106
def parse_node(self, cell):
107+
# Return None if we received a null value.
108+
if self.is_null_scalar(cell):
109+
return None
110+
107111
# Node ID (integer),
108112
# [label string offset (integer)],
109113
# [[name, value type, value] X N]
@@ -116,6 +120,10 @@ def parse_node(self, cell):
116120
return Node(node_id=node_id, label=label, properties=properties)
117121

118122
def parse_edge(self, cell):
123+
# Return None if we received a null value.
124+
if self.is_null_scalar(cell):
125+
return None
126+
119127
# Edge ID (integer),
120128
# reltype string offset (integer),
121129
# src node ID offset (integer),
@@ -219,6 +227,9 @@ def pretty_print(self):
219227
def is_empty(self):
220228
return len(self.result_set) == 0
221229

230+
def is_null_scalar(self, cell):
231+
return cell == [ResultSetScalarTypes.VALUE_NULL, None]
232+
222233
@staticmethod
223234
def _get_value(prop, statistics):
224235
for stat in statistics:

test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,30 @@ def test_stringify_query_result(self):
162162

163163
redis_graph.delete()
164164

165+
def test_optional_match(self):
166+
redis_graph = Graph('optional', self.r)
167+
168+
# Build a graph of form (a)-[R]->(b)
169+
node0 = Node(node_id=0, label="L1", properties={'value': 'a'})
170+
node1 = Node(node_id=1, label="L1", properties={'value': 'b'})
171+
172+
edge01 = Edge(node0, "R", node1, edge_id=0)
173+
174+
redis_graph.add_node(node0)
175+
redis_graph.add_node(node1)
176+
redis_graph.add_edge(edge01)
177+
178+
redis_graph.flush()
179+
180+
# Issue a query that collects all outgoing edges from both nodes (the second has none).
181+
query = """MATCH (a) OPTIONAL MATCH (a)-[e]->(b) RETURN a, e, b ORDER BY a.value"""
182+
expected_results = [[node0, edge01, node1],
183+
[node1, None, None]]
184+
185+
result = redis_graph.query(query)
186+
self.assertEqual(expected_results, result.result_set)
187+
188+
redis_graph.delete()
165189

166190
if __name__ == '__main__':
167191
unittest.main()

0 commit comments

Comments
 (0)