diff --git a/client_test.go b/client_test.go index 44ed0a3..7e0e407 100644 --- a/client_test.go +++ b/client_test.go @@ -265,6 +265,22 @@ func TestMap(t *testing.T) { assert.Equal(t, mapval, expected, "expecting a map projection") } +func TestPoint(t *testing.T) { + createGraph() + + q := "RETURN point({latitude: -33.8567844, longitude: 151.213108})" + res, err := graph.Query(q) + if err != nil { + t.Error(err) + } + res.Next() + r := res.Record() + pointval := r.GetByIndex(0).(map[string]float64) + + expected := map[string]float64{"latitude": -33.8567844, "longitude": 151.213108} + assert.InDeltaMapValues(t, pointval, expected, 0.001, "expecting a point map") +} + func TestPath(t *testing.T) { createGraph() q := "MATCH p = (:Person)-[:Visited]->(:Country) RETURN p" diff --git a/query_result.go b/query_result.go index f16fe4b..bf8bd0c 100644 --- a/query_result.go +++ b/query_result.go @@ -45,6 +45,7 @@ const ( VALUE_NODE VALUE_PATH VALUE_MAP + VALUE_POINT ) type QueryResultHeader struct { @@ -241,6 +242,16 @@ func (qr *QueryResult) parseMap(cell interface{}) map[string]interface{} { return parsed_map } +func (qr *QueryResult) parsePoint(cell interface{}) map[string]float64 { + point := make(map[string]float64) + var array = cell.([]interface{}) + if len(array) == 2 { + point["latitude"], _ = redis.Float64(array[0], nil) + point["longitude"], _ = redis.Float64(array[1], nil) + } + return point +} + func (qr *QueryResult) parseScalar(cell []interface{}) interface{} { t, _ := redis.Int(cell[0], nil) v := cell[1] @@ -276,6 +287,9 @@ func (qr *QueryResult) parseScalar(cell []interface{}) interface{} { case VALUE_MAP: s = qr.parseMap(v) + case VALUE_POINT: + s = qr.parsePoint(v) + case VALUE_UNKNOWN: panic("Unknown scalar type\n") }