Skip to content

Commit 9d69937

Browse files
committed
address review
1 parent 2c30de8 commit 9d69937

File tree

3 files changed

+57
-45
lines changed

3 files changed

+57
-45
lines changed

redisgraph/execution_plan.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33

44
class ProfileStats:
5+
"""
6+
ProfileStats, runtime execution statistics of operation.
7+
"""
8+
59
def __init__(self, records_produced, execution_time):
610
self.records_produced = records_produced
711
self.execution_time = execution_time
@@ -43,7 +47,7 @@ def __eq__(self, o: object) -> bool:
4347
return (self.name == o.name and self.args == o.args)
4448

4549
def __str__(self) -> str:
46-
args_str = "" if self.args is None else " | " + " | ".join(self.args)
50+
args_str = "" if self.args is None else " | " + self.args
4751
return f"{self.name}{args_str}"
4852

4953

@@ -151,7 +155,7 @@ def _create_operation(args):
151155
execution_time = float(re.search("Execution time: (\\d+.\\d+) ms", args[-1]).group(1))
152156
profile_stats = ProfileStats(records_produced, execution_time)
153157
args.pop(-1)
154-
return Operation(name, None if len(args) == 0 else [arg.strip() for arg in args], profile_stats)
158+
return Operation(name, None if len(args) == 0 else args[0].strip(), profile_stats)
155159

156160
# iterate plan operations
157161
while i < len(self.plan):

redisgraph/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def query(self, q, params=None, timeout=None, read_only=False):
219219
def execution_plan(self, query, params=None):
220220
"""
221221
Get the execution plan for given query,
222-
GRAPH.EXPLAIN returns an array of operations.
222+
GRAPH.EXPLAIN returns ExecutionPlan object.
223223
224224
Args:
225225
query: the query that will be executed
@@ -234,7 +234,7 @@ def execution_plan(self, query, params=None):
234234
def profile(self, query, params=None):
235235
"""
236236
Get the profield execution plan for given query,
237-
GRAPH.PROFILE returns an array of operations.
237+
GRAPH.PROFILE returns ExecutionPlan object.
238238
239239
Args:
240240
query: the query that will be executed

tests/functional/test_all.py

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def test_cached_execution(self):
246246

247247
def test_execution_plan(self):
248248
redis_graph = Graph('execution_plan', self.r)
249+
# graph creation / population
249250
create_query = """CREATE
250251
(:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'}),
251252
(:Rider {name:'Dani Pedrosa'})-[:rides]->(:Team {name:'Honda'}),
@@ -254,11 +255,11 @@ def test_execution_plan(self):
254255

255256
result = redis_graph.execution_plan("""MATCH (r:Rider)-[:rides]->(t:Team)
256257
WHERE t.name = $name
257-
RETURN r.name, t.name, $params
258+
RETURN r.name, t.name
258259
UNION
259260
MATCH (r:Rider)-[:rides]->(t:Team)
260261
WHERE t.name = $name
261-
RETURN r.name, t.name, $params""", {'name': 'Yehuda'})
262+
RETURN r.name, t.name""", {'name': 'Yamaha'})
262263
expected = '''\
263264
Results
264265
Distinct
@@ -292,47 +293,54 @@ def test_execution_plan(self):
292293

293294
def test_profile(self):
294295
redis_graph = Graph('profile', self.r)
295-
create_query = """CREATE
296-
(:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'}),
297-
(:Rider {name:'Dani Pedrosa'})-[:rides]->(:Team {name:'Honda'}),
298-
(:Rider {name:'Andrea Dovizioso'})-[:rides]->(:Team {name:'Ducati'})"""
296+
# graph creation / population
297+
create_query = """UNWIND range(1, 30) as x CREATE (:Person {id: x})"""
299298
redis_graph.query(create_query)
300299

301-
result = redis_graph.profile("""MATCH (r:Rider)-[:rides]->(t:Team)
302-
WHERE t.name = $name
303-
RETURN r.name, t.name, $params
304-
UNION
305-
MATCH (r:Rider)-[:rides]->(t:Team)
306-
WHERE t.name = $name
307-
RETURN r.name, t.name, $params""", {'name': 'Yehuda'})
308-
expected = '''\
309-
Results
310-
Distinct
311-
Join
312-
Project
313-
Conditional Traverse | (t:Team)->(r:Rider)
314-
Filter
315-
Node By Label Scan | (t:Team)
316-
Project
317-
Conditional Traverse | (t:Team)->(r:Rider)
318-
Filter
319-
Node By Label Scan | (t:Team)'''
320-
self.assertEqual(str(result), expected)
321-
322-
expected = Operation('Results') \
323-
.append_child(Operation('Distinct')
324-
.append_child(Operation('Join')
325-
.append_child(Operation('Project')
326-
.append_child(Operation('Conditional Traverse', "(t:Team)->(r:Rider)")
327-
.append_child(Operation("Filter")
328-
.append_child(Operation('Node By Label Scan', "(t:Team)")))))
329-
.append_child(Operation('Project')
330-
.append_child(Operation('Conditional Traverse', "(t:Team)->(r:Rider)")
331-
.append_child(Operation("Filter")
332-
.append_child(Operation('Node By Label Scan', "(t:Team)")))))
333-
))
334-
335-
self.assertEqual(result.structured_plan, expected)
300+
plan = redis_graph.profile("""MATCH (p:Person)
301+
WHERE p.id > 15
302+
RETURN p""")
303+
304+
results = plan.structured_plan
305+
self.assertEqual(results.name, "Results")
306+
self.assertEqual(results.profile_stats.records_produced, 15)
307+
self.assertGreater(results.profile_stats.execution_time, 0)
308+
309+
project = results.children[0]
310+
self.assertEqual(project.name, "Project")
311+
self.assertEqual(project.profile_stats.records_produced, 15)
312+
self.assertGreater(project.profile_stats.execution_time, 0)
313+
314+
filter = project.children[0]
315+
self.assertEqual(filter.name, "Filter")
316+
self.assertEqual(filter.profile_stats.records_produced, 15)
317+
self.assertGreater(filter.profile_stats.execution_time, 0)
318+
319+
node_by_label_scan = filter.children[0]
320+
self.assertEqual(node_by_label_scan.name, "Node By Label Scan")
321+
self.assertEqual(node_by_label_scan.profile_stats.records_produced, 30)
322+
self.assertGreater(node_by_label_scan.profile_stats.execution_time, 0)
323+
324+
redis_graph.query("CREATE INDEX FOR (p:Person) ON (p.id)")
325+
326+
plan = redis_graph.profile("""MATCH (p:Person)
327+
WHERE p.id > 15
328+
RETURN p""")
329+
330+
results = plan.structured_plan
331+
self.assertEqual(results.name, "Results")
332+
self.assertEqual(results.profile_stats.records_produced, 15)
333+
self.assertGreater(results.profile_stats.execution_time, 0)
334+
335+
project = results.children[0]
336+
self.assertEqual(project.name, "Project")
337+
self.assertEqual(project.profile_stats.records_produced, 15)
338+
self.assertGreater(project.profile_stats.execution_time, 0)
339+
340+
node_by_index_scan = project.children[0]
341+
self.assertEqual(node_by_index_scan.name, "Node By Index Scan")
342+
self.assertEqual(node_by_index_scan.profile_stats.records_produced, 15)
343+
self.assertGreater(node_by_index_scan.profile_stats.execution_time, 0)
336344

337345
redis_graph.delete()
338346

0 commit comments

Comments
 (0)