From cb4f76705d218acd28f2fd85391bdbae48d9a086 Mon Sep 17 00:00:00 2001 From: DvirDukhan Date: Tue, 19 Jul 2022 23:12:37 +0300 Subject: [PATCH 1/6] grpah - add counters for removed labels and properties --- redis/commands/graph/query_result.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/redis/commands/graph/query_result.py b/redis/commands/graph/query_result.py index 644ac5a3db..e9adfe5682 100644 --- a/redis/commands/graph/query_result.py +++ b/redis/commands/graph/query_result.py @@ -9,10 +9,12 @@ from .path import Path LABELS_ADDED = "Labels added" +LABELS_REMOVED = "Labels removed" NODES_CREATED = "Nodes created" NODES_DELETED = "Nodes deleted" RELATIONSHIPS_DELETED = "Relationships deleted" PROPERTIES_SET = "Properties set" +PROPERTIES_REMOVED = "Properties removed" RELATIONSHIPS_CREATED = "Relationships created" INDICES_CREATED = "Indices created" INDICES_DELETED = "Indices deleted" @@ -21,8 +23,10 @@ STATS = [ LABELS_ADDED, + LABELS_REMOVED, NODES_CREATED, PROPERTIES_SET, + PROPERTIES_REMOVED, RELATIONSHIPS_CREATED, NODES_DELETED, RELATIONSHIPS_DELETED, @@ -325,6 +329,10 @@ def _get_stat(self, stat): def labels_added(self): return self._get_stat(LABELS_ADDED) + @property + def labels_removed(self): + return self._get_stat(LABELS_REMOVED) + @property def nodes_created(self): return self._get_stat(NODES_CREATED) @@ -337,6 +345,10 @@ def nodes_deleted(self): def properties_set(self): return self._get_stat(PROPERTIES_SET) + @property + def properties_removed(self): + return self._get_stat(PROPERTIES_REMOVED) + @property def relationships_created(self): return self._get_stat(RELATIONSHIPS_CREATED) From ebfa03adca5b3f6a6aba728a58810109a77db12c Mon Sep 17 00:00:00 2001 From: DvirDukhan Date: Mon, 25 Jul 2022 03:21:44 +0300 Subject: [PATCH 2/6] added mock graph result set statistics --- tests/test_graph.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_graph.py b/tests/test_graph.py index 76f8794c18..1651f91d3a 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -2,8 +2,10 @@ from redis.commands.graph import Edge, Node, Path from redis.commands.graph.execution_plan import Operation +from redis.commands.graph.query_result import * from redis.exceptions import ResponseError from tests.conftest import skip_if_redis_enterprise +from unittest.mock import patch @pytest.fixture @@ -575,3 +577,32 @@ def test_explain(client): assert result.structured_plan == expected redis_graph.delete() + +@pytest.mark.redismod +def test_resultset_statistics(client): + with patch.object(target = QueryResult, attribute = "_get_stat") as mock_get_stats: + result = client.graph().query("RETURN 1") + result.labels_added + mock_get_stats.assert_called_with(LABELS_ADDED) + result.labels_removed + mock_get_stats.assert_called_with(LABELS_REMOVED) + result.nodes_created + mock_get_stats.assert_called_with(NODES_CREATED) + result.nodes_deleted + mock_get_stats.assert_called_with(NODES_DELETED) + result.properties_set + mock_get_stats.assert_called_with(PROPERTIES_SET) + result.properties_removed + mock_get_stats.assert_called_with(PROPERTIES_REMOVED) + result.relationships_created + mock_get_stats.assert_called_with(RELATIONSHIPS_CREATED) + result.relationships_deleted + mock_get_stats.assert_called_with(RELATIONSHIPS_DELETED) + result.indices_created + mock_get_stats.assert_called_with(INDICES_CREATED) + result.indices_deleted + mock_get_stats.assert_called_with(INDICES_DELETED) + result.cached_execution + mock_get_stats.assert_called_with(CACHED_EXECUTION) + result.run_time_ms + mock_get_stats.assert_called_with(INTERNAL_EXECUTION_TIME) From 74635be3cc2dbc8d8ebbf5e0fc6b86815d180dab Mon Sep 17 00:00:00 2001 From: DvirDukhan Date: Mon, 25 Jul 2022 07:47:54 +0300 Subject: [PATCH 3/6] docstrings for graph result set statistics --- redis/commands/graph/query_result.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/redis/commands/graph/query_result.py b/redis/commands/graph/query_result.py index e9adfe5682..9c21b9dbd4 100644 --- a/redis/commands/graph/query_result.py +++ b/redis/commands/graph/query_result.py @@ -325,50 +325,61 @@ def _get_value(prop, statistics): def _get_stat(self, stat): return self.statistics[stat] if stat in self.statistics else 0 + '''Returns the number of labels added in the query''' @property def labels_added(self): return self._get_stat(LABELS_ADDED) + '''Returns the number of labels removed in the query''' @property def labels_removed(self): return self._get_stat(LABELS_REMOVED) - + '''Returns the number of nodes created in the query''' @property def nodes_created(self): return self._get_stat(NODES_CREATED) + '''Returns the number of nodes deleted in the query''' @property def nodes_deleted(self): return self._get_stat(NODES_DELETED) + '''Returns the number of properties set in the query''' @property def properties_set(self): return self._get_stat(PROPERTIES_SET) + '''Returns the number of properties removed in the query''' @property def properties_removed(self): return self._get_stat(PROPERTIES_REMOVED) + '''Returns the number of relationships created in the query''' @property def relationships_created(self): return self._get_stat(RELATIONSHIPS_CREATED) + '''Returns the number of relationships deleted in the query''' @property def relationships_deleted(self): return self._get_stat(RELATIONSHIPS_DELETED) + '''Returns the number of indices created in the query''' @property def indices_created(self): return self._get_stat(INDICES_CREATED) + '''Returns the number of indices deleted in the query''' @property def indices_deleted(self): return self._get_stat(INDICES_DELETED) + '''Returns whether or not the query execution plan was cached''' @property def cached_execution(self): return self._get_stat(CACHED_EXECUTION) == 1 + '''Returns the server execution time of the query''' @property def run_time_ms(self): return self._get_stat(INTERNAL_EXECUTION_TIME) From 15ca812f250088760e24e3b98c16a11d2cd19237 Mon Sep 17 00:00:00 2001 From: DvirDukhan Date: Mon, 25 Jul 2022 10:38:02 +0300 Subject: [PATCH 4/6] format --- redis/commands/graph/query_result.py | 37 +++++++++++++++++++--------- tests/test_graph.py | 19 ++++++++++++-- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/redis/commands/graph/query_result.py b/redis/commands/graph/query_result.py index 9c21b9dbd4..a1b228c59a 100644 --- a/redis/commands/graph/query_result.py +++ b/redis/commands/graph/query_result.py @@ -325,61 +325,74 @@ def _get_value(prop, statistics): def _get_stat(self, stat): return self.statistics[stat] if stat in self.statistics else 0 - '''Returns the number of labels added in the query''' + """Returns the number of labels added in the query""" + @property def labels_added(self): return self._get_stat(LABELS_ADDED) - '''Returns the number of labels removed in the query''' + """Returns the number of labels removed in the query""" + @property def labels_removed(self): return self._get_stat(LABELS_REMOVED) - '''Returns the number of nodes created in the query''' + + """Returns the number of nodes created in the query""" + @property def nodes_created(self): return self._get_stat(NODES_CREATED) - '''Returns the number of nodes deleted in the query''' + """Returns the number of nodes deleted in the query""" + @property def nodes_deleted(self): return self._get_stat(NODES_DELETED) - '''Returns the number of properties set in the query''' + """Returns the number of properties set in the query""" + @property def properties_set(self): return self._get_stat(PROPERTIES_SET) - '''Returns the number of properties removed in the query''' + """Returns the number of properties removed in the query""" + @property def properties_removed(self): return self._get_stat(PROPERTIES_REMOVED) - '''Returns the number of relationships created in the query''' + """Returns the number of relationships created in the query""" + @property def relationships_created(self): return self._get_stat(RELATIONSHIPS_CREATED) - '''Returns the number of relationships deleted in the query''' + """Returns the number of relationships deleted in the query""" + @property def relationships_deleted(self): return self._get_stat(RELATIONSHIPS_DELETED) - '''Returns the number of indices created in the query''' + """Returns the number of indices created in the query""" + @property def indices_created(self): return self._get_stat(INDICES_CREATED) - '''Returns the number of indices deleted in the query''' + """Returns the number of indices deleted in the query""" + @property def indices_deleted(self): return self._get_stat(INDICES_DELETED) - '''Returns whether or not the query execution plan was cached''' + """Returns whether or not the query execution plan was cached""" + @property def cached_execution(self): return self._get_stat(CACHED_EXECUTION) == 1 - '''Returns the server execution time of the query''' + """Returns the server execution time of the query""" + @property def run_time_ms(self): return self._get_stat(INTERNAL_EXECUTION_TIME) diff --git a/tests/test_graph.py b/tests/test_graph.py index 1651f91d3a..ed5af07303 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -2,7 +2,21 @@ from redis.commands.graph import Edge, Node, Path from redis.commands.graph.execution_plan import Operation -from redis.commands.graph.query_result import * +from redis.commands.graph.query_result import ( + QueryResult, + LABELS_ADDED, + LABELS_REMOVED, + NODES_CREATED, + NODES_DELETED, + RELATIONSHIPS_CREATED, + RELATIONSHIPS_DELETED, + PROPERTIES_SET, + PROPERTIES_REMOVED, + CACHED_EXECUTION, + INTERNAL_EXECUTION_TIME, + INDICES_CREATED, + INDICES_DELETED, +) from redis.exceptions import ResponseError from tests.conftest import skip_if_redis_enterprise from unittest.mock import patch @@ -578,9 +592,10 @@ def test_explain(client): redis_graph.delete() + @pytest.mark.redismod def test_resultset_statistics(client): - with patch.object(target = QueryResult, attribute = "_get_stat") as mock_get_stats: + with patch.object(target=QueryResult, attribute="_get_stat") as mock_get_stats: result = client.graph().query("RETURN 1") result.labels_added mock_get_stats.assert_called_with(LABELS_ADDED) From f58843d89910cf0f1f97465d48343725907bb41f Mon Sep 17 00:00:00 2001 From: DvirDukhan Date: Mon, 25 Jul 2022 10:40:54 +0300 Subject: [PATCH 5/6] isort --- tests/test_graph.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_graph.py b/tests/test_graph.py index ed5af07303..526308c672 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -1,25 +1,26 @@ +from unittest.mock import patch + import pytest from redis.commands.graph import Edge, Node, Path from redis.commands.graph.execution_plan import Operation from redis.commands.graph.query_result import ( - QueryResult, + CACHED_EXECUTION, + INDICES_CREATED, + INDICES_DELETED, + INTERNAL_EXECUTION_TIME, LABELS_ADDED, LABELS_REMOVED, NODES_CREATED, NODES_DELETED, + PROPERTIES_REMOVED, + PROPERTIES_SET, RELATIONSHIPS_CREATED, RELATIONSHIPS_DELETED, - PROPERTIES_SET, - PROPERTIES_REMOVED, - CACHED_EXECUTION, - INTERNAL_EXECUTION_TIME, - INDICES_CREATED, - INDICES_DELETED, + QueryResult, ) from redis.exceptions import ResponseError from tests.conftest import skip_if_redis_enterprise -from unittest.mock import patch @pytest.fixture From 6403620e76f89a7ae5394bb91a029987746c75a2 Mon Sep 17 00:00:00 2001 From: DvirDukhan Date: Tue, 26 Jul 2022 15:54:08 +0300 Subject: [PATCH 6/6] moved docstrings into functions --- redis/commands/graph/query_result.py | 36 ++++++++++------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/redis/commands/graph/query_result.py b/redis/commands/graph/query_result.py index a1b228c59a..3ffa664791 100644 --- a/redis/commands/graph/query_result.py +++ b/redis/commands/graph/query_result.py @@ -325,74 +325,62 @@ def _get_value(prop, statistics): def _get_stat(self, stat): return self.statistics[stat] if stat in self.statistics else 0 - """Returns the number of labels added in the query""" - @property def labels_added(self): + """Returns the number of labels added in the query""" return self._get_stat(LABELS_ADDED) - """Returns the number of labels removed in the query""" - @property def labels_removed(self): + """Returns the number of labels removed in the query""" return self._get_stat(LABELS_REMOVED) - """Returns the number of nodes created in the query""" - @property def nodes_created(self): + """Returns the number of nodes created in the query""" return self._get_stat(NODES_CREATED) - """Returns the number of nodes deleted in the query""" - @property def nodes_deleted(self): + """Returns the number of nodes deleted in the query""" return self._get_stat(NODES_DELETED) - """Returns the number of properties set in the query""" - @property def properties_set(self): + """Returns the number of properties set in the query""" return self._get_stat(PROPERTIES_SET) - """Returns the number of properties removed in the query""" - @property def properties_removed(self): + """Returns the number of properties removed in the query""" return self._get_stat(PROPERTIES_REMOVED) - """Returns the number of relationships created in the query""" - @property def relationships_created(self): + """Returns the number of relationships created in the query""" return self._get_stat(RELATIONSHIPS_CREATED) - """Returns the number of relationships deleted in the query""" - @property def relationships_deleted(self): + """Returns the number of relationships deleted in the query""" return self._get_stat(RELATIONSHIPS_DELETED) - """Returns the number of indices created in the query""" - @property def indices_created(self): + """Returns the number of indices created in the query""" return self._get_stat(INDICES_CREATED) - """Returns the number of indices deleted in the query""" - @property def indices_deleted(self): + """Returns the number of indices deleted in the query""" return self._get_stat(INDICES_DELETED) - """Returns whether or not the query execution plan was cached""" - @property def cached_execution(self): + """Returns whether or not the query execution plan was cached""" return self._get_stat(CACHED_EXECUTION) == 1 - """Returns the server execution time of the query""" - @property def run_time_ms(self): + """Returns the server execution time of the query""" return self._get_stat(INTERNAL_EXECUTION_TIME)