diff --git a/cayley_test.go b/cayley_test.go index b94389a5b..e9410719d 100644 --- a/cayley_test.go +++ b/cayley_test.go @@ -348,7 +348,7 @@ func TestQueries(t *testing.T) { // TODO(kortschak) Be more rigorous in this result validation. if len(got) != len(test.expect) { - t.Errorf("Unexpected number of results, got:%d expect:%d.", len(got), len(test.expect)) + t.Errorf("Unexpected number of results, got:%d expect:%d on %s.", len(got), len(test.expect), test.message) } } } diff --git a/graph/iterator.go b/graph/iterator.go index e7c2ad859..3880b80b0 100644 --- a/graph/iterator.go +++ b/graph/iterator.go @@ -154,11 +154,14 @@ func Next(it Iterator) (Value, bool) { } // Height is a convienence function to measure the height of an iterator tree. -func Height(it Iterator) int { +func Height(it Iterator, until Type) int { + if it.Type() == until { + return 1 + } subs := it.SubIterators() maxDepth := 0 for _, sub := range subs { - h := Height(sub) + h := Height(sub, until) if h > maxDepth { maxDepth = h } diff --git a/graph/iterator/and_iterator_optimize.go b/graph/iterator/and_iterator_optimize.go index f0adfad82..774904d59 100644 --- a/graph/iterator/and_iterator_optimize.go +++ b/graph/iterator/and_iterator_optimize.go @@ -300,7 +300,7 @@ func materializeIts(its []graph.Iterator) []graph.Iterator { for _, it := range its { stats := it.Stats() if stats.Size*stats.NextCost < stats.ContainsCost { - if graph.Height(it) > 10 { + if graph.Height(it, graph.Materialize) > 10 { out = append(out, NewMaterialize(it)) continue } diff --git a/graph/iterator/materialize_iterator.go b/graph/iterator/materialize_iterator.go index 4180a0bc2..03360800f 100644 --- a/graph/iterator/materialize_iterator.go +++ b/graph/iterator/materialize_iterator.go @@ -73,10 +73,16 @@ func (it *Materialize) TagResults(dst map[string]graph.Value) { if !it.hasRun { return } + if it.aborted { + it.subIt.TagResults(dst) + return + } + if it.lastIndex > len(it.values) { + return + } for _, tag := range it.tags.Tags() { dst[tag] = it.Result() } - for tag, value := range it.values[it.lastIndex].tags { dst[tag] = value } @@ -154,6 +160,7 @@ func (it *Materialize) Stats() graph.IteratorStats { } func (it *Materialize) Next() (graph.Value, bool) { + graph.NextLogIn(it) if !it.hasRun { it.materializeSet() } @@ -164,14 +171,15 @@ func (it *Materialize) Next() (graph.Value, bool) { lastVal := it.Result() for it.lastIndex < len(it.values) { it.lastIndex++ - if it.Result() != lastVal { - return it.Result(), true + if it.Result() != lastVal && it.Result() != nil { + return graph.NextLogOut(it, it.Result(), true) } } - return nil, false + return graph.NextLogOut(it, nil, false) } func (it *Materialize) Contains(v graph.Value) bool { + graph.ContainsLogIn(it, v) if !it.hasRun { it.materializeSet() } @@ -180,9 +188,9 @@ func (it *Materialize) Contains(v graph.Value) bool { } if i, ok := it.containsMap[v]; ok { it.lastIndex = i - return true + return graph.ContainsLogOut(it, v, true) } - return false + return graph.ContainsLogOut(it, v, false) } func (it *Materialize) NextResult() bool {