added support for returning SetBit effect

This commit is contained in:
Todd Gruben 2016-02-16 17:38:56 -06:00
parent 00413a9e9a
commit 7c8a27338a
3 changed files with 38 additions and 22 deletions

View file

@ -303,7 +303,7 @@ func (cmd *ImportCommand) parsePath(path string) ([]pilosa.Bit, error) {
// Ignore blank rows.
if record[0] == "" {
continue
} else if len(record) != 2 {
} else if len(record) < 2 {
return nil, fmt.Errorf("bad column count on row %d: col=%d", rnum, len(record))
}

View file

@ -50,7 +50,7 @@ func (e *Executor) Execute(db string, q *pql.Query, slices []uint64) (interface{
// Ignore slices for set calls.
switch root := q.Root.(type) {
case *pql.SetBit:
return nil, e.executeSetBit(db, root)
return e.executeSetBit(db, root)
case *pql.SetBitmapAttrs:
return nil, e.executeSetBitmapAttrs(db, root)
case *pql.SetProfileAttrs:
@ -315,27 +315,33 @@ func (e *Executor) executeProfile(db string, c *pql.Profile) (*Profile, error) {
}
// executeSetBit executes a SetBit() call.
func (e *Executor) executeSetBit(db string, c *pql.SetBit) error {
func (e *Executor) executeSetBit(db string, c *pql.SetBit) (bool,error){
slice := c.ProfileID / SliceWidth
ret :=false
for _, node := range e.Cluster.SliceNodes(slice) {
// Update locally if host matches.
if node.Host == e.Host {
f, err := e.Index().CreateFragmentIfNotExists(db, c.Frame, slice)
if err != nil {
return fmt.Errorf("fragment: %s", err)
return false,fmt.Errorf("fragment: %s", err)
}
err,val :=f.SetBit(c.ID, c.ProfileID)
if err != nil{
return false, err
}
if val{
ret = true
}
f.SetBit(c.ID, c.ProfileID)
continue
}
// Forward call to remote node otherwise.
if _, err := e.exec(node, db, &pql.Query{Root: c}, nil); err != nil {
// FIXME: Handle errors more gracefully.
return err
return false,err
}
fmt.Println("NEED TO IMPLEMENT REMOTE SETBIT")
}
return nil
return ret,nil
}
// executeSetBitmapAttrs executes a SetBitmapAttrs() call.

View file

@ -13,6 +13,7 @@ import (
"syscall"
"time"
"unsafe"
"reflect"
"github.com/gogo/protobuf/proto"
"github.com/umbel/pilosa/internal"
@ -312,51 +313,50 @@ func (f *Fragment) bitmap(bitmapID uint64) *Bitmap {
// SetBit sets a bit for a given profile & bitmap within the fragment.
// This updates both the on-disk storage and the in-cache bitmap.
func (f *Fragment) SetBit(bitmapID, profileID uint64) error {
func (f *Fragment) SetBit(bitmapID, profileID uint64) (error,bool) {
f.mu.Lock()
defer f.mu.Unlock()
return f.setBit(bitmapID, profileID)
}
func (f *Fragment) setBit(bitmapID, profileID uint64) error {
func (f *Fragment) setBit(bitmapID, profileID uint64) (error,bool) {
// Determine the position of the bit in the storage.
pos, err := f.pos(bitmapID, profileID)
if err != nil {
return err
return err,false
}
// Write to storage.
if err := f.storage.Add(pos); err != nil {
return err
return err,false
}
// Update the cache.
f.bitmap(bitmapID).setBit(profileID)
return nil
// Update the cache.
return nil,f.bitmap(bitmapID).setBit(profileID)
}
// ClearBit clears a bit for a given profile & bitmap within the fragment.
// This updates both the on-disk storage and the in-cache bitmap.
func (f *Fragment) ClearBit(bitmapID, profileID uint64) error {
func (f *Fragment) ClearBit(bitmapID, profileID uint64) (error,bool) {
f.mu.Lock()
defer f.mu.Unlock()
// Determine the position of the bit in the storage.
pos, err := f.pos(bitmapID, profileID)
if err != nil {
return err
return err,false
}
// Write to storage.
if err := f.storage.Remove(pos); err != nil {
return err
return err,false
}
// Update the cache.
f.bitmap(bitmapID).clearBit(profileID)
return nil, f.bitmap(bitmapID).clearBit(profileID)
return nil
}
// pos translates the bitmap ID and profile ID into a position in the storage bitmap.
@ -385,7 +385,15 @@ func (f *Fragment) TopN(n int, src *Bitmap, field string, fieldValues []interfac
if len(fieldValues) > 0 {
filters = make(map[interface{}]struct{})
for _, v := range fieldValues {
filters[v] = struct{}{}
switch v.(type){
case uint64:
i:=int64(v.(uint64))
filters[i] = struct{}{}
default:
filters[v] = struct{}{}
}
fmt.Println(reflect.TypeOf(v))
}
}
@ -409,6 +417,8 @@ func (f *Fragment) TopN(n int, src *Bitmap, field string, fieldValues []interfac
} else if attrValue := attr[field]; attrValue == nil {
continue
} else if _, ok := filters[attrValue]; !ok {
fmt.Println(reflect.TypeOf(attrValue),"==")
continue
}
}