@@ -112,11 +112,28 @@ def query(self, q):
112112 response = self .redis_con .execute_command ("GRAPH.QUERY" , self .name , q , "--compact" )
113113 return QueryResult (self , response )
114114
115+ def _execution_plan_to_string (self , plan , plan_str , ident = 0 ):
116+ plan_str += ("\t " * ident ) + plan [0 ] + "\n "
117+ for i in range (1 , len (plan )):
118+ plan_str = self ._execution_plan_to_string (plan [i ], plan_str , ident + 1 )
119+ return plan_str
120+
115121 def execution_plan (self , query ):
116122 """
117123 Get the execution plan for given query.
118- """
119- return self .redis_con .execute_command ("GRAPH.EXPLAIN" , self .name , query )
124+ GRAPH.EXPLAIN returns a nested set of arrays
125+ the first element of each array is a string representing
126+ the current operation, followed by 0 or more sub-arrays
127+ one for each child operation.
128+ """
129+ plan = self .redis_con .execute_command ("GRAPH.EXPLAIN" , self .name , query )
130+ plan_str = ""
131+ # TODO: Consider switching to a tree structure
132+ # https://treelib.readthedocs.io/en/latest/
133+ # make sure we're able to search for a specific operation
134+ # within the tree.
135+ plan_str = self ._execution_plan_to_string (plan , plan_str )
136+ return plan_str
120137
121138 def delete (self ):
122139 """
0 commit comments