Skip to content

Commit 0d6a465

Browse files
authored
Merge pull request #8 from RedisGraph/new-resultset-structure
resultset might include numeric values in addition to strings
2 parents f4340a2 + d51ee6e commit 0d6a465

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

client.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"os"
77
"strings"
8+
"strconv"
9+
810

911
"github.com/gomodule/redigo/redis"
1012
"github.com/olekukonko/tablewriter"
@@ -192,19 +194,47 @@ func (g *Graph) Query(q string) (QueryResult, error) {
192194
return qr, err
193195
}
194196

197+
// Result-set is an array of arrays.
195198
results, err := redis.Values(r[0], nil)
196199
if err != nil {
197200
return qr, err
198201
}
199202

200-
qr.Results = make([][]string, len(results))
203+
records := make([][]interface{}, len(results))
204+
201205
for i, result := range results {
202-
qr.Results[i], err = redis.Strings(result, nil)
206+
// Parse each record.
207+
records[i], err = redis.Values(result, nil)
203208
if err != nil {
204209
return qr, err
205210
}
206211
}
207212

213+
// Convert each record item to string.
214+
qr.Results = make([][]string, len(records))
215+
for i, record := range records {
216+
qr.Results[i] = make([]string, len(record))
217+
for j, item := range record {
218+
switch item.(type) {
219+
case int64:
220+
n, err := redis.Int64(item, nil)
221+
if err != nil {
222+
return qr, err
223+
}
224+
qr.Results[i][j] = strconv.FormatInt(n, 10)
225+
break
226+
227+
case string:
228+
qr.Results[i][j], err = redis.String(item, nil)
229+
break
230+
231+
default:
232+
qr.Results[i][j], err = redis.String(item, nil)
233+
break
234+
}
235+
}
236+
}
237+
208238
qr.Statistics, err = redis.Strings(r[1], nil)
209239
if err != nil {
210240
return qr, err

client_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func TestFlush(t *testing.T) {
7171
rg := Graph{}.New("rubbles", conn)
7272
users := [3]string{"Barney", "Betty", "Bam-Bam"}
7373
for _, user := range users {
74-
7574
family := Node{
7675
Label: "person",
7776
Properties: map[string]interface{}{

0 commit comments

Comments
 (0)