From f701bd276f6bf89ac4005672f5186b437250dbda Mon Sep 17 00:00:00 2001 From: Avi Avni Date: Thu, 21 Oct 2021 15:06:15 +0300 Subject: [PATCH 1/6] multi label api change --- client_test.go | 62 +++++++++---------- example_graph_test.go | 11 ++-- .../redisgraph_tls_client.go | 7 ++- node.go | 10 +-- query_result.go | 30 ++++----- 5 files changed, 61 insertions(+), 59 deletions(-) diff --git a/client_test.go b/client_test.go index 85effbe..e4b7523 100644 --- a/client_test.go +++ b/client_test.go @@ -16,8 +16,8 @@ func createGraph() { graph = GraphNew("social", conn) // Create 2 nodes connect via a single edge. - japan := NodeNew("Country", "j", nil) - john := NodeNew("Person", "p", nil) + japan := NodeNew([]string{"Country"}, "j", nil) + john := NodeNew([]string{"Person"}, "p", nil) edge := EdgeNew("Visited", john, japan, nil) // Set node properties. @@ -91,9 +91,9 @@ func checkQueryResults(t *testing.T, res *QueryResult) { d, ok := r.GetByIndex(2).(*Node) assert.True(t, ok, "Third column should contain nodes.") - assert.Equal(t, s.Label, "Person", "Node should be of type 'Person'") + assert.Equal(t, s.Labels[0], "Person", "Node should be of type 'Person'") assert.Equal(t, e.Relation, "Visited", "Edge should be of relation type 'Visited'") - assert.Equal(t, d.Label, "Country", "Node should be of type 'Country'") + assert.Equal(t, d.Labels[0], "Country", "Node should be of type 'Country'") assert.Equal(t, len(s.Properties), 4, "Person node should have 4 properties") @@ -131,7 +131,7 @@ func TestCreateQuery(t *testing.T) { res.Next() r := res.Record() w := r.GetByIndex(0).(*Node) - assert.Equal(t, w.Label, "WorkPlace", "Unexpected node label.") + assert.Equal(t, w.Labels[0], "WorkPlace", "Unexpected node label.") } func TestCreateROQueryFailure(t *testing.T) { @@ -199,8 +199,8 @@ func TestArray(t *testing.T) { t.Error(err) } - a := NodeNew("person", "", nil) - b := NodeNew("person", "", nil) + a := NodeNew([]string{"person"}, "", nil) + b := NodeNew([]string{"person"}, "", nil) a.SetProperty("name", "a") a.SetProperty("age", 32) @@ -288,9 +288,9 @@ func TestPath(t *testing.T) { e := p.GetEdge(0) d := p.LastNode() - assert.Equal(t, s.Label, "Person", "Node should be of type 'Person'") + assert.Equal(t, s.Labels[0], "Person", "Node should be of type 'Person'") assert.Equal(t, e.Relation, "Visited", "Edge should be of relation type 'Visited'") - assert.Equal(t, d.Label, "Country", "Node should be of type 'Country'") + assert.Equal(t, d.Labels[0], "Country", "Node should be of type 'Country'") assert.Equal(t, len(s.Properties), 4, "Person node should have 4 properties") @@ -308,12 +308,12 @@ func TestPath(t *testing.T) { func TestParameterizedQuery(t *testing.T) { createGraph() - params := []interface{}{1, 2.3, "str", true, false, nil, []interface {}{0, 1, 2}, []interface {}{"0", "1", "2"}} + params := []interface{}{1, 2.3, "str", true, false, nil, []interface{}{0, 1, 2}, []interface{}{"0", "1", "2"}} q := "RETURN $param" params_map := make(map[string]interface{}) for index, param := range params { params_map["param"] = param - res, err := graph.ParameterizedQuery(q, params_map); + res, err := graph.ParameterizedQuery(q, params_map) if err != nil { t.Error(err) } @@ -348,24 +348,24 @@ func TestCreateIndex(t *testing.T) { func TestQueryStatistics(t *testing.T) { graph.Flush() err := graph.Delete() - assert.Nil(t,err) + assert.Nil(t, err) q := "CREATE (:Person{name:'a',age:32,array:[0,1,2]})" res, err := graph.Query(q) - assert.Nil(t,err) + assert.Nil(t, err) assert.Equal(t, 1, res.NodesCreated(), "Expecting 1 node created") assert.Equal(t, 0, res.NodesDeleted(), "Expecting 0 nodes deleted") - assert.Greater(t, res.InternalExecutionTime(),0.0, "Expecting internal execution time not to be 0.0") + assert.Greater(t, res.InternalExecutionTime(), 0.0, "Expecting internal execution time not to be 0.0") assert.Equal(t, true, res.Empty(), "Expecting empty resultset") - res,err = graph.Query("MATCH (n) DELETE n") - assert.Nil(t,err) + res, err = graph.Query("MATCH (n) DELETE n") + assert.Nil(t, err) assert.Equal(t, 1, res.NodesDeleted(), "Expecting 1 nodes deleted") // Create 2 nodes connect via a single edge. - japan := NodeNew("Country", "j", nil) - john := NodeNew("Person", "p", nil) + japan := NodeNew([]string{"Country"}, "j", nil) + john := NodeNew([]string{"Person"}, "p", nil) edge := EdgeNew("Visited", john, japan, nil) // Set node properties. @@ -386,21 +386,21 @@ func TestQueryStatistics(t *testing.T) { // Flush graph to DB. res, err = graph.Commit() - assert.Nil(t,err) + assert.Nil(t, err) assert.Equal(t, 2, res.NodesCreated(), "Expecting 2 node created") assert.Equal(t, 0, res.NodesDeleted(), "Expecting 0 nodes deleted") assert.Equal(t, 7, res.PropertiesSet(), "Expecting 7 properties set") assert.Equal(t, 1, res.RelationshipsCreated(), "Expecting 1 relationships created") assert.Equal(t, 0, res.RelationshipsDeleted(), "Expecting 0 relationships deleted") - assert.Greater(t, res.InternalExecutionTime(),0.0, "Expecting internal execution time not to be 0.0") + assert.Greater(t, res.InternalExecutionTime(), 0.0, "Expecting internal execution time not to be 0.0") assert.Equal(t, true, res.Empty(), "Expecting empty resultset") q = "MATCH p = (:Person)-[:Visited]->(:Country) RETURN p" res, err = graph.Query(q) - assert.Nil(t,err) + assert.Nil(t, err) assert.Equal(t, len(res.results), 1, "expecting 1 result record") assert.Equal(t, false, res.Empty(), "Expecting resultset to have records") - res,err = graph.Query("MATCH ()-[r]-() DELETE r") - assert.Nil(t,err) + res, err = graph.Query("MATCH ()-[r]-() DELETE r") + assert.Nil(t, err) assert.Equal(t, 1, res.RelationshipsDeleted(), "Expecting 1 relationships deleted") } @@ -410,9 +410,9 @@ func TestUtils(t *testing.T) { res = ToString("test_string") assert.Equal(t, res, "\"test_string\"") - + res = ToString(10) - assert.Equal(t, res, "10") + assert.Equal(t, res, "10") res = ToString(1.2) assert.Equal(t, res, "1.2") @@ -420,12 +420,12 @@ func TestUtils(t *testing.T) { res = ToString(true) assert.Equal(t, res, "true") - var arr = []interface{}{1,2,3,"boom"} + var arr = []interface{}{1, 2, 3, "boom"} res = ToString(arr) assert.Equal(t, res, "[1,2,3,\"boom\"]") - + jsonMap := make(map[string]interface{}) - jsonMap["object"] = map[string]interface{} {"foo": 1} + jsonMap["object"] = map[string]interface{}{"foo": 1} res = ToString(jsonMap) assert.Equal(t, res, "{object: {foo: 1}}") } @@ -436,13 +436,13 @@ func TestNodeMapDatatype(t *testing.T) { assert.Nil(t, err) // Create 2 nodes connect via a single edge. - japan := NodeNew("Country", "j", + japan := NodeNew([]string{"Country"}, "j", map[string]interface{}{ "name": "Japan", "population": 126800000, "states": []string{"Kanto", "Chugoku"}, }) - john := NodeNew("Person", "p", + john := NodeNew([]string{"Person"}, "p", map[string]interface{}{ "name": "John Doe", "age": 33, @@ -488,7 +488,7 @@ func TestTimeout(t *testing.T) { params := make(map[string]interface{}) params["ub"] = 1000000 - res, err = graph.ParameterizedQueryWithOptions("UNWIND range(0, $ub) AS v RETURN v", params, options); + res, err = graph.ParameterizedQueryWithOptions("UNWIND range(0, $ub) AS v RETURN v", params, options) assert.Nil(t, res) assert.NotNil(t, err) } diff --git a/example_graph_test.go b/example_graph_test.go index c475ee3..7bb1876 100644 --- a/example_graph_test.go +++ b/example_graph_test.go @@ -4,11 +4,12 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "github.com/RedisGraph/redisgraph-go" - "github.com/gomodule/redigo/redis" "io/ioutil" "log" "os" + + "github.com/RedisGraph/redisgraph-go" + "github.com/gomodule/redigo/redis" ) func ExampleGraphNew() { @@ -22,7 +23,7 @@ func ExampleGraphNew() { res.Next() r := res.Record() w := r.GetByIndex(0).(*redisgraph.Node) - fmt.Println(w.Label) + fmt.Println(w.Labels[0]) // Output: WorkPlace } @@ -40,7 +41,7 @@ func ExampleGraphNew_pool() { res.Next() r := res.Record() w := r.GetByIndex(0).(*redisgraph.Node) - fmt.Println(w.Label) + fmt.Println(w.Labels[0]) // Output: WorkPlace } @@ -103,7 +104,7 @@ func ExampleGraphNew_tls() { res.Next() r := res.Record() w := r.GetByIndex(0).(*redisgraph.Node) - fmt.Println(w.Label) + fmt.Println(w.Labels[0]) } func getConnectionDetails() (host string, password string) { diff --git a/examples/redisgraph_tls_client/redisgraph_tls_client.go b/examples/redisgraph_tls_client/redisgraph_tls_client.go index 769b7d3..f3b03b0 100644 --- a/examples/redisgraph_tls_client/redisgraph_tls_client.go +++ b/examples/redisgraph_tls_client/redisgraph_tls_client.go @@ -5,11 +5,12 @@ import ( "crypto/x509" "flag" "fmt" - "github.com/RedisGraph/redisgraph-go" - "github.com/gomodule/redigo/redis" "io/ioutil" "log" "os" + + "github.com/RedisGraph/redisgraph-go" + "github.com/gomodule/redigo/redis" ) var ( @@ -85,6 +86,6 @@ func main() { res.Next() r := res.Record() w := r.GetByIndex(0).(*redisgraph.Node) - fmt.Println(w.Label) + fmt.Println(w.Labels[0]) // Output: WorkPlace } diff --git a/node.go b/node.go index 50f7308..f34bda7 100644 --- a/node.go +++ b/node.go @@ -8,13 +8,13 @@ import ( // Node represents a node within a graph. type Node struct { ID uint64 - Label string + Labels []string Alias string Properties map[string]interface{} graph *Graph } -func NodeNew(label string, alias string, properties map[string]interface{}) *Node { +func NodeNew(labels []string, alias string, properties map[string]interface{}) *Node { p := properties if p == nil { @@ -22,7 +22,7 @@ func NodeNew(label string, alias string, properties map[string]interface{}) *Nod } return &Node{ - Label: label, + Labels: labels, Alias: alias, Properties: p, graph: nil, @@ -60,8 +60,8 @@ func (n Node) Encode() string { s = append(s, n.Alias) } - if n.Label != "" { - s = append(s, ":", n.Label) + for _, label := range n.Labels { + s = append(s, ":", label) } if len(n.Properties) > 0 { diff --git a/query_result.go b/query_result.go index f16fe4b..8408f93 100644 --- a/query_result.go +++ b/query_result.go @@ -5,6 +5,7 @@ import ( "os" "strconv" "strings" + "github.com/gomodule/redigo/redis" "github.com/olekukonko/tablewriter" ) @@ -16,10 +17,10 @@ const ( RELATIONSHIPS_DELETED string = "Relationships deleted" PROPERTIES_SET string = "Properties set" RELATIONSHIPS_CREATED string = "Relationships created" - INDICES_CREATED string = "Indices created" - INDICES_DELETED string = "Indices deleted" + INDICES_CREATED string = "Indices created" + INDICES_DELETED string = "Indices deleted" INTERNAL_EXECUTION_TIME string = "Query internal execution time" - CACHED_EXECUTION string = "Cached execution" + CACHED_EXECUTION string = "Cached execution" ) type ResultSetColumnTypes int @@ -54,11 +55,11 @@ type QueryResultHeader struct { // QueryResult represents the results of a query. type QueryResult struct { - graph *Graph - header QueryResultHeader - results []*Record - statistics map[string]float64 - current_record_idx int + graph *Graph + header QueryResultHeader + results []*Record + statistics map[string]float64 + current_record_idx int } func QueryResultNew(g *Graph, response interface{}) (*QueryResult, error) { @@ -69,7 +70,7 @@ func QueryResultNew(g *Graph, response interface{}) (*QueryResult, error) { column_names: make([]string, 0), column_types: make([]ResultSetColumnTypes, 0), }, - graph: g, + graph: g, current_record_idx: -1, } @@ -172,18 +173,18 @@ func (qr *QueryResult) parseNode(cell interface{}) *Node { // [label string offset (integer)], // [[name, value type, value] X N] - var label string c, _ := redis.Values(cell, nil) id, _ := redis.Uint64(c[0], nil) - labels, _ := redis.Ints(c[1], nil) - if len(labels) > 0 { - label = qr.graph.getLabel(labels[0]) + label_ids, _ := redis.Ints(c[1], nil) + labels := make([]string, len(label_ids)) + for i := 0; i < len(label_ids); i++ { + labels[i] = qr.graph.getLabel(label_ids[i]) } rawProps, _ := redis.Values(c[2], nil) properties := qr.parseProperties(rawProps) - n := NodeNew(label, "", properties) + n := NodeNew(labels, "", properties) n.ID = id return n } @@ -386,4 +387,3 @@ func (qr *QueryResult) InternalExecutionTime() float64 { func (qr *QueryResult) CachedExecution() int { return int(qr.getStat(CACHED_EXECUTION)) } - From 934d4a1ce8739e50207548d298e9a51ca7b47ea8 Mon Sep 17 00:00:00 2001 From: swilly22 Date: Mon, 30 May 2022 09:22:29 +0300 Subject: [PATCH 2/6] multi-label test --- client_test.go | 23 +++++++++++++++++++++++ edge.go | 7 +++++++ node.go | 8 ++++++-- query_result.go | 10 +++++----- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/client_test.go b/client_test.go index e4b7523..34c73c6 100644 --- a/client_test.go +++ b/client_test.go @@ -430,6 +430,29 @@ func TestUtils(t *testing.T) { assert.Equal(t, res, "{object: {foo: 1}}") } +func TestMultiLabelNode(t *testing.T) { + // clear database + graph.Flush() + err := graph.Delete() + assert.Nil(t, err) + + // create a multi label node + multiLabelNode := NodeNew([]string{"A","B"}, nil) + graph.AddNode(multiLabelNode) + res, err := graph.Commit() + + // fetch node + res, err = graph.Query("MATCH (n) RETURN n") + res.Next() + r := res.Record() + n := r.GetByIndex(0).(*Node) + + // expecting 2 labels + assert.Equal(t, len(n.Labels), 2, "expecting 2 labels") + assert.Equal(t, n.Labels[0], "A") + assert.Equal(t, n.Labels[1], "B") +} + func TestNodeMapDatatype(t *testing.T) { graph.Flush() err := graph.Delete() diff --git a/edge.go b/edge.go index 95b79f8..e3994ae 100644 --- a/edge.go +++ b/edge.go @@ -17,6 +17,7 @@ type Edge struct { graph *Graph } +// Create a new Edge func EdgeNew(relation string, srcNode *Node, destNode *Node, properties map[string]interface{}) *Edge { p := properties if p == nil { @@ -32,15 +33,18 @@ func EdgeNew(relation string, srcNode *Node, destNode *Node, properties map[stri } } +// Assign a new property to edge func (e *Edge) SetProperty(key string, value interface{}) { e.Properties[key] = value } +// Retrieves property from edge func (e *Edge) GetProperty(key string) interface{} { v, _ := e.Properties[key] return v } +// Returns edge source node ID func (e Edge) SourceNodeID() uint64 { if e.Source != nil { return e.Source.ID @@ -49,6 +53,7 @@ func (e Edge) SourceNodeID() uint64 { } } +// Returns edge destination node ID func (e Edge) DestNodeID() uint64 { if e.Source != nil { return e.Destination.ID @@ -57,6 +62,7 @@ func (e Edge) DestNodeID() uint64 { } } +// Returns a string representation of edge func (e Edge) String() string { if len(e.Properties) == 0 { return "{}" @@ -71,6 +77,7 @@ func (e Edge) String() string { return s } +// String makes Edge satisfy the Stringer interface func (e Edge) Encode() string { s := []string{"(", e.Source.Alias, ")"} diff --git a/node.go b/node.go index f34bda7..8fc3304 100644 --- a/node.go +++ b/node.go @@ -5,7 +5,7 @@ import ( "strings" ) -// Node represents a node within a graph. +// Node represents a node within a graph type Node struct { ID uint64 Labels []string @@ -14,6 +14,7 @@ type Node struct { graph *Graph } +// Create a new Node func NodeNew(labels []string, alias string, properties map[string]interface{}) *Node { p := properties @@ -29,15 +30,18 @@ func NodeNew(labels []string, alias string, properties map[string]interface{}) * } } +// Asssign a new property to node func (n *Node) SetProperty(key string, value interface{}) { n.Properties[key] = value } +// Retrieves property from node func (n Node) GetProperty(key string) interface{} { v, _ := n.Properties[key] return v } +// Returns a string representation of a node func (n Node) String() string { if len(n.Properties) == 0 { return "{}" @@ -52,7 +56,7 @@ func (n Node) String() string { return s } -// String makes Node satisfy the Stringer interface. +// String makes Node satisfy the Stringer interface func (n Node) Encode() string { s := []string{"("} diff --git a/query_result.go b/query_result.go index 8408f93..0a51da0 100644 --- a/query_result.go +++ b/query_result.go @@ -59,7 +59,7 @@ type QueryResult struct { header QueryResultHeader results []*Record statistics map[string]float64 - current_record_idx int + currentRecordIdx int } func QueryResultNew(g *Graph, response interface{}) (*QueryResult, error) { @@ -175,10 +175,10 @@ func (qr *QueryResult) parseNode(cell interface{}) *Node { c, _ := redis.Values(cell, nil) id, _ := redis.Uint64(c[0], nil) - label_ids, _ := redis.Ints(c[1], nil) - labels := make([]string, len(label_ids)) - for i := 0; i < len(label_ids); i++ { - labels[i] = qr.graph.getLabel(label_ids[i]) + labelIds, _ := redis.Ints(c[1], nil) + labels := make([]string, len(labelIds)) + for i := 0; i < len(labelIds); i++ { + labels[i] = qr.graph.getLabel(labelIds[i]) } rawProps, _ := redis.Values(c[2], nil) From 56b43abdbcf8a2c96be271bfe6524fce651bdf5b Mon Sep 17 00:00:00 2001 From: swilly22 Date: Mon, 30 May 2022 09:27:47 +0300 Subject: [PATCH 3/6] comments --- edge.go | 12 ++++++------ node.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/edge.go b/edge.go index e3994ae..724dbc7 100644 --- a/edge.go +++ b/edge.go @@ -17,7 +17,7 @@ type Edge struct { graph *Graph } -// Create a new Edge +// EdgeNew create a new Edge func EdgeNew(relation string, srcNode *Node, destNode *Node, properties map[string]interface{}) *Edge { p := properties if p == nil { @@ -33,18 +33,18 @@ func EdgeNew(relation string, srcNode *Node, destNode *Node, properties map[stri } } -// Assign a new property to edge +// SetProperty assign a new property to edge func (e *Edge) SetProperty(key string, value interface{}) { e.Properties[key] = value } -// Retrieves property from edge +// GetProperty retrieves property from edge func (e *Edge) GetProperty(key string) interface{} { v, _ := e.Properties[key] return v } -// Returns edge source node ID +// SourceNodeID returns edge source node ID func (e Edge) SourceNodeID() uint64 { if e.Source != nil { return e.Source.ID @@ -53,7 +53,7 @@ func (e Edge) SourceNodeID() uint64 { } } -// Returns edge destination node ID +// DestNodeID returns edge destination node ID func (e Edge) DestNodeID() uint64 { if e.Source != nil { return e.Destination.ID @@ -77,7 +77,7 @@ func (e Edge) String() string { return s } -// String makes Edge satisfy the Stringer interface +// Encode makes Edge satisfy the Stringer interface func (e Edge) Encode() string { s := []string{"(", e.Source.Alias, ")"} diff --git a/node.go b/node.go index 8fc3304..b6f6f81 100644 --- a/node.go +++ b/node.go @@ -14,7 +14,7 @@ type Node struct { graph *Graph } -// Create a new Node +// NodeNew create a new Node func NodeNew(labels []string, alias string, properties map[string]interface{}) *Node { p := properties @@ -30,12 +30,12 @@ func NodeNew(labels []string, alias string, properties map[string]interface{}) * } } -// Asssign a new property to node +// SetProperty asssign a new property to node func (n *Node) SetProperty(key string, value interface{}) { n.Properties[key] = value } -// Retrieves property from node +// GetProperty retrieves property from node func (n Node) GetProperty(key string) interface{} { v, _ := n.Properties[key] return v @@ -56,7 +56,7 @@ func (n Node) String() string { return s } -// String makes Node satisfy the Stringer interface +// Encode makes Node satisfy the Stringer interface func (n Node) Encode() string { s := []string{"("} From e7bc30afa4a4d2e50e760ede4194285f6f27b8e0 Mon Sep 17 00:00:00 2001 From: swilly22 Date: Mon, 30 May 2022 09:31:03 +0300 Subject: [PATCH 4/6] rewrite --- client_test.go | 2 +- query_result.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client_test.go b/client_test.go index 34c73c6..84fd2da 100644 --- a/client_test.go +++ b/client_test.go @@ -437,7 +437,7 @@ func TestMultiLabelNode(t *testing.T) { assert.Nil(t, err) // create a multi label node - multiLabelNode := NodeNew([]string{"A","B"}, nil) + multiLabelNode := NodeNew([]string{"A","B"}, "n", nil) graph.AddNode(multiLabelNode) res, err := graph.Commit() diff --git a/query_result.go b/query_result.go index 0a51da0..2c36514 100644 --- a/query_result.go +++ b/query_result.go @@ -71,7 +71,7 @@ func QueryResultNew(g *Graph, response interface{}) (*QueryResult, error) { column_types: make([]ResultSetColumnTypes, 0), }, graph: g, - current_record_idx: -1, + currentRecordIdx: -1, } r, _ := redis.Values(response, nil) @@ -297,8 +297,8 @@ func (qr *QueryResult) Next() bool { if qr.Empty() { return false } - if qr.current_record_idx < len(qr.results)-1 { - qr.current_record_idx++ + if qr.currentRecordIdx < len(qr.results)-1 { + qr.currentRecordIdx++ return true } else { return false @@ -307,8 +307,8 @@ func (qr *QueryResult) Next() bool { // Record returns the current record. func (qr *QueryResult) Record() *Record { - if qr.current_record_idx >= 0 && qr.current_record_idx < len(qr.results) { - return qr.results[qr.current_record_idx] + if qr.currentRecordIdx >= 0 && qr.currentRecordIdx < len(qr.results) { + return qr.results[qr.currentRecordIdx] } else { return nil } From 69414595c2480e8c55ebe1e3b79e6348ff1ce8a2 Mon Sep 17 00:00:00 2001 From: swilly22 Date: Mon, 30 May 2022 09:48:24 +0300 Subject: [PATCH 5/6] clear internal mappings upon deletion --- graph.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/graph.go b/graph.go index bc3e6b9..3115ae9 100644 --- a/graph.go +++ b/graph.go @@ -75,6 +75,12 @@ func (g *Graph) ExecutionPlan(q string) (string, error) { // Delete removes the graph. func (g *Graph) Delete() error { _, err := g.Conn.Do("GRAPH.DELETE", g.Id) + + // clear internal mappings + g.labels = g.labels[:0] + g.properties = g.properties[:0] + g.relationshipTypes = g.relationshipTypes[:0] + return err } From 69b85d14c5925f482be9b029fe4cdea3ca4a90ed Mon Sep 17 00:00:00 2001 From: swilly22 Date: Mon, 30 May 2022 10:01:24 +0300 Subject: [PATCH 6/6] address deepsource comments --- client_test.go | 7 +++++-- graph.go | 2 +- query_result.go | 3 --- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client_test.go b/client_test.go index 84fd2da..241918c 100644 --- a/client_test.go +++ b/client_test.go @@ -439,10 +439,13 @@ func TestMultiLabelNode(t *testing.T) { // create a multi label node multiLabelNode := NodeNew([]string{"A","B"}, "n", nil) graph.AddNode(multiLabelNode) - res, err := graph.Commit() + _, err = graph.Commit() + assert.Nil(t, err) // fetch node - res, err = graph.Query("MATCH (n) RETURN n") + res, err := graph.Query("MATCH (n) RETURN n") + assert.Nil(t, err) + res.Next() r := res.Record() n := r.GetByIndex(0).(*Node) diff --git a/graph.go b/graph.go index 3115ae9..0cc8069 100644 --- a/graph.go +++ b/graph.go @@ -272,7 +272,7 @@ func (g *Graph) CallProcedure(procedure string, yield []string, args ...interfac } q += fmt.Sprintf("%s)", strings.Join(tmp, ",")) - if yield != nil && len(yield) > 0 { + if len(yield) > 0 { q += fmt.Sprintf(" YIELD %s", strings.Join(yield, ",")) } diff --git a/query_result.go b/query_result.go index 2c36514..fe82e06 100644 --- a/query_result.go +++ b/query_result.go @@ -139,13 +139,10 @@ func (qr *QueryResult) parseRecords(raw_result_set []interface{}) { case COLUMN_SCALAR: s, _ := redis.Values(c, nil) values[idx] = qr.parseScalar(s) - break case COLUMN_NODE: values[idx] = qr.parseNode(c) - break case COLUMN_RELATION: values[idx] = qr.parseEdge(c) - break default: panic("Unknown column type.") }