Skip to content

Commit f4e976d

Browse files
committed
[fix] Introduced InternalExecutionTime() and deprecated RunTime()
1 parent d2a117c commit f4e976d

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

client_test.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func TestMatchQuery(t *testing.T) {
6464
if err != nil {
6565
t.Error(err)
6666
}
67-
6867
assert.Equal(t, len(res.results), 1, "expecting 1 result record")
6968

7069
res.Next()
@@ -295,3 +294,62 @@ func TestCreateIndex(t *testing.T) {
295294
_, err = graph.Query("DROP INDEX ON :user(name)")
296295
assert.Equal(t, err.Error(), "ERR Unable to drop index on :user(name): no such index.")
297296
}
297+
298+
func TestQueryStatistics(t *testing.T) {
299+
graph.Flush()
300+
err := graph.Delete()
301+
assert.Nil(t,err)
302+
303+
q := "CREATE (:Person{name:'a',age:32,array:[0,1,2]})"
304+
res, err := graph.Query(q)
305+
assert.Nil(t,err)
306+
307+
assert.Equal(t, 1, res.NodesCreated(), "Expecting 1 node created")
308+
assert.Equal(t, 0, res.NodesDeleted(), "Expecting 0 nodes deleted")
309+
assert.Greater(t, res.InternalExecutionTime(),0.0, "Expecting internal execution time not to be 0.0")
310+
assert.Equal(t, true, res.Empty(), "Expecting empty resultset")
311+
312+
res,err = graph.Query("MATCH (n) DELETE n")
313+
assert.Nil(t,err)
314+
assert.Equal(t, 1, res.NodesDeleted(), "Expecting 1 nodes deleted")
315+
316+
// Create 2 nodes connect via a single edge.
317+
japan := NodeNew("Country", "j", nil)
318+
john := NodeNew("Person", "p", nil)
319+
edge := EdgeNew("Visited", john, japan, nil)
320+
321+
// Set node properties.
322+
john.SetProperty("name", "John Doe")
323+
john.SetProperty("age", 33)
324+
john.SetProperty("gender", "male")
325+
john.SetProperty("status", "single")
326+
327+
japan.SetProperty("name", "Japan")
328+
japan.SetProperty("population", 126800000)
329+
330+
edge.SetProperty("year", 2017)
331+
332+
// Introduce entities to graph.
333+
graph.AddNode(john)
334+
graph.AddNode(japan)
335+
graph.AddEdge(edge)
336+
337+
// Flush graph to DB.
338+
res, err = graph.Commit()
339+
assert.Nil(t,err)
340+
assert.Equal(t, 2, res.NodesCreated(), "Expecting 2 node created")
341+
assert.Equal(t, 0, res.NodesDeleted(), "Expecting 0 nodes deleted")
342+
assert.Equal(t, 7, res.PropertiesSet(), "Expecting 7 properties set")
343+
assert.Equal(t, 1, res.RelationshipsCreated(), "Expecting 1 relationships created")
344+
assert.Equal(t, 0, res.RelationshipsDeleted(), "Expecting 0 relationships deleted")
345+
assert.Greater(t, res.InternalExecutionTime(),0.0, "Expecting internal execution time not to be 0.0")
346+
assert.Equal(t, true, res.Empty(), "Expecting empty resultset")
347+
q = "MATCH p = (:Person)-[:Visited]->(:Country) RETURN p"
348+
res, err = graph.Query(q)
349+
assert.Nil(t,err)
350+
assert.Equal(t, len(res.results), 1, "expecting 1 result record")
351+
assert.Equal(t, false, res.Empty(), "Expecting resultset to have records")
352+
res,err = graph.Query("MATCH ()-[r]-() DELETE r")
353+
assert.Nil(t,err)
354+
assert.Equal(t, 1, res.RelationshipsDeleted(), "Expecting 1 relationships deleted")
355+
}

query_result.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,14 @@ func (qr *QueryResult) IndicesDeleted() int {
361361
return int(qr.getStat(INDICES_DELETED))
362362
}
363363

364-
func (qr *QueryResult) RunTime() float64 {
364+
// This method is deprecated and returns wrong internal execution times.
365+
// Deprecated: Please use InternalExecutionTime() instead
366+
func (qr *QueryResult) RunTime() int {
367+
return int(qr.getStat(INTERNAL_EXECUTION_TIME))
368+
}
369+
370+
// Returns the query internal execution time in milliseconds
371+
func (qr *QueryResult) InternalExecutionTime() float64 {
365372
return qr.getStat(INTERNAL_EXECUTION_TIME)
366373
}
367374

0 commit comments

Comments
 (0)