Skip to content
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

Implement support for ValueType VALUE_POINT. #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions query_result.go
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ const (
VALUE_NODE
VALUE_PATH
VALUE_MAP
VALUE_POINT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use ALL_CAPS in Go names; use CamelCase

)

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should always be true, but there is no harm in checking for it.

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")
}