Skip to content

Commit f8ecfaa

Browse files
Add support for Point datatype (#121)
* Add support for Point datatype * point returned as a map with keys: lat,lon Co-authored-by: swilly22 <roi@redislabs.com>
1 parent 5238a92 commit f8ecfaa

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

redisgraph/query_result.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ResultSetScalarTypes:
4141
VALUE_NODE = 8
4242
VALUE_PATH = 9
4343
VALUE_MAP = 10
44+
VALUE_POINT = 11
4445

4546

4647
class QueryResult:
@@ -179,6 +180,14 @@ def parse_map(self, cell):
179180

180181
return m
181182

183+
def parse_point(self, cell):
184+
p = {}
185+
# A point is received an array of the form: [latitude, longitude]
186+
# It is returned as a map of the form: {"latitude": latitude, "longitude": longitude}
187+
p["latitude"] = float(cell[0])
188+
p["longitude"] = float(cell[1])
189+
return p
190+
182191
def parse_scalar(self, cell):
183192
scalar_type = int(cell[0])
184193
value = cell[1]
@@ -223,6 +232,9 @@ def parse_scalar(self, cell):
223232
elif scalar_type == ResultSetScalarTypes.VALUE_MAP:
224233
scalar = self.parse_map(value)
225234

235+
elif scalar_type == ResultSetScalarTypes.VALUE_POINT:
236+
scalar = self.parse_point(value)
237+
226238
elif scalar_type == ResultSetScalarTypes.VALUE_UNKNOWN:
227239
print("Unknown scalar type\n")
228240

tests/functional/test_all.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ def test_map(self):
115115
# All done, remove graph.
116116
redis_graph.delete()
117117

118+
def test_point(self):
119+
redis_graph = Graph('map', self.r)
120+
121+
query = "RETURN point({latitude: 32.070794860, longitude: 34.820751118})"
122+
expected_lat = 32.070794860
123+
expected_lon = 34.820751118
124+
actual = redis_graph.query(query).result_set[0][0]
125+
self.assertTrue(abs(actual['latitude'] - expected_lat) < 0.001)
126+
self.assertTrue(abs(actual['longitude'] - expected_lon) < 0.001)
127+
128+
query = "RETURN point({latitude: 32, longitude: 34.0})"
129+
expected_lat = 32
130+
expected_lon = 34
131+
actual = redis_graph.query(query).result_set[0][0]
132+
self.assertTrue(abs(actual['latitude'] - expected_lat) < 0.001)
133+
self.assertTrue(abs(actual['longitude'] - expected_lon) < 0.001)
134+
135+
# All done, remove graph.
136+
redis_graph.delete()
137+
118138
def test_index_response(self):
119139
redis_graph = Graph('social', self.r)
120140

0 commit comments

Comments
 (0)