diff --git a/query/parser.go b/query/parser.go index fac11a8ed..8891c8ca8 100644 --- a/query/parser.go +++ b/query/parser.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "log" + "pilosa/index" "pilosa/util" "strconv" "time" @@ -191,6 +192,27 @@ ArgLoop: } query.Args["n"] = i } + case "recall": //need pair based list of frag_id,handle + arg, ok := query.Args["stash"] + if !ok { + arg = &Stash{make([]CacheItem, 0), false} + query.Args["stash"] = arg + } + + recallArgs := arg.(*Stash) + if !recallArgs.incomplete { + i, err := strconv.ParseUint(token.Text, 10, 64) + if err != nil { + return nil, fmt.Errorf("Expecting fragment id! (%v)", err) + } + recallArgs.Add(util.SUUID(i)) //constructs a new arg + } else { + i, err := strconv.ParseUint(token.Text, 10, 64) + if err != nil { + return nil, fmt.Errorf("Expecting handle! (%v)", err) + } + recallArgs.Assign(index.BitmapHandle(i)) //sets the value of the last created arg + } default: spew.Dump("UNPROCESSED VALUE", token) } diff --git a/query/parser_test.go b/query/parser_test.go index 1801a713e..f21884a24 100644 --- a/query/parser_test.go +++ b/query/parser_test.go @@ -2,6 +2,8 @@ package query import ( "testing" + + "github.com/davecgh/go-spew/spew" . "github.com/smartystreets/goconvey/convey" ) @@ -82,4 +84,10 @@ func TestQueryParser(t *testing.T) { _, err = Parse(tokens) So(err, ShouldBeNil) }) + Convey("Recall", t, func() { + tokens, err := Lex("recall(12345,1,12345,2,12345,3)") + q, err := Parse(tokens) + spew.Dump(q) + So(err, ShouldBeNil) + }) } diff --git a/query/planner.go b/query/planner.go index 9415b913f..85923075c 100644 --- a/query/planner.go +++ b/query/planner.go @@ -797,8 +797,21 @@ type CacheItem struct { } type Stash struct { - Stash []CacheItem //index.BitmapHandle //probably need to make the a struct with fragment_id and handle + Stash []CacheItem //index.BitmapHandle //probably need to make the a struct with fragment_id and handle + incomplete bool } + +func (st *Stash) Add(i util.SUUID) { + item := CacheItem{i, 0} + st.Stash = append(st.Stash, item) + st.incomplete = true +} + +func (st *Stash) Assign(i index.BitmapHandle) { + st.Stash[len(st.Stash)-1].Handle = i //big assumption that item already exists + st.incomplete = false +} + type StashQueryStep struct { *BaseQueryStep Inputs []*util.GUID