Skip to content

Commit 3dedf1f

Browse files
committed
Implement support for ValueType VALUE_POINT.
Currently, returning a point fails to parse. RedisGraph implements this value type as a 2-element array (see _ResultSet_CompactReplyWithPoint). In this client implementation, I parse that into a 2-element map[string]float64.
1 parent 852ca0d commit 3dedf1f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

client_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ func TestMap(t *testing.T) {
245245
assert.Equal(t, mapval, expected, "expecting a map projection")
246246
}
247247

248+
func TestPoint(t *testing.T) {
249+
createGraph()
250+
251+
q := "RETURN point({latitude: -33.8567844, longitude: 151.213108})"
252+
res, err := graph.Query(q)
253+
if err != nil {
254+
t.Error(err)
255+
}
256+
res.Next()
257+
r := res.Record()
258+
pointval := r.GetByIndex(0).(map[string]float64)
259+
260+
expected := map[string]float64{"latitude": -33.8567844, "longitude": 151.213108}
261+
assert.InDeltaMapValues(t, pointval, expected, 0.001, "expecting a point map")
262+
}
263+
248264
func TestPath(t *testing.T) {
249265
createGraph()
250266
q := "MATCH p = (:Person)-[:Visited]->(:Country) RETURN p"

query_result.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
VALUE_NODE
4646
VALUE_PATH
4747
VALUE_MAP
48+
VALUE_POINT
4849
)
4950

5051
type QueryResultHeader struct {
@@ -241,6 +242,16 @@ func (qr *QueryResult) parseMap(cell interface{}) map[string]interface{} {
241242
return parsed_map
242243
}
243244

245+
func (qr *QueryResult) parsePoint(cell interface{}) map[string]float64 {
246+
point := make(map[string]float64)
247+
var array = cell.([]interface{})
248+
if len(array) == 2 {
249+
point["latitude"], _ = redis.Float64(array[0], nil)
250+
point["longitude"], _ = redis.Float64(array[1], nil)
251+
}
252+
return point
253+
}
254+
244255
func (qr *QueryResult) parseScalar(cell []interface{}) interface{} {
245256
t, _ := redis.Int(cell[0], nil)
246257
v := cell[1]
@@ -276,6 +287,9 @@ func (qr *QueryResult) parseScalar(cell []interface{}) interface{} {
276287
case VALUE_MAP:
277288
s = qr.parseMap(v)
278289

290+
case VALUE_POINT:
291+
s = qr.parsePoint(v)
292+
279293
case VALUE_UNKNOWN:
280294
panic("Unknown scalar type\n")
281295
}

0 commit comments

Comments
 (0)