Remove non-documentation lint
Because of extensive nature of changes, tested all three non-memstore backends - passed.
This commit is contained in:
parent
6614466d23
commit
484bf145a8
35 changed files with 277 additions and 284 deletions
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue