Remove non-documentation lint

Because of extensive nature of changes, tested all three non-memstore
backends - passed.
This commit is contained in:
kortschak 2014-08-28 11:51:39 +09:30
parent 6614466d23
commit 484bf145a8
35 changed files with 277 additions and 284 deletions

View file

@ -140,7 +140,7 @@ func buildInOutIterator(obj *otto.Object, qs graph.QuadStore, base graph.Iterato
}
func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.Iterator) graph.Iterator {
var it graph.Iterator = base
it := base
// TODO: Better error handling
var subIt graph.Iterator

View file

@ -112,9 +112,8 @@ func (wk *worker) toValueFunc(env *otto.Otto, obj *otto.Object, withTags bool) f
if err != nil {
glog.Error(err)
return otto.NullValue()
} else {
return val
}
return val
}
}
@ -260,9 +259,8 @@ func (wk *worker) send(r *Result) bool {
wk.count++
if wk.limit >= 0 && wk.limit == wk.count {
return false
} else {
return true
}
return true
}
return false
}

View file

@ -21,6 +21,7 @@ import (
"time"
"github.com/robertkrimen/otto"
// Provide underscore JS library.
_ "github.com/robertkrimen/otto/underscore"
"github.com/google/cayley/graph"
@ -176,7 +177,7 @@ func (s *Session) ToText(result interface{}) string {
tags := data.actualResults
tagKeys := make([]string, len(tags))
i := 0
for k, _ := range tags {
for k := range tags {
tagKeys[i] = k
i++
}
@ -203,7 +204,7 @@ func (s *Session) ToText(result interface{}) string {
}
// Web stuff
func (s *Session) BuildJson(result interface{}) {
func (s *Session) BuildJSON(result interface{}) {
data := result.(*Result)
if !data.metaresult {
if data.val == nil {
@ -211,7 +212,7 @@ func (s *Session) BuildJson(result interface{}) {
tags := data.actualResults
tagKeys := make([]string, len(tags))
i := 0
for k, _ := range tags {
for k := range tags {
tagKeys[i] = k
i++
}
@ -232,8 +233,8 @@ func (s *Session) BuildJson(result interface{}) {
}
}
func (s *Session) GetJson() ([]interface{}, error) {
defer s.ClearJson()
func (s *Session) GetJSON() ([]interface{}, error) {
defer s.ClearJSON()
if s.err != nil {
return nil, s.err
}
@ -245,6 +246,6 @@ func (s *Session) GetJson() ([]interface{}, error) {
}
}
func (s *Session) ClearJson() {
func (s *Session) ClearJSON() {
s.dataOutput = nil
}

View file

@ -47,7 +47,7 @@ func (q *Query) BuildIteratorTree(query interface{}) {
var isOptional bool
q.it, isOptional, q.err = q.buildIteratorTreeInternal(query, NewPath())
if isOptional {
q.err = errors.New("Optional iterator at the top level?")
q.err = errors.New("optional iterator at the top level")
}
}
@ -84,7 +84,7 @@ func (q *Query) buildIteratorTreeInternal(query interface{}, path Path) (it grap
} else if len(t) == 1 {
it, optional, err = q.buildIteratorTreeInternal(t[0], path)
} else {
err = errors.New(fmt.Sprintf("Multiple fields at location root%s", path.DisplayString()))
err = fmt.Errorf("multiple fields at location root %s", path.DisplayString())
}
case map[string]interface{}:
// for JSON objects
@ -166,13 +166,13 @@ func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path
return it, nil
}
type ResultPathSlice []ResultPath
type byRecordLength []ResultPath
func (p ResultPathSlice) Len() int {
func (p byRecordLength) Len() int {
return len(p)
}
func (p ResultPathSlice) Less(i, j int) bool {
func (p byRecordLength) Less(i, j int) bool {
iLen := len(strings.Split(string(p[i]), "\x30"))
jLen := len(strings.Split(string(p[j]), "\x30"))
if iLen < jLen {
@ -186,6 +186,6 @@ func (p ResultPathSlice) Less(i, j int) bool {
return false
}
func (p ResultPathSlice) Swap(i, j int) {
func (p byRecordLength) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}

View file

@ -34,13 +34,11 @@ func (q *Query) treeifyResult(tags map[string]graph.Value) map[ResultPath]string
resultPaths[k.ToResultPathFromMap(results)] = v
}
var paths ResultPathSlice
for path, _ := range resultPaths {
paths := make([]ResultPath, 0, len(resultPaths))
for path := range resultPaths {
paths = append(paths, path)
}
sort.Sort(paths)
sort.Sort(byRecordLength(paths))
// Build Structure
for _, path := range paths {

View file

@ -172,9 +172,9 @@ func runQuery(g []quad.Quad, query string) interface{} {
c := make(chan interface{}, 5)
go s.ExecInput(query, c, -1)
for result := range c {
s.BuildJson(result)
s.BuildJSON(result)
}
result, _ := s.GetJson()
result, _ := s.GetJSON()
return result
}

View file

@ -21,8 +21,10 @@ import (
"github.com/google/cayley/graph"
)
type Path string
type ResultPath string
type (
Path string
ResultPath string
)
type Query struct {
ses *Session

View file

@ -38,29 +38,28 @@ func NewSession(qs graph.QuadStore) *Session {
return &m
}
func (m *Session) ToggleDebug() {
m.debug = !m.debug
func (s *Session) ToggleDebug() {
s.debug = !s.debug
}
func (m *Session) GetQuery(input string, output_struct chan map[string]interface{}) {
defer close(output_struct)
func (s *Session) GetQuery(input string, out chan map[string]interface{}) {
defer close(out)
var mqlQuery interface{}
err := json.Unmarshal([]byte(input), &mqlQuery)
if err != nil {
return
}
m.currentQuery = NewQuery(m)
m.currentQuery.BuildIteratorTree(mqlQuery)
s.currentQuery = NewQuery(s)
s.currentQuery.BuildIteratorTree(mqlQuery)
output := make(map[string]interface{})
iterator.OutputQueryShapeForIterator(m.currentQuery.it, m.qs, output)
nodes := output["nodes"].([]iterator.Node)
new_nodes := make([]iterator.Node, 0)
for _, n := range nodes {
iterator.OutputQueryShapeForIterator(s.currentQuery.it, s.qs, output)
nodes := make([]iterator.Node, 0)
for _, n := range output["nodes"].([]iterator.Node) {
n.Tags = nil
new_nodes = append(new_nodes, n)
nodes = append(nodes, n)
}
output["nodes"] = new_nodes
output_struct <- output
output["nodes"] = nodes
out <- output
}
func (s *Session) InputParses(input string) (query.ParseResult, error) {
@ -109,7 +108,7 @@ func (s *Session) ToText(result interface{}) string {
r, _ := json.MarshalIndent(s.currentQuery.results, "", " ")
fmt.Println(string(r))
i := 0
for k, _ := range tags {
for k := range tags {
tagKeys[i] = string(k)
i++
}
@ -123,20 +122,19 @@ func (s *Session) ToText(result interface{}) string {
return out
}
func (s *Session) BuildJson(result interface{}) {
func (s *Session) BuildJSON(result interface{}) {
s.currentQuery.treeifyResult(result.(map[string]graph.Value))
}
func (s *Session) GetJson() ([]interface{}, error) {
func (s *Session) GetJSON() ([]interface{}, error) {
s.currentQuery.buildResults()
if s.currentQuery.isError() {
return nil, s.currentQuery.err
} else {
return s.currentQuery.results, nil
}
return s.currentQuery.results, nil
}
func (s *Session) ClearJson() {
func (s *Session) ClearJSON() {
// Since we create a new Query underneath every query, clearing isn't necessary.
return
}

View file

@ -32,14 +32,14 @@ type Session interface {
ToggleDebug()
}
type HttpSession interface {
type HTTP interface {
// Return whether the string is a valid expression.
InputParses(string) (ParseResult, error)
// Runs the query and returns individual results on the channel.
ExecInput(string, chan interface{}, int)
GetQuery(string, chan map[string]interface{})
BuildJson(interface{})
GetJson() ([]interface{}, error)
ClearJson()
BuildJSON(interface{})
GetJSON() ([]interface{}, error)
ClearJSON()
ToggleDebug()
}

View file

@ -53,7 +53,7 @@ func (s *Session) InputParses(input string) (query.ParseResult, error) {
if (i - 10) > min {
min = i - 10
}
return query.ParseFail, errors.New(fmt.Sprintf("Too many close parens at char %d: %s", i, input[min:i]))
return query.ParseFail, fmt.Errorf("too many close parentheses at char %d: %s", i, input[min:i])
}
}
}
@ -63,7 +63,7 @@ func (s *Session) InputParses(input string) (query.ParseResult, error) {
if len(ParseString(input)) > 0 {
return query.Parsed, nil
}
return query.ParseFail, errors.New("Invalid Syntax")
return query.ParseFail, errors.New("invalid syntax")
}
func (s *Session) ExecInput(input string, out chan interface{}, limit int) {