added parser support for recall

This commit is contained in:
Todd Gruben 2014-09-02 20:07:12 +00:00
parent cd6e4d07e8
commit 098a062a2b
3 changed files with 44 additions and 1 deletions

View file

@ -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)
}

View file

@ -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)
})
}

View file

@ -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