From b2393ea1a0aac05f9b6594e1c930d00685c4d280 Mon Sep 17 00:00:00 2001 From: Roi Lipman Date: Sun, 2 Jun 2019 14:22:41 +0300 Subject: [PATCH] execution-plan is structured as a nested array --- redisgraph/graph.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index ad2039e..1955ad8 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -112,11 +112,28 @@ def query(self, q): response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q, "--compact") return QueryResult(self, response) + def _execution_plan_to_string(self, plan, plan_str, ident=0): + plan_str += ("\t" * ident) + plan[0] + "\n" + for i in range (1, len(plan)): + plan_str = self._execution_plan_to_string(plan[i], plan_str, ident+1) + return plan_str + def execution_plan(self, query): """ Get the execution plan for given query. - """ - return self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query) + GRAPH.EXPLAIN returns a nested set of arrays + the first element of each array is a string representing + the current operation, followed by 0 or more sub-arrays + one for each child operation. + """ + plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query) + plan_str = "" + # TODO: Consider switching to a tree structure + # https://treelib.readthedocs.io/en/latest/ + # make sure we're able to search for a specific operation + # within the tree. + plan_str = self._execution_plan_to_string(plan, plan_str) + return plan_str def delete(self): """