From 9443ce67d1bbed9c6fd73b338acfc87ea7dab4c4 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Sun, 6 Jun 2021 09:40:06 +0300 Subject: [PATCH] test --- redisgraph/edge.py | 2 +- redisgraph/graph.py | 38 +++++++++++++++++++++++++++++++++++--- redisgraph/node.py | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/redisgraph/edge.py b/redisgraph/edge.py index 8d0d2cd..7a638f8 100644 --- a/redisgraph/edge.py +++ b/redisgraph/edge.py @@ -12,7 +12,7 @@ def __init__(self, src_node, relation, dest_node, edge_id=None, """ Create a new edge. """ - if (src_node is None or dest_node is None): + if src_node is None or dest_node is None: # NOTE(bors-42): It makes sense to change AssertionError to # ValueError here raise AssertionError("Both src_node & dest_node must be provided") diff --git a/redisgraph/graph.py b/redisgraph/graph.py index 7653645..d62add9 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -13,6 +13,10 @@ class Graph: def __init__(self, name, redis_con): """ Create a new graph. + + Args: + name: string that represents the name of the graph + redis_con: connection to Redis """ self.name = name # Graph key self.redis_con = redis_con @@ -59,6 +63,12 @@ def _refresh_attributes(self): self._properties[i] = p[0] def get_label(self, idx): + """ + Returns a label by it's index + + Args: + idx: The index of the label + """ try: label = self._labels[idx] except IndexError: @@ -68,6 +78,12 @@ def get_label(self, idx): return label def get_relation(self, idx): + """ + Returns a relationship type by it's index + + Args: + idx: The index of the relation + """ try: relationshipType = self._relationshipTypes[idx] except IndexError: @@ -77,6 +93,12 @@ def get_relation(self, idx): return relationshipType def get_property(self, idx): + """ + Returns a property by it's index + + Args: + idx: The index of the property + """ try: propertie = self._properties[idx] except IndexError: @@ -130,7 +152,7 @@ def flush(self): self.nodes = {} self.edges = [] - def build_params_header(self, params): + def _build_params_header(self, params): if not isinstance(params, dict): raise TypeError("'params' must be a dict") # Header starts with "CYPHER" @@ -148,6 +170,12 @@ def build_params_header(self, params): def query(self, q, params=None, timeout=None, read_only=False): """ Executes a query against the graph. + + Args: + q: the query + params: query parameters + timeout: maximum runtime for read queries in milliseconds + read_only: executes a readonly query if set to True """ # maintain original 'q' @@ -155,7 +183,7 @@ def query(self, q, params=None, timeout=None, read_only=False): # handle query parameters if params is not None: - query = self.build_params_header(params) + query + query = self._build_params_header(params) + query # construct query command # ask for compact result-set format @@ -196,9 +224,13 @@ def execution_plan(self, query, params=None): """ Get the execution plan for given query, GRAPH.EXPLAIN returns an array of operations. + + Args: + query: the query that will be executed + params: query parameters """ if params is not None: - query = self.build_params_header(params) + query + query = self._build_params_header(params) + query plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query, query) return self._execution_plan_to_string(plan) diff --git a/redisgraph/node.py b/redisgraph/node.py index 76db17c..856d55e 100644 --- a/redisgraph/node.py +++ b/redisgraph/node.py @@ -3,7 +3,7 @@ class Node: """ - A node within the garph. + A node within the graph. """ def __init__(self, node_id=None, alias=None, label=None, properties=None): """