@@ -246,6 +246,7 @@ def test_cached_execution(self):
246
246
247
247
def test_execution_plan (self ):
248
248
redis_graph = Graph ('execution_plan' , self .r )
249
+ # graph creation / population
249
250
create_query = """CREATE
250
251
(:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'}),
251
252
(:Rider {name:'Dani Pedrosa'})-[:rides]->(:Team {name:'Honda'}),
@@ -254,11 +255,11 @@ def test_execution_plan(self):
254
255
255
256
result = redis_graph .execution_plan ("""MATCH (r:Rider)-[:rides]->(t:Team)
256
257
WHERE t.name = $name
257
- RETURN r.name, t.name, $params
258
+ RETURN r.name, t.name
258
259
UNION
259
260
MATCH (r:Rider)-[:rides]->(t:Team)
260
261
WHERE t.name = $name
261
- RETURN r.name, t.name, $params """ , {'name' : 'Yehuda ' })
262
+ RETURN r.name, t.name""" , {'name' : 'Yamaha ' })
262
263
expected = '''\
263
264
Results
264
265
Distinct
@@ -292,47 +293,54 @@ def test_execution_plan(self):
292
293
293
294
def test_profile (self ):
294
295
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})"""
299
298
redis_graph .query (create_query )
300
299
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 )
336
344
337
345
redis_graph .delete ()
338
346
0 commit comments