diff --git a/appengine.go b/appengine.go index 843f29a..1b36f00 100644 --- a/appengine.go +++ b/appengine.go @@ -29,7 +29,7 @@ import ( func init() { glog.SetToStderr(true) - cfg := config.ParseConfigFromFile("cayley_appengine.cfg") + cfg, _ := config.Load("cayley_appengine.cfg") qs, _ := graph.NewQuadStore("memstore", "", nil) glog.Errorln(cfg) db.Load(qs, cfg, cfg.DatabasePath) diff --git a/graph/bolt/quadstore.go b/graph/bolt/quadstore.go index 265f948..6c5c76c 100644 --- a/graph/bolt/quadstore.go +++ b/graph/bolt/quadstore.go @@ -43,7 +43,6 @@ var ( } hashSize = sha1.Size localFillPercent = 0.7 - ) type Token struct { @@ -209,10 +208,10 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta, ignoreOpts graph.IgnoreOp for _, d := range deltas { err := qs.buildQuadWrite(tx, d.Quad, d.ID.Int(), d.Action == graph.Add) if err != nil { - if err == graph.ErrQuadExists && ignoreOpts.IgnoreDup{ + if err == graph.ErrQuadExists && ignoreOpts.IgnoreDup { continue } - if err == graph.ErrQuadNotExist && ignoreOpts.IgnoreMissing{ + if err == graph.ErrQuadNotExist && ignoreOpts.IgnoreMissing { continue } return err @@ -269,7 +268,7 @@ func (qs *QuadStore) buildQuadWrite(tx *bolt.Tx, q quad.Quad, id int64, isAdd bo return graph.ErrQuadExists } if !isAdd && len(entry.History)%2 == 0 { - glog.Error("attempt to delete non-existent quad %v: %#c", entry, q) + glog.Errorf("attempt to delete non-existent quad %v: %#v", entry, q) return graph.ErrQuadNotExist } diff --git a/graph/iterator.go b/graph/iterator.go index 4442ea5..01a0358 100644 --- a/graph/iterator.go +++ b/graph/iterator.go @@ -30,7 +30,7 @@ type Tagger struct { fixedTags map[string]Value } -// Adds a tag to the iterator. +// Add a tag to the iterator. func (t *Tagger) Add(tag string) { t.tags = append(t.tags, tag) } @@ -42,12 +42,12 @@ func (t *Tagger) AddFixed(tag string, value Value) { t.fixedTags[tag] = value } -// Returns the tags. The returned value must not be mutated. +// Tags returns the tags held in the tagger. The returned value must not be mutated. func (t *Tagger) Tags() []string { return t.tags } -// Returns the fixed tags. The returned value must not be mutated. +// Fixed returns the fixed tags held in the tagger. The returned value must not be mutated. func (t *Tagger) Fixed() map[string]Value { return t.fixedTags } @@ -206,6 +206,7 @@ type IteratorStats struct { // Type enumerates the set of Iterator types. type Type int +// These are the iterator types, defined as constants const ( Invalid Type = iota All @@ -306,6 +307,7 @@ func DumpStats(it Iterator) StatsContainer { // Utility logging functions for when an iterator gets called Next upon, or Contains upon, as // well as what they return. Highly useful for tracing the execution path of a query. + func ContainsLogIn(it Iterator, val Value) { if glog.V(4) { glog.V(4).Infof("%s %d CHECK CONTAINS %d", strings.ToUpper(it.Type().String()), it.UID(), val) diff --git a/graph/iterator/or_iterator_test.go b/graph/iterator/or_iterator_test.go index 2091569..27cdc7d 100644 --- a/graph/iterator/or_iterator_test.go +++ b/graph/iterator/or_iterator_test.go @@ -90,9 +90,9 @@ func TestShortCircuitingOrBasics(t *testing.T) { or = NewShortCircuitOr() or.AddSubIterator(f1) or.AddSubIterator(f2) - v, exact := or.Size() - if v != 4 { - t.Errorf("Unexpected iterator size, got:%d expected %d", v, 4) + size, exact := or.Size() + if size != 4 { + t.Errorf("Unexpected iterator size, got:%d expected %d", size, 4) } if !exact { t.Error("Size not exact.") diff --git a/graph/mongo/iterator.go b/graph/mongo/iterator.go index 32bc472..876dff8 100644 --- a/graph/mongo/iterator.go +++ b/graph/mongo/iterator.go @@ -160,7 +160,7 @@ func (it *Iterator) NextPath() bool { return false } -// No subiterators. +// SubIterators returns no subiterators for a Mongo iterator. func (it *Iterator) SubIterators() []graph.Iterator { return nil } diff --git a/graph/quadwriter.go b/graph/quadwriter.go index fdf65f3..aaaf05f 100644 --- a/graph/quadwriter.go +++ b/graph/quadwriter.go @@ -23,8 +23,8 @@ package graph import ( "errors" - "time" "flag" + "time" "github.com/google/cayley/quad" ) @@ -64,7 +64,7 @@ var ( ) var ( - IgnoreDup = flag.Bool("ignoredup", false, "Don't stop loading on duplicated key on add") + IgnoreDup = flag.Bool("ignoredup", false, "Don't stop loading on duplicated key on add") IgnoreMissing = flag.Bool("ignoremissing", false, "Don't stop loading on missing key on delete") ) diff --git a/query/gremlin/build_iterator.go b/query/gremlin/build_iterator.go index d95a5e8..f92d473 100644 --- a/query/gremlin/build_iterator.go +++ b/query/gremlin/build_iterator.go @@ -140,10 +140,12 @@ func buildInOutIterator(obj *otto.Object, qs graph.QuadStore, base graph.Iterato } func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.Iterator) graph.Iterator { - it := base - // TODO: Better error handling - var subIt graph.Iterator + var ( + it graph.Iterator + subIt graph.Iterator + ) + if prev, _ := obj.Get("_gremlin_prev"); !prev.IsObject() { subIt = base } else { @@ -314,5 +316,8 @@ func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.It and.AddSubIterator(notIt) it = and } + if it == nil { + panic("Iterator building does not catch the output iterator in some case.") + } return it } diff --git a/query/sexp/parser_test.go b/query/sexp/parser_test.go index 77f16cb..babefc4 100644 --- a/query/sexp/parser_test.go +++ b/query/sexp/parser_test.go @@ -57,9 +57,9 @@ var testQueries = []struct { func TestMemstoreBackedSexp(t *testing.T) { qs, _ := graph.NewQuadStore("memstore", "", nil) w, _ := graph.NewQuadWriter("single", qs, nil) - it := BuildIteratorTreeForQuery(qs, "()") - if it.Type() != graph.Null { - t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type()) + emptyIt := BuildIteratorTreeForQuery(qs, "()") + if emptyIt.Type() != graph.Null { + t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, emptyIt.Type()) } for _, test := range testQueries { if test.add.IsValid() {