From bf3ac2be9eb763d827c678cfd04c4874cbaaee15 Mon Sep 17 00:00:00 2001 From: kortschak Date: Sat, 2 Aug 2014 22:49:57 +0930 Subject: [PATCH] Destutter gremlin.GremlinResult --- query/gremlin/environ.go | 2 +- query/gremlin/finals.go | 4 ++-- query/gremlin/gremlin_test.go | 5 +++-- query/gremlin/session.go | 12 ++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/query/gremlin/environ.go b/query/gremlin/environ.go index 670b6b6..7918a21 100644 --- a/query/gremlin/environ.go +++ b/query/gremlin/environ.go @@ -84,7 +84,7 @@ func setupGremlin(env *otto.Otto, ses *Session) { graph.Set("Emit", func(call otto.FunctionCall) otto.Value { value := call.Argument(0) if value.IsDefined() { - ses.SendResult(&GremlinResult{val: &value}) + ses.SendResult(&Result{val: &value}) } return otto.NullValue() }) diff --git a/query/gremlin/finals.go b/query/gremlin/finals.go index 6658502..42998fa 100644 --- a/query/gremlin/finals.go +++ b/query/gremlin/finals.go @@ -267,7 +267,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) { } tags := make(map[string]graph.Value) it.TagResults(tags) - if !ses.SendResult(&GremlinResult{actualResults: &tags}) { + if !ses.SendResult(&Result{actualResults: &tags}) { break } for it.NextResult() == true { @@ -278,7 +278,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) { } tags := make(map[string]graph.Value) it.TagResults(tags) - if !ses.SendResult(&GremlinResult{actualResults: &tags}) { + if !ses.SendResult(&Result{actualResults: &tags}) { break } } diff --git a/query/gremlin/gremlin_test.go b/query/gremlin/gremlin_test.go index 453ff81..dbd115a 100644 --- a/query/gremlin/gremlin_test.go +++ b/query/gremlin/gremlin_test.go @@ -20,8 +20,9 @@ import ( "testing" "github.com/google/cayley/graph" - _ "github.com/google/cayley/graph/memstore" "github.com/google/cayley/quad" + + _ "github.com/google/cayley/graph/memstore" ) // This is a simple test graph. @@ -252,7 +253,7 @@ func runQueryGetTag(g []*quad.Quad, query string, tag string) []string { var results []string for res := range c { - data := res.(*GremlinResult) + data := res.(*Result) if data.val == nil { val := (*data.actualResults)[tag] if val != nil { diff --git a/query/gremlin/session.go b/query/gremlin/session.go index 8223c37..e5b3460 100644 --- a/query/gremlin/session.go +++ b/query/gremlin/session.go @@ -60,7 +60,7 @@ func NewSession(inputTripleStore graph.TripleStore, timeoutSec int, persist bool return &g } -type GremlinResult struct { +type Result struct { metaresult bool err error val *otto.Value @@ -89,7 +89,7 @@ func (s *Session) InputParses(input string) (query.ParseResult, error) { return query.Parsed, nil } -func (s *Session) SendResult(result *GremlinResult) bool { +func (s *Session) SendResult(r *Result) bool { if s.limit >= 0 && s.limit == s.count { return false } @@ -99,7 +99,7 @@ func (s *Session) SendResult(result *GremlinResult) bool { default: } if s.results != nil { - s.results <- result + s.results <- r s.count++ if s.limit >= 0 && s.limit == s.count { return false @@ -156,7 +156,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) { } else { value, err = s.runUnsafe(s.script) } - out <- &GremlinResult{ + out <- &Result{ metaresult: true, err: err, val: &value, @@ -169,7 +169,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) { } func (s *Session) ToText(result interface{}) string { - data := result.(*GremlinResult) + data := result.(*Result) if data.metaresult { if data.err != nil { return fmt.Sprintf("Error: %v\n", data.err) @@ -220,7 +220,7 @@ func (s *Session) ToText(result interface{}) string { // Web stuff func (s *Session) BuildJson(result interface{}) { - data := result.(*GremlinResult) + data := result.(*Result) if !data.metaresult { if data.val == nil { obj := make(map[string]string)