diff --git a/redisgraph/query_result.py b/redisgraph/query_result.py index 4d92f1f..7f9b4de 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: {"latitude": latitude, "longitude": longitude} + p["latitude"] = float(cell[0]) + p["longitude"] = 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") 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)