From 27b30a3a98101091a698e9c22d2d49a7c225d700 Mon Sep 17 00:00:00 2001 From: Ofir Moskovich <ofir.moskovich@redislabs.com> Date: Sun, 1 Aug 2021 14:59:51 +0300 Subject: [PATCH 1/7] added query params argument --- redisgraph/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index a12fe7f..a12b657 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -160,7 +160,7 @@ def _build_params_header(self, params): if not isinstance(params, dict): raise TypeError("'params' must be a dict") # Header starts with "CYPHER" - params_header = "CYPHER " + params_header = "query_params " for key, value in params.items(): # If value is string add quotation marks. if isinstance(value, str): From 5ddbf31e8e2f0c234605bdf34c4e7dca9bf453f0 Mon Sep 17 00:00:00 2001 From: Ofir Moskovich <ofir.moskovich@redislabs.com> Date: Sun, 1 Aug 2021 15:21:51 +0300 Subject: [PATCH 2/7] amend to prev --- redisgraph/graph.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index a12b657..f399a11 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -160,7 +160,7 @@ def _build_params_header(self, params): if not isinstance(params, dict): raise TypeError("'params' must be a dict") # Header starts with "CYPHER" - params_header = "query_params " + params_header = "query_params" for key, value in params.items(): # If value is string add quotation marks. if isinstance(value, str): @@ -168,7 +168,7 @@ def _build_params_header(self, params): # Value is None, replace with "null" string. elif value is None: value = "null" - params_header += str(key) + "=" + str(value) + " " + params_header += " " + str(key) + "=" + str(value) return params_header def query(self, q, params=None, timeout=None, read_only=False): @@ -185,16 +185,15 @@ def query(self, q, params=None, timeout=None, read_only=False): # maintain original 'q' query = q - # handle query parameters - if params is not None: - query = self._build_params_header(params) + query - # construct query command # ask for compact result-set format # specify known graph version cmd = "GRAPH.RO_QUERY" if read_only else "GRAPH.QUERY" # command = [cmd, self.name, query, "--compact", "version", self.version] - command = [cmd, self.name, query, "--compact"] + if params is not None: + command = [cmd, self.name, query, self._build_params_header(params), "--compact"] + else: + command = [cmd, self.name, query, "--compact"] # include timeout is specified if timeout: @@ -234,9 +233,9 @@ def execution_plan(self, query, params=None): params: query parameters """ if params is not None: - query = self._build_params_header(params) + query - - plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query) + plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query, self._build_params_header(params)) + else: + plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query) return self._execution_plan_to_string(plan) def delete(self): From 2be5a6744d138634b6d31ecb1770cd053e3d8a66 Mon Sep 17 00:00:00 2001 From: Ofir Moskovich <ofir.moskovich@redislabs.com> Date: Sun, 1 Aug 2021 15:32:59 +0300 Subject: [PATCH 3/7] amend to prev --- redisgraph/graph.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index f399a11..2882c7b 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -159,8 +159,7 @@ def flush(self): def _build_params_header(self, params): if not isinstance(params, dict): raise TypeError("'params' must be a dict") - # Header starts with "CYPHER" - params_header = "query_params" + params_header = "" for key, value in params.items(): # If value is string add quotation marks. if isinstance(value, str): @@ -168,7 +167,7 @@ def _build_params_header(self, params): # Value is None, replace with "null" string. elif value is None: value = "null" - params_header += " " + str(key) + "=" + str(value) + params_header += str(key) + "=" + str(value) + " " return params_header def query(self, q, params=None, timeout=None, read_only=False): @@ -190,10 +189,11 @@ def query(self, q, params=None, timeout=None, read_only=False): # specify known graph version cmd = "GRAPH.RO_QUERY" if read_only else "GRAPH.QUERY" # command = [cmd, self.name, query, "--compact", "version", self.version] - if params is not None: - command = [cmd, self.name, query, self._build_params_header(params), "--compact"] - else: - command = [cmd, self.name, query, "--compact"] + command = [cmd, self.name, query, "--compact"] + + # query params are specified + if params: + command += ["query_params", self._build_params_header(params)] # include timeout is specified if timeout: @@ -233,7 +233,7 @@ def execution_plan(self, query, params=None): params: query parameters """ if params is not None: - plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query, self._build_params_header(params)) + plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query, "query_params", self._build_params_header(params)) else: plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query) return self._execution_plan_to_string(plan) From 4705ce7d3cb35a0c72e3edbc6c95c643f901f950 Mon Sep 17 00:00:00 2001 From: Ofir Moskovich <ofir.moskovich@redislabs.com> Date: Sun, 1 Aug 2021 15:41:48 +0300 Subject: [PATCH 4/7] amend to prev --- redisgraph/graph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index 2882c7b..f5b5370 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -193,6 +193,7 @@ def query(self, q, params=None, timeout=None, read_only=False): # query params are specified if params: + print("AAAAAAA") command += ["query_params", self._build_params_header(params)] # include timeout is specified From d178e4ec49641cc93f9c8ec9e0522fc6fc512ccb Mon Sep 17 00:00:00 2001 From: Ofir Moskovich <ofir.moskovich@redislabs.com> Date: Mon, 2 Aug 2021 00:32:50 +0300 Subject: [PATCH 5/7] amend to prev --- redisgraph/graph.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index f5b5370..dd56936 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -159,7 +159,8 @@ def flush(self): def _build_params_header(self, params): if not isinstance(params, dict): raise TypeError("'params' must be a dict") - params_header = "" + # Header starts with "CYPHER" + params_header = "CYPHER " for key, value in params.items(): # If value is string add quotation marks. if isinstance(value, str): From 2d7f53f120862500c924674abe5e00c8de8acdd3 Mon Sep 17 00:00:00 2001 From: Ofir Moskovich <ofir.moskovich@redislabs.com> Date: Mon, 2 Aug 2021 13:00:29 +0300 Subject: [PATCH 6/7] amend to prev --- redisgraph/graph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index dd56936..5ae2829 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -194,7 +194,6 @@ def query(self, q, params=None, timeout=None, read_only=False): # query params are specified if params: - print("AAAAAAA") command += ["query_params", self._build_params_header(params)] # include timeout is specified From 08bbf45e9ff12e4a38a18dea15a8fc54eb689097 Mon Sep 17 00:00:00 2001 From: Ofir Moskovich <ofir.moskovich@redislabs.com> Date: Mon, 2 Aug 2021 16:43:15 +0300 Subject: [PATCH 7/7] amend to prev --- redisgraph/graph.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/redisgraph/graph.py b/redisgraph/graph.py index 5ae2829..cb6f4c3 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -157,7 +157,10 @@ def flush(self): self.edges = [] def _build_params_header(self, params): - if not isinstance(params, dict): + if isinstance(params, str): + #params is in header format use it as is + return params + elif not isinstance(params, dict): raise TypeError("'params' must be a dict") # Header starts with "CYPHER" params_header = "CYPHER "