Skip to content

Add support for Point datatype #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions redisgraph/query_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ResultSetScalarTypes:
VALUE_NODE = 8
VALUE_PATH = 9
VALUE_MAP = 10
VALUE_POINT = 11


class QueryResult:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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")

Expand Down
20 changes: 20 additions & 0 deletions tests/functional/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down