Replace DebugString with Describe

This change makes tree description completely open to mechanical
analysis and ensures consistency between description formats for each of
the iterator types.

Renamed StatsContainer.(Kind -> Type) for consistency.
This commit is contained in:
kortschak 2014-09-05 09:05:02 +09:30
parent b5f113203d
commit 62013d3dfc
22 changed files with 186 additions and 162 deletions

View file

@ -208,7 +208,14 @@ func (wk *worker) runIteratorToArrayNoTags(it graph.Iterator, limit int) []strin
func (wk *worker) runIteratorWithCallback(it graph.Iterator, callback otto.Value, this otto.FunctionCall, limit int) {
n := 0
it, _ = it.Optimize()
glog.V(2).Infoln(it.DebugString(0))
if glog.V(2) {
b, err := json.MarshalIndent(it.Describe(), "", " ")
if err != nil {
glog.V(2).Infof("failed to format description: %v", err)
} else {
glog.V(2).Infof("%s", b)
}
}
for {
select {
case <-wk.kill:
@ -271,7 +278,14 @@ func (wk *worker) runIterator(it graph.Iterator) {
return
}
it, _ = it.Optimize()
glog.V(2).Infoln(it.DebugString(0))
if glog.V(2) {
b, err := json.MarshalIndent(it.Describe(), "", " ")
if err != nil {
glog.Infof("failed to format description: %v", err)
} else {
glog.Infof("%s", b)
}
}
for {
select {
case <-wk.kill:

View file

@ -85,7 +85,12 @@ func (s *Session) ExecInput(input string, c chan interface{}, _ int) {
}
it, _ := s.currentQuery.it.Optimize()
if glog.V(2) {
glog.V(2).Infoln(it.DebugString(0))
b, err := json.MarshalIndent(it.Describe(), "", " ")
if err != nil {
glog.Infof("failed to format description: %v", err)
} else {
glog.Infof("%s", b)
}
}
for graph.Next(it) {
tags := make(map[string]graph.Value)

View file

@ -89,7 +89,7 @@ func TestTreeConstraintParse(t *testing.T) {
"($a (:is :good))))"
it := BuildIteratorTreeForQuery(qs, query)
if it.Type() != graph.And {
t.Errorf("Odd iterator tree. Got: %s", it.DebugString(0))
t.Errorf("Odd iterator tree. Got: %#v", it.Describe())
}
if !graph.Next(it) {
t.Error("Got no results")
@ -137,7 +137,7 @@ func TestMultipleConstraintParse(t *testing.T) {
)`
it := BuildIteratorTreeForQuery(qs, query)
if it.Type() != graph.And {
t.Errorf("Odd iterator tree. Got: %s", it.DebugString(0))
t.Errorf("Odd iterator tree. Got: %#v", it.Describe())
}
if !graph.Next(it) {
t.Error("Got no results")

View file

@ -17,6 +17,7 @@ package sexp
// Defines a running session of the sexp query language.
import (
"encoding/json"
"errors"
"fmt"
"sort"
@ -74,7 +75,12 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
}
if s.debug {
fmt.Println(it.DebugString(0))
b, err := json.MarshalIndent(it.Describe(), "", " ")
if err != nil {
fmt.Printf("failed to format description: %v", err)
} else {
fmt.Printf("%s", b)
}
}
nResults := 0
for graph.Next(it) {