From 94df38782b2afe51f7408ce0f2473dd898f9182e Mon Sep 17 00:00:00 2001 From: Jeffrey Lovitz Date: Wed, 17 Feb 2021 16:28:55 -0500 Subject: [PATCH 1/2] Add support for Point datatype --- redisgraph/query_result.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/redisgraph/query_result.py b/redisgraph/query_result.py index 4d92f1f..2e610c1 100644 --- a/redisgraph/query_result.py +++ b/redisgraph/query_result.py @@ -41,6 +41,7 @@ class ResultSetScalarTypes: VALUE_NODE = 8 VALUE_PATH = 9 VALUE_MAP = 10 + VALUE_POINT = 11 class QueryResult: @@ -179,6 +180,14 @@ def parse_map(self, cell): return m + def parse_point(self, cell): + p = {} + # A point is received an array of the form: [latitude, longitude] + # It is returned as a map of the form: {"x": latitude, "y": longitude} + p["x"] = float(cell[0]) + p["y"] = float(cell[1]) + return p + def parse_scalar(self, cell): scalar_type = int(cell[0]) value = cell[1] @@ -223,6 +232,9 @@ def parse_scalar(self, cell): elif scalar_type == ResultSetScalarTypes.VALUE_MAP: scalar = self.parse_map(value) + elif scalar_type == ResultSetScalarTypes.VALUE_POINT: + scalar = self.parse_point(value) + elif scalar_type == ResultSetScalarTypes.VALUE_UNKNOWN: print("Unknown scalar type\n") From 207eff27e9b1db1d5ff71c6113c72c9f016c784f Mon Sep 17 00:00:00 2001 From: swilly22 Date: Thu, 18 Feb 2021 10:54:27 +0200 Subject: [PATCH 2/2] point returned as a map with keys: lat,lon --- redisgraph/query_result.py | 6 +++--- tests/functional/test_all.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/redisgraph/query_result.py b/redisgraph/query_result.py index 2e610c1..7f9b4de 100644 --- a/redisgraph/query_result.py +++ b/redisgraph/query_result.py @@ -183,9 +183,9 @@ def parse_map(self, cell): def parse_point(self, cell): p = {} # A point is received an array of the form: [latitude, longitude] - # It is returned as a map of the form: {"x": latitude, "y": longitude} - p["x"] = float(cell[0]) - p["y"] = float(cell[1]) + # It is returned as a map of the form: {"latitude": latitude, "longitude": longitude} + p["latitude"] = float(cell[0]) + p["longitude"] = float(cell[1]) return p def parse_scalar(self, cell): diff --git a/tests/functional/test_all.py b/tests/functional/test_all.py index 422448a..865ea9c 100644 --- a/tests/functional/test_all.py +++ b/tests/functional/test_all.py @@ -115,6 +115,26 @@ def test_map(self): # All done, remove graph. redis_graph.delete() + def test_point(self): + redis_graph = Graph('map', self.r) + + query = "RETURN point({latitude: 32.070794860, longitude: 34.820751118})" + expected_lat = 32.070794860 + expected_lon = 34.820751118 + actual = redis_graph.query(query).result_set[0][0] + self.assertTrue(abs(actual['latitude'] - expected_lat) < 0.001) + self.assertTrue(abs(actual['longitude'] - expected_lon) < 0.001) + + query = "RETURN point({latitude: 32, longitude: 34.0})" + expected_lat = 32 + expected_lon = 34 + actual = redis_graph.query(query).result_set[0][0] + self.assertTrue(abs(actual['latitude'] - expected_lat) < 0.001) + self.assertTrue(abs(actual['longitude'] - expected_lon) < 0.001) + + # All done, remove graph. + redis_graph.delete() + def test_index_response(self): redis_graph = Graph('social', self.r)