diff --git a/api.go b/api.go index af182e0f8..e053e11fa 100644 --- a/api.go +++ b/api.go @@ -114,7 +114,7 @@ func (api *API) Query(ctx context.Context, req *QueryRequest) (QueryResponse, er // Consolidate all column ids across all calls. var columnIDs []uint64 for _, result := range results { - bm, ok := result.(*Bitmap) + bm, ok := result.(*Row) if !ok { continue } diff --git a/cache.go b/cache.go index 6fc70dcaf..5305cfef8 100644 --- a/cache.go +++ b/cache.go @@ -463,8 +463,8 @@ func (p uint64Slice) merge(other []uint64) []uint64 { // BitmapCache provides an interface for caching full bitmaps. type BitmapCache interface { - Fetch(id uint64) (*Bitmap, bool) - Add(id uint64, b *Bitmap) + Fetch(id uint64) (*Row, bool) + Add(id uint64, b *Row) } // SimpleCache implements BitmapCache @@ -473,17 +473,17 @@ type BitmapCache interface { // A read-heavy use case would cause the cache to get bigger, potentially causing the // node to run out of memory. type SimpleCache struct { - cache map[uint64]*Bitmap + cache map[uint64]*Row } // Fetch retrieves the bitmap at the id in the cache. -func (s *SimpleCache) Fetch(id uint64) (*Bitmap, bool) { +func (s *SimpleCache) Fetch(id uint64) (*Row, bool) { m, ok := s.cache[id] return m, ok } // Add adds the bitmap to the cache, keyed on the id. -func (s *SimpleCache) Add(id uint64, b *Bitmap) { +func (s *SimpleCache) Add(id uint64, b *Row) { s.cache[id] = b } diff --git a/executor.go b/executor.go index 329a571aa..2b9f129e4 100644 --- a/executor.go +++ b/executor.go @@ -310,7 +310,7 @@ func (e *Executor) executeFieldMax(ctx context.Context, index string, c *pql.Cal } // executeBitmapCall executes a call that returns a bitmap. -func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (*Bitmap, error) { +func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (*Row, error) { // Execute calls in bulk on each remote node and merge. mapFn := func(slice uint64) (interface{}, error) { return e.executeBitmapCallSlice(ctx, index, c, slice) @@ -318,11 +318,11 @@ func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.C // Merge returned results at coordinating node. reduceFn := func(prev, v interface{}) interface{} { - other, _ := prev.(*Bitmap) + other, _ := prev.(*Row) if other == nil { - other = NewBitmap() + other = NewRow() } - other.Merge(v.(*Bitmap)) + other.Merge(v.(*Row)) return other } @@ -334,10 +334,10 @@ func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.C // Attach attributes for Bitmap() calls. // If the column label is used then return column attributes. // If the row label is used then return bitmap attributes. - bm, _ := other.(*Bitmap) + row, _ := other.(*Row) if c.Name == "Bitmap" { if opt.ExcludeAttrs { - bm.Attrs = map[string]interface{}{} + row.Attrs = map[string]interface{}{} } else { idx := e.Holder.Index(index) if idx != nil { @@ -346,7 +346,7 @@ func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.C if err != nil { return nil, errors.Wrap(err, "getting column attrs") } - bm.Attrs = attrs + row.Attrs = attrs } else if err != nil { return nil, err } else { @@ -360,7 +360,7 @@ func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.C if err != nil { return nil, errors.Wrap(err, "getting row attrs") } - bm.Attrs = attrs + row.Attrs = attrs } } } @@ -368,14 +368,14 @@ func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.C } if opt.ExcludeBits { - bm.segments = []BitmapSegment{} + row.segments = []RowSegment{} } - return bm, nil + return row, nil } // executeBitmapCallSlice executes a bitmap call for a single slice. -func (e *Executor) executeBitmapCallSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { +func (e *Executor) executeBitmapCallSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { switch c.Name { case "Bitmap": return e.executeBitmapSlice(ctx, index, c, slice) @@ -396,13 +396,13 @@ func (e *Executor) executeBitmapCallSlice(ctx context.Context, index string, c * // executeSumCountSlice calculates the sum and count for fields on a slice. func (e *Executor) executeSumCountSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (ValCount, error) { - var filter *Bitmap + var filter *Row if len(c.Children) == 1 { - bm, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) + row, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) if err != nil { return ValCount{}, errors.Wrap(err, "executing bitmap call") } - filter = bm + filter = row } frameName, _ := c.Args["frame"].(string) @@ -435,13 +435,13 @@ func (e *Executor) executeSumCountSlice(ctx context.Context, index string, c *pq // executeFieldMinSlice calculates the min for fields on a slice. func (e *Executor) executeFieldMinSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (ValCount, error) { - var filter *Bitmap + var filter *Row if len(c.Children) == 1 { - bm, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) + row, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) if err != nil { return ValCount{}, err } - filter = bm + filter = row } frameName, _ := c.Args["frame"].(string) @@ -474,13 +474,13 @@ func (e *Executor) executeFieldMinSlice(ctx context.Context, index string, c *pq // executeFieldMaxSlice calculates the max for fields on a slice. func (e *Executor) executeFieldMaxSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (ValCount, error) { - var filter *Bitmap + var filter *Row if len(c.Children) == 1 { - bm, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) + row, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) if err != nil { return ValCount{}, err } - filter = bm + filter = row } frameName, _ := c.Args["frame"].(string) @@ -601,13 +601,13 @@ func (e *Executor) executeTopNSlice(ctx context.Context, index string, c *pql.Ca } // Retrieve bitmap used to intersect. - var src *Bitmap + var src *Row if len(c.Children) == 1 { - bm, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) + row, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) if err != nil { return nil, err } - src = bm + src = row } else if len(c.Children) > 1 { return nil, errors.New("TopN() can only have one input bitmap") } @@ -647,28 +647,28 @@ func (e *Executor) executeTopNSlice(ctx context.Context, index string, c *pql.Ca } // executeDifferenceSlice executes a difference() call for a local slice. -func (e *Executor) executeDifferenceSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { - var other *Bitmap +func (e *Executor) executeDifferenceSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { + var other *Row if len(c.Children) == 0 { return nil, fmt.Errorf("empty Difference query is currently not supported") } for i, input := range c.Children { - bm, err := e.executeBitmapCallSlice(ctx, index, input, slice) + row, err := e.executeBitmapCallSlice(ctx, index, input, slice) if err != nil { return nil, err } if i == 0 { - other = bm + other = row } else { - other = other.Difference(bm) + other = other.Difference(row) } } other.InvalidateCount() return other, nil } -func (e *Executor) executeBitmapSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { +func (e *Executor) executeBitmapSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { // Fetch column label from index. idx := e.Holder.Index(index) if idx == nil { @@ -708,27 +708,27 @@ func (e *Executor) executeBitmapSlice(ctx context.Context, index string, c *pql. frag := e.Holder.Fragment(index, frame, view, slice) if frag == nil { - return NewBitmap(), nil + return NewRow(), nil } return frag.Row(id), nil } // executeIntersectSlice executes a intersect() call for a local slice. -func (e *Executor) executeIntersectSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { - var other *Bitmap +func (e *Executor) executeIntersectSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { + var other *Row if len(c.Children) == 0 { return nil, fmt.Errorf("empty Intersect query is currently not supported") } for i, input := range c.Children { - bm, err := e.executeBitmapCallSlice(ctx, index, input, slice) + row, err := e.executeBitmapCallSlice(ctx, index, input, slice) if err != nil { return nil, err } if i == 0 { - other = bm + other = row } else { - other = other.Intersect(bm) + other = other.Intersect(row) } } other.InvalidateCount() @@ -736,7 +736,7 @@ func (e *Executor) executeIntersectSlice(ctx context.Context, index string, c *p } // executeRangeSlice executes a range() call for a local slice. -func (e *Executor) executeRangeSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { +func (e *Executor) executeRangeSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { // Handle field ranges differently. if c.HasConditionArg() { return e.executeFieldRangeSlice(ctx, index, c, slice) @@ -806,24 +806,24 @@ func (e *Executor) executeRangeSlice(ctx context.Context, index string, c *pql.C // If no quantum exists then return an empty bitmap. q := f.TimeQuantum() if q == "" { - return &Bitmap{}, nil + return &Row{}, nil } // Union bitmaps across all time-based subframes. - bm := &Bitmap{} + row := &Row{} for _, view := range ViewsByTimeRange(viewName, startTime, endTime, q) { f := e.Holder.Fragment(index, frame, view, slice) if f == nil { continue } - bm = bm.Union(f.Row(id)) + row = row.Union(f.Row(id)) } f.Stats.Count("range", 1, 1.0) - return bm, nil + return row, nil } // executeFieldRangeSlice executes a range(field) call for a local slice. -func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { +func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { // Parse frame, use default if unset. frame, _ := c.Args["frame"].(string) if frame == "" { @@ -874,7 +874,7 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c * // Retrieve fragment. frag := e.Holder.Fragment(index, frame, ViewFieldPrefix+fieldName, slice) if frag == nil { - return NewBitmap(), nil + return NewRow(), nil } return frag.FieldNotNull(field.BitDepth()) @@ -903,13 +903,13 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c * baseValueMin, baseValueMax, outOfRange := field.BaseValueBetween(predicates[0], predicates[1]) if outOfRange { - return NewBitmap(), nil + return NewRow(), nil } // Retrieve fragment. frag := e.Holder.Fragment(index, frame, ViewFieldPrefix+fieldName, slice) if frag == nil { - return NewBitmap(), nil + return NewRow(), nil } // If the query is asking for the entire valid range, just return @@ -936,13 +936,13 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c * baseValue, outOfRange := field.BaseValue(cond.Op, value) if outOfRange && cond.Op != pql.NEQ { - return NewBitmap(), nil + return NewRow(), nil } // Retrieve fragment. frag := e.Holder.Fragment(index, frame, ViewFieldPrefix+fieldName, slice) if frag == nil { - return NewBitmap(), nil + return NewRow(), nil } // LT[E] and GT[E] should return all not-null if selected range fully encompasses valid field range. @@ -962,18 +962,18 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c * } // executeUnionSlice executes a union() call for a local slice. -func (e *Executor) executeUnionSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { - other := NewBitmap() +func (e *Executor) executeUnionSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { + other := NewRow() for i, input := range c.Children { - bm, err := e.executeBitmapCallSlice(ctx, index, input, slice) + row, err := e.executeBitmapCallSlice(ctx, index, input, slice) if err != nil { return nil, err } if i == 0 { - other = bm + other = row } else { - other = other.Union(bm) + other = other.Union(row) } } other.InvalidateCount() @@ -981,18 +981,18 @@ func (e *Executor) executeUnionSlice(ctx context.Context, index string, c *pql.C } // executeXorSlice executes a xor() call for a local slice. -func (e *Executor) executeXorSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Bitmap, error) { - other := NewBitmap() +func (e *Executor) executeXorSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) { + other := NewRow() for i, input := range c.Children { - bm, err := e.executeBitmapCallSlice(ctx, index, input, slice) + row, err := e.executeBitmapCallSlice(ctx, index, input, slice) if err != nil { return nil, err } if i == 0 { - other = bm + other = row } else { - other = other.Xor(bm) + other = other.Xor(row) } } other.InvalidateCount() @@ -1009,11 +1009,11 @@ func (e *Executor) executeCount(ctx context.Context, index string, c *pql.Call, // Execute calls in bulk on each remote node and merge. mapFn := func(slice uint64) (interface{}, error) { - bm, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) + row, err := e.executeBitmapCallSlice(ctx, index, c.Children[0], slice) if err != nil { return 0, err } - return bm.Count(), nil + return row.Count(), nil } // Merge returned results at coordinating node. @@ -1520,7 +1520,7 @@ func (e *Executor) remoteExec(ctx context.Context, node *Node, index string, q * case "SetRowAttrs": case "SetColumnAttrs": default: - v, err = decodeBitmap(pb.Results[i].GetBitmap()), nil + v, err = decodeRow(pb.Results[i].GetRow()), nil } if err != nil { return nil, err diff --git a/executor_test.go b/executor_test.go index 0fd8a925b..7948ed2fe 100644 --- a/executor_test.go +++ b/executor_test.go @@ -54,27 +54,27 @@ func TestExecutor_Execute_Bitmap(t *testing.T) { if res, err := e.Execute(context.Background(), "i", test.MustParse(`Bitmap(row=10, frame=f)`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{3, SliceWidth + 1}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{3, SliceWidth + 1}) { t.Fatalf("unexpected bits: %+v", bits) - } else if attrs := res[0].(*pilosa.Bitmap).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{"foo": "bar", "baz": int64(123)}) { + } else if attrs := res[0].(*pilosa.Row).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{"foo": "bar", "baz": int64(123)}) { t.Fatalf("unexpected attrs: %s", spew.Sdump(attrs)) } // Inhibit bits. if res, err := e.Execute(context.Background(), "i", test.MustParse(`Bitmap(row=10, frame=f)`), nil, &pilosa.ExecOptions{ExcludeBits: true}); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{}) { t.Fatalf("unexpected bits: %+v", bits) - } else if attrs := res[0].(*pilosa.Bitmap).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{"foo": "bar", "baz": int64(123)}) { + } else if attrs := res[0].(*pilosa.Row).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{"foo": "bar", "baz": int64(123)}) { t.Fatalf("unexpected attrs: %s", spew.Sdump(attrs)) } // Inhibit attributes. if res, err := e.Execute(context.Background(), "i", test.MustParse(`Bitmap(row=10, frame=f)`), nil, &pilosa.ExecOptions{ExcludeAttrs: true}); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{3, SliceWidth + 1}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{3, SliceWidth + 1}) { t.Fatalf("unexpected bits: %+v", bits) - } else if attrs := res[0].(*pilosa.Bitmap).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{}) { + } else if attrs := res[0].(*pilosa.Row).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{}) { t.Fatalf("unexpected attrs: %s", spew.Sdump(attrs)) } }) @@ -103,9 +103,9 @@ func TestExecutor_Execute_Bitmap(t *testing.T) { if res, err := e.Execute(context.Background(), "i", test.MustParse(fmt.Sprintf(`Bitmap(col=%d, frame=f)`, SliceWidth+1)), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{10, 20}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{10, 20}) { t.Fatalf("unexpected bits: %+v", bits) - } else if attrs := res[0].(*pilosa.Bitmap).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{"foo": "bar", "baz": int64(123)}) { + } else if attrs := res[0].(*pilosa.Row).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{"foo": "bar", "baz": int64(123)}) { t.Fatalf("unexpected attrs: %s", spew.Sdump(attrs)) } }) @@ -124,7 +124,7 @@ func TestExecutor_Execute_Difference(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) if res, err := e.Execute(context.Background(), "i", test.MustParse(`Difference(Bitmap(row=10), Bitmap(row=11))`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{1, 3}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{1, 3}) { t.Fatalf("unexpected bits: %+v", bits) } } @@ -156,7 +156,7 @@ func TestExecutor_Execute_Intersect(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) if res, err := e.Execute(context.Background(), "i", test.MustParse(`Intersect(Bitmap(row=10), Bitmap(row=11))`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{1, SliceWidth + 2}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{1, SliceWidth + 2}) { t.Fatalf("unexpected bits: %+v", bits) } } @@ -186,7 +186,7 @@ func TestExecutor_Execute_Union(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) if res, err := e.Execute(context.Background(), "i", test.MustParse(`Union(Bitmap(row=10), Bitmap(row=11))`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{0, 2, SliceWidth + 1, SliceWidth + 2}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{0, 2, SliceWidth + 1, SliceWidth + 2}) { t.Fatalf("unexpected bits: %+v", bits) } } @@ -200,7 +200,7 @@ func TestExecutor_Execute_Empty_Union(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) if res, err := e.Execute(context.Background(), "i", test.MustParse(`Union()`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{}) { t.Fatalf("unexpected bits: %+v", bits) } } @@ -219,7 +219,7 @@ func TestExecutor_Execute_Xor(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) if res, err := e.Execute(context.Background(), "i", test.MustParse(`Xor(Bitmap(row=10), Bitmap(row=11))`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{0, 2, SliceWidth + 1}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{0, 2, SliceWidth + 1}) { t.Fatalf("unexpected bits: %+v", bits) } } @@ -784,7 +784,7 @@ func TestExecutor_Execute_Range(t *testing.T) { t.Run("Standard", func(t *testing.T) { if res, err := e.Execute(context.Background(), "i", test.MustParse(`Range(row=1, frame=f, start="1999-12-31T00:00", end="2002-01-01T03:00")`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{2, 3, 4, 5, 6, 7}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{2, 3, 4, 5, 6, 7}) { t.Fatalf("unexpected bits: %+v", bits) } }) @@ -793,7 +793,7 @@ func TestExecutor_Execute_Range(t *testing.T) { e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) if res, err := e.Execute(context.Background(), "i", test.MustParse(`Range(col=2, frame=f, start="1999-01-01T00:00", end="2003-01-01T00:00")`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{1, 10}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{1, 10}) { t.Fatalf("unexpected bits: %+v", bits) } }) @@ -854,7 +854,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("EQ", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo == 20)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{50, (5 * SliceWidth) + 100}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{50, (5 * SliceWidth) + 100}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -863,28 +863,28 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { // NEQ null if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo != null)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } // NEQ if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo != 20)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{SliceWidth, SliceWidth + 1, SliceWidth + 2}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{SliceWidth, SliceWidth + 1, SliceWidth + 2}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } // NEQ - if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo != -20)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Bits()) { //t.Fatalf("unexpected result: %s", spew.Sdump(result)) - t.Fatalf("unexpected result: %v", result[0].(*pilosa.Bitmap).Bits()) + t.Fatalf("unexpected result: %v", result[0].(*pilosa.Row).Bits()) } }) t.Run("LT", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo < 20)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{SliceWidth + 2}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{SliceWidth + 2}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -892,7 +892,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("LTE", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo <= 20)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{50, SliceWidth + 2, (5 * SliceWidth) + 100}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{50, SliceWidth + 2, (5 * SliceWidth) + 100}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -900,7 +900,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("GT", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo > 20)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{SliceWidth, SliceWidth + 1}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{SliceWidth, SliceWidth + 1}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -908,7 +908,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("GTE", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo >= 20)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{50, SliceWidth, SliceWidth + 1, (5 * SliceWidth) + 100}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{50, SliceWidth, SliceWidth + 1, (5 * SliceWidth) + 100}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -916,7 +916,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("BETWEEN", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo >< [1, 1000])`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -925,7 +925,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("FieldNotNull", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo >< [0, 1000])`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -933,7 +933,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("BelowMin", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo == 0)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -941,7 +941,7 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("AboveMax", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo == 200)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{}, result[0].(*pilosa.Bitmap).Bits()) { + } else if !reflect.DeepEqual([]uint64{}, result[0].(*pilosa.Row).Bits()) { t.Fatalf("unexpected result: %s", spew.Sdump(result)) } }) @@ -949,16 +949,16 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { t.Run("LTAboveMax", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=edge, foo < 200)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{0, 1}, result[0].(*pilosa.Bitmap).Bits()) { - t.Fatalf("unexpected result: %s", spew.Sdump(result[0].(*pilosa.Bitmap).Bits())) + } else if !reflect.DeepEqual([]uint64{0, 1}, result[0].(*pilosa.Row).Bits()) { + t.Fatalf("unexpected result: %s", spew.Sdump(result[0].(*pilosa.Row).Bits())) } }) t.Run("GTBelowMin", func(t *testing.T) { if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=edge, foo > -200)`), nil, nil); err != nil { t.Fatal(err) - } else if !reflect.DeepEqual([]uint64{0, 1}, result[0].(*pilosa.Bitmap).Bits()) { - t.Fatalf("unexpected result: %s", spew.Sdump(result[0].(*pilosa.Bitmap).Bits())) + } else if !reflect.DeepEqual([]uint64{0, 1}, result[0].(*pilosa.Row).Bits()) { + t.Fatalf("unexpected result: %s", spew.Sdump(result[0].(*pilosa.Row).Bits())) } }) @@ -975,8 +975,8 @@ func TestExecutor_Execute_FieldRange(t *testing.T) { }) } -// Ensure a remote query can return a bitmap. -func TestExecutor_Execute_Remote_Bitmap(t *testing.T) { +// Ensure a remote query can return a row. +func TestExecutor_Execute_Remote_Row(t *testing.T) { c := test.NewCluster(2) // Create secondary server and update second cluster node. @@ -1000,12 +1000,12 @@ func TestExecutor_Execute_Remote_Bitmap(t *testing.T) { } // Set bits in slice 0 & 2. - bm := pilosa.NewBitmap( + r := pilosa.NewRow( (0*SliceWidth)+1, (0*SliceWidth)+2, (2*SliceWidth)+4, ) - return []interface{}{bm}, nil + return []interface{}{r}, nil } // Create local executor data. @@ -1018,7 +1018,7 @@ func TestExecutor_Execute_Remote_Bitmap(t *testing.T) { e := test.NewExecutor(hldr.Holder, c) if res, err := e.Execute(context.Background(), "i", test.MustParse(`Bitmap(row=10, frame=f)`), nil, nil); err != nil { t.Fatal(err) - } else if bits := res[0].(*pilosa.Bitmap).Bits(); !reflect.DeepEqual(bits, []uint64{1, 2, 2*SliceWidth + 4}) { + } else if bits := res[0].(*pilosa.Row).Bits(); !reflect.DeepEqual(bits, []uint64{1, 2, 2*SliceWidth + 4}) { t.Fatalf("unexpected bits: %+v", bits) } } diff --git a/fragment.go b/fragment.go index aab5d0524..492524c0d 100644 --- a/fragment.go +++ b/fragment.go @@ -239,7 +239,7 @@ func (f *Fragment) openStorage() error { // Attach the file to the bitmap to act as a write-ahead log. f.storage.OpWriter = f.file - f.rowCache = &SimpleCache{make(map[uint64]*Bitmap)} + f.rowCache = &SimpleCache{make(map[uint64]*Row)} return nil @@ -343,13 +343,13 @@ func (f *Fragment) closeStorage() error { } // Row returns a row by ID. -func (f *Fragment) Row(rowID uint64) *Bitmap { +func (f *Fragment) Row(rowID uint64) *Row { f.mu.Lock() defer f.mu.Unlock() return f.row(rowID, true, true) } -func (f *Fragment) row(rowID uint64, checkRowCache bool, updateRowCache bool) *Bitmap { +func (f *Fragment) row(rowID uint64, checkRowCache bool, updateRowCache bool) *Row { if checkRowCache { r, ok := f.rowCache.Fetch(rowID) if ok && r != nil { @@ -362,22 +362,22 @@ func (f *Fragment) row(rowID uint64, checkRowCache bool, updateRowCache bool) *B data := f.storage.OffsetRange(f.slice*SliceWidth, rowID*SliceWidth, (rowID+1)*SliceWidth) // Reference bitmap subrange in storage. - // We Clone() data because otherwise bm will contains pointers to containers in storage. + // We Clone() data because otherwise row will contains pointers to containers in storage. // This causes unexpected results when we cache the row and try to use it later. - bm := &Bitmap{ - segments: []BitmapSegment{{ + row := &Row{ + segments: []RowSegment{{ data: *data.Clone(), slice: f.slice, writable: false, }}, } - bm.InvalidateCount() + row.InvalidateCount() if updateRowCache { - f.rowCache.Add(rowID, bm) + f.rowCache.Add(rowID, row) } - return bm + return row } // SetBit sets a bit for a given column & row within the fragment. @@ -415,11 +415,11 @@ func (f *Fragment) setBit(rowID, columnID uint64) (changed bool, err error) { } // Get the row from row cache or fragment.storage. - bm := f.row(rowID, true, true) - bm.SetBit(columnID) + row := f.row(rowID, true, true) + row.SetBit(columnID) // Update the cache. - f.cache.Add(rowID, bm.Count()) + f.cache.Add(rowID, row.Count()) f.stats.Count("setBit", 1, 0.001) @@ -467,11 +467,11 @@ func (f *Fragment) clearBit(rowID, columnID uint64) (changed bool, err error) { } // Get the row from cache or fragment.storage. - bm := f.row(rowID, true, true) - bm.ClearBit(columnID) + row := f.row(rowID, true, true) + row.ClearBit(columnID) // Update the cache. - f.cache.Add(rowID, bm.Count()) + f.cache.Add(rowID, row.Count()) f.stats.Count("clearBit", 1, 1.0) @@ -584,7 +584,7 @@ func (f *Fragment) importSetFieldValue(columnID uint64, bitDepth uint, value uin // FieldSum returns the sum of a given field as well as the number of columns involved. // A bitmap can be passed in to optionally filter the computed columns. -func (f *Fragment) FieldSum(filter *Bitmap, bitDepth uint) (sum, count uint64, err error) { +func (f *Fragment) FieldSum(filter *Row, bitDepth uint) (sum, count uint64, err error) { // Compute count based on the existence bit. row := f.Row(uint64(bitDepth)) if filter != nil { @@ -616,7 +616,7 @@ func (f *Fragment) FieldSum(filter *Bitmap, bitDepth uint) (sum, count uint64, e // FieldMin returns the min of a given field as well as the number of columns involved. // A bitmap can be passed in to optionally filter the computed columns. -func (f *Fragment) FieldMin(filter *Bitmap, bitDepth uint) (min, count uint64, err error) { +func (f *Fragment) FieldMin(filter *Row, bitDepth uint) (min, count uint64, err error) { consider := f.Row(uint64(bitDepth)) if filter != nil { @@ -649,7 +649,7 @@ func (f *Fragment) FieldMin(filter *Bitmap, bitDepth uint) (min, count uint64, e // FieldMax returns the max of a given field as well as the number of columns involved. // A bitmap can be passed in to optionally filter the computed columns. -func (f *Fragment) FieldMax(filter *Bitmap, bitDepth uint) (max, count uint64, err error) { +func (f *Fragment) FieldMax(filter *Row, bitDepth uint) (max, count uint64, err error) { consider := f.Row(uint64(bitDepth)) if filter != nil { @@ -679,7 +679,7 @@ func (f *Fragment) FieldMax(filter *Bitmap, bitDepth uint) (max, count uint64, e } // FieldRange returns bitmaps with a field value encoding matching the predicate. -func (f *Fragment) FieldRange(op pql.Token, bitDepth uint, predicate uint64) (*Bitmap, error) { +func (f *Fragment) FieldRange(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { switch op { case pql.EQ: return f.fieldRangeEQ(bitDepth, predicate) @@ -694,7 +694,7 @@ func (f *Fragment) FieldRange(op pql.Token, bitDepth uint, predicate uint64) (*B } } -func (f *Fragment) fieldRangeEQ(bitDepth uint, predicate uint64) (*Bitmap, error) { +func (f *Fragment) fieldRangeEQ(bitDepth uint, predicate uint64) (*Row, error) { // Start with set of columns with values set. b := f.Row(uint64(bitDepth)) @@ -713,7 +713,7 @@ func (f *Fragment) fieldRangeEQ(bitDepth uint, predicate uint64) (*Bitmap, error return b, nil } -func (f *Fragment) fieldRangeNEQ(bitDepth uint, predicate uint64) (*Bitmap, error) { +func (f *Fragment) fieldRangeNEQ(bitDepth uint, predicate uint64) (*Row, error) { // Start with set of columns with values set. b := f.Row(uint64(bitDepth)) @@ -729,8 +729,8 @@ func (f *Fragment) fieldRangeNEQ(bitDepth uint, predicate uint64) (*Bitmap, erro return b, nil } -func (f *Fragment) fieldRangeLT(bitDepth uint, predicate uint64, allowEquality bool) (*Bitmap, error) { - keep := NewBitmap() +func (f *Fragment) fieldRangeLT(bitDepth uint, predicate uint64, allowEquality bool) (*Row, error) { + keep := NewRow() // Start with set of columns with values set. b := f.Row(uint64(bitDepth)) @@ -777,9 +777,9 @@ func (f *Fragment) fieldRangeLT(bitDepth uint, predicate uint64, allowEquality b return b, nil } -func (f *Fragment) fieldRangeGT(bitDepth uint, predicate uint64, allowEquality bool) (*Bitmap, error) { +func (f *Fragment) fieldRangeGT(bitDepth uint, predicate uint64, allowEquality bool) (*Row, error) { b := f.Row(uint64(bitDepth)) - keep := NewBitmap() + keep := NewRow() // Filter any bits that don't match the current bit value. for i := int(bitDepth - 1); i >= 0; i-- { @@ -813,15 +813,15 @@ func (f *Fragment) fieldRangeGT(bitDepth uint, predicate uint64, allowEquality b } // FieldNotNull returns the not-null row (stored at bitDepth). -func (f *Fragment) FieldNotNull(bitDepth uint) (*Bitmap, error) { +func (f *Fragment) FieldNotNull(bitDepth uint) (*Row, error) { return f.Row(uint64(bitDepth)), nil } // FieldRangeBetween returns bitmaps with a field value encoding matching any value between predicateMin and predicateMax. -func (f *Fragment) FieldRangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Bitmap, error) { +func (f *Fragment) FieldRangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) { b := f.Row(uint64(bitDepth)) - keep1 := NewBitmap() // GTE - keep2 := NewBitmap() // LTE + keep1 := NewRow() // GTE + keep2 := NewRow() // LTE // Filter any bits that don't match the current bit value. for i := int(bitDepth - 1); i >= 0; i-- { @@ -1048,12 +1048,12 @@ func (f *Fragment) topBitmapPairs(rowIDs []uint64) []BitmapPair { continue } - bm := f.Row(rowID) - if bm.Count() > 0 { + row := f.Row(rowID) + if row.Count() > 0 { // Otherwise load from storage. pairs = append(pairs, BitmapPair{ ID: rowID, - Count: bm.Count(), + Count: row.Count(), }) } } @@ -1067,7 +1067,7 @@ type TopOptions struct { N int // Bitmap to intersect with. - Src *Bitmap + Src *Row // Specific rows to filter against. RowIDs []uint64 @@ -1370,7 +1370,7 @@ func (f *Fragment) Import(rowIDs, columnIDs []uint64) error { // Update cache counts for all rows. for rowID := range set { - // Import should ALWAYS have row() load a new bm from fragment.storage + // Import should ALWAYS have row() load a new row from fragment.storage // because the row that's in rowCache hasn't been updated with // this import's data. f.cache.BulkAdd(rowID, f.row(rowID, false, false).Count()) diff --git a/fragment_test.go b/fragment_test.go index f72f03ee1..22c8fe81f 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -248,7 +248,7 @@ func TestFragment_FieldSum(t *testing.T) { }) t.Run("WithFilter", func(t *testing.T) { - if sum, n, err := f.FieldSum(pilosa.NewBitmap(2000, 4000, 5000), bitDepth); err != nil { + if sum, n, err := f.FieldSum(pilosa.NewRow(2000, 4000, 5000), bitDepth); err != nil { t.Fatal(err) } else if n != 2 { t.Fatalf("unexpected count: %d", n) @@ -284,16 +284,16 @@ func TestFragment_FieldMinMax(t *testing.T) { t.Run("Min", func(t *testing.T) { tests := []struct { - filter *pilosa.Bitmap + filter *pilosa.Row exp uint64 cnt uint64 }{ {filter: nil, exp: 0, cnt: 1}, - {filter: pilosa.NewBitmap(2000, 4000, 5000), exp: 300, cnt: 2}, - {filter: pilosa.NewBitmap(2000, 4000), exp: 300, cnt: 2}, - {filter: pilosa.NewBitmap(1), exp: 0, cnt: 0}, - {filter: pilosa.NewBitmap(1000), exp: 382, cnt: 1}, - {filter: pilosa.NewBitmap(7000), exp: 0, cnt: 1}, + {filter: pilosa.NewRow(2000, 4000, 5000), exp: 300, cnt: 2}, + {filter: pilosa.NewRow(2000, 4000), exp: 300, cnt: 2}, + {filter: pilosa.NewRow(1), exp: 0, cnt: 0}, + {filter: pilosa.NewRow(1000), exp: 382, cnt: 1}, + {filter: pilosa.NewRow(7000), exp: 0, cnt: 1}, } for i, test := range tests { if min, cnt, err := f.FieldMin(test.filter, bitDepth); err != nil { @@ -308,16 +308,16 @@ func TestFragment_FieldMinMax(t *testing.T) { t.Run("Max", func(t *testing.T) { tests := []struct { - filter *pilosa.Bitmap + filter *pilosa.Row exp uint64 cnt uint64 }{ {filter: nil, exp: 2818, cnt: 2}, - {filter: pilosa.NewBitmap(2000, 4000, 5000), exp: 2818, cnt: 1}, - {filter: pilosa.NewBitmap(2000, 4000), exp: 300, cnt: 2}, - {filter: pilosa.NewBitmap(1), exp: 0, cnt: 0}, - {filter: pilosa.NewBitmap(1000), exp: 382, cnt: 1}, - {filter: pilosa.NewBitmap(7000), exp: 0, cnt: 1}, + {filter: pilosa.NewRow(2000, 4000, 5000), exp: 2818, cnt: 1}, + {filter: pilosa.NewRow(2000, 4000), exp: 300, cnt: 2}, + {filter: pilosa.NewRow(1), exp: 0, cnt: 0}, + {filter: pilosa.NewRow(1000), exp: 382, cnt: 1}, + {filter: pilosa.NewRow(7000), exp: 0, cnt: 1}, } for i, test := range tests { if max, cnt, err := f.FieldMax(test.filter, bitDepth); err != nil { @@ -642,7 +642,7 @@ func TestFragment_TopN_Intersect(t *testing.T) { defer f.Close() // Create an intersecting input row. - src := pilosa.NewBitmap(1, 2, 3) + src := pilosa.NewRow(1, 2, 3) // Set bits on various rows. f.MustSetBits(100, 1, 10, 11, 12) // one intersection @@ -673,7 +673,7 @@ func TestFragment_TopN_Intersect_Large(t *testing.T) { defer f.Close() // Create an intersecting input row. - src := pilosa.NewBitmap( + src := pilosa.NewRow( 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, ) @@ -1081,7 +1081,7 @@ func TestFragment_Tanimoto(t *testing.T) { f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, pilosa.CacheTypeRanked) defer f.Close() - src := pilosa.NewBitmap(1, 2, 3) + src := pilosa.NewRow(1, 2, 3) // Set bits on the rows 100, 101, & 102. f.MustSetBits(100, 1, 3, 2, 200) @@ -1104,7 +1104,7 @@ func TestFragment_Zero_Tanimoto(t *testing.T) { f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, pilosa.CacheTypeRanked) defer f.Close() - src := pilosa.NewBitmap(1, 2, 3) + src := pilosa.NewRow(1, 2, 3) // Set bits on the rows 100, 101, & 102. f.MustSetBits(100, 1, 3, 2, 200) diff --git a/frame.go b/frame.go index 0cf71f918..de9d3527f 100644 --- a/frame.go +++ b/frame.go @@ -718,8 +718,8 @@ func (f *Frame) SetFieldValue(columnID uint64, name string, value int64) (change } // FieldSum returns the sum and count for a field. -// An optional filtering bitmap can be provided. -func (f *Frame) FieldSum(filter *Bitmap, name string) (sum, count int64, err error) { +// An optional filtering row can be provided. +func (f *Frame) FieldSum(filter *Row, name string) (sum, count int64, err error) { field := f.Field(name) if field == nil { return 0, 0, ErrFieldNotFound @@ -738,8 +738,8 @@ func (f *Frame) FieldSum(filter *Bitmap, name string) (sum, count int64, err err } // FieldMin returns the min for a field. -// An optional filtering bitmap can be provided. -func (f *Frame) FieldMin(filter *Bitmap, name string) (min, count int64, err error) { +// An optional filtering row can be provided. +func (f *Frame) FieldMin(filter *Row, name string) (min, count int64, err error) { field := f.Field(name) if field == nil { return 0, 0, ErrFieldNotFound @@ -758,8 +758,8 @@ func (f *Frame) FieldMin(filter *Bitmap, name string) (min, count int64, err err } // FieldMax returns the max for a field. -// An optional filtering bitmap can be provided. -func (f *Frame) FieldMax(filter *Bitmap, name string) (max, count int64, err error) { +// An optional filtering row can be provided. +func (f *Frame) FieldMax(filter *Row, name string) (max, count int64, err error) { field := f.Field(name) if field == nil { return 0, 0, ErrFieldNotFound @@ -777,7 +777,7 @@ func (f *Frame) FieldMax(filter *Bitmap, name string) (max, count int64, err err return int64(vmax) + field.Min, int64(vcount), nil } -func (f *Frame) FieldRange(name string, op pql.Token, predicate int64) (*Bitmap, error) { +func (f *Frame) FieldRange(name string, op pql.Token, predicate int64) (*Row, error) { // Retrieve and validate field. field := f.Field(name) if field == nil { @@ -794,13 +794,13 @@ func (f *Frame) FieldRange(name string, op pql.Token, predicate int64) (*Bitmap, baseValue, outOfRange := field.BaseValue(op, predicate) if outOfRange { - return NewBitmap(), nil + return NewRow(), nil } return view.FieldRange(op, field.BitDepth(), baseValue) } -func (f *Frame) FieldRangeBetween(name string, predicateMin, predicateMax int64) (*Bitmap, error) { +func (f *Frame) FieldRangeBetween(name string, predicateMin, predicateMax int64) (*Row, error) { // Retrieve and validate field. field := f.Field(name) if field == nil { @@ -817,7 +817,7 @@ func (f *Frame) FieldRangeBetween(name string, predicateMin, predicateMax int64) baseValueMin, baseValueMax, outOfRange := field.BaseValueBetween(predicateMin, predicateMax) if outOfRange { - return NewBitmap(), nil + return NewRow(), nil } return view.FieldRangeBetween(field.BitDepth(), baseValueMin, baseValueMax) diff --git a/handler.go b/handler.go index 67ed11404..a11c5b43f 100644 --- a/handler.go +++ b/handler.go @@ -1158,7 +1158,7 @@ func (h *Handler) handleGetVersion(w http.ResponseWriter, r *http.Request) { // QueryResult types. const ( QueryResultTypeNil uint32 = iota - QueryResultTypeBitmap + QueryResultTypeRow QueryResultTypePairs QueryResultTypeValCount QueryResultTypeUint64 @@ -1243,9 +1243,9 @@ func encodeQueryResponse(resp *QueryResponse) *internal.QueryResponse { pb.Results[i] = &internal.QueryResult{} switch result := resp.Results[i].(type) { - case *Bitmap: - pb.Results[i].Type = QueryResultTypeBitmap - pb.Results[i].Bitmap = encodeBitmap(result) + case *Row: + pb.Results[i].Type = QueryResultTypeRow + pb.Results[i].Row = encodeRow(result) case []Pair: pb.Results[i].Type = QueryResultTypePairs pb.Results[i].Pairs = encodePairs(result) diff --git a/handler_test.go b/handler_test.go index c5843617b..b39b207c5 100644 --- a/handler_test.go +++ b/handler_test.go @@ -410,9 +410,9 @@ func TestHandler_Query_Bitmap_JSON(t *testing.T) { h.API.Cluster = test.NewCluster(1) h.API.Holder = hldr.Holder h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) { - bm := pilosa.NewBitmap(1, 3, 66, pilosa.SliceWidth+1) - bm.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true} - return []interface{}{bm}, nil + r := pilosa.NewRow(1, 3, 66, pilosa.SliceWidth+1) + r.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true} + return []interface{}{r}, nil } w := httptest.NewRecorder() @@ -424,8 +424,8 @@ func TestHandler_Query_Bitmap_JSON(t *testing.T) { } } -// Ensure the handler can execute a query that returns a bitmap with column attributes as JSON. -func TestHandler_Query_Bitmap_ColumnAttrs_JSON(t *testing.T) { +// Ensure the handler can execute a query that returns a row with column attributes as JSON. +func TestHandler_Query_Row_ColumnAttrs_JSON(t *testing.T) { hldr := test.NewHolder() defer hldr.Close() @@ -443,9 +443,9 @@ func TestHandler_Query_Bitmap_ColumnAttrs_JSON(t *testing.T) { h.API.Holder = hldr.Holder h.API.Cluster = test.NewCluster(1) h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) { - bm := pilosa.NewBitmap(1, 3, 66, pilosa.SliceWidth+1) - bm.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true} - return []interface{}{bm}, nil + r := pilosa.NewRow(1, 3, 66, pilosa.SliceWidth+1) + r.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true} + return []interface{}{r}, nil } w := httptest.NewRecorder() @@ -457,8 +457,8 @@ func TestHandler_Query_Bitmap_ColumnAttrs_JSON(t *testing.T) { } } -// Ensure the handler can execute a query that returns a bitmap as protobuf. -func TestHandler_Query_Bitmap_Protobuf(t *testing.T) { +// Ensure the handler can execute a query that returns a row as protobuf. +func TestHandler_Query_Row_Protobuf(t *testing.T) { hldr := test.MustOpenHolder() defer hldr.Close() @@ -466,9 +466,9 @@ func TestHandler_Query_Bitmap_Protobuf(t *testing.T) { h.API.Cluster = test.NewCluster(1) h.API.Holder = hldr.Holder h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) { - bm := pilosa.NewBitmap(1, pilosa.SliceWidth+1) - bm.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true} - return []interface{}{bm}, nil + r := pilosa.NewRow(1, pilosa.SliceWidth+1) + r.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true} + return []interface{}{r}, nil } w := httptest.NewRecorder() @@ -482,11 +482,11 @@ func TestHandler_Query_Bitmap_Protobuf(t *testing.T) { var resp internal.QueryResponse if err := proto.Unmarshal(w.Body.Bytes(), &resp); err != nil { t.Fatal(err) - } else if rt := resp.Results[0].Type; rt != pilosa.QueryResultTypeBitmap { + } else if rt := resp.Results[0].Type; rt != pilosa.QueryResultTypeRow { t.Fatalf("unexpected response type: %d", resp.Results[0].Type) - } else if bits := resp.Results[0].Bitmap.Bits; !reflect.DeepEqual(bits, []uint64{1, SliceWidth + 1}) { + } else if bits := resp.Results[0].Row.Bits; !reflect.DeepEqual(bits, []uint64{1, SliceWidth + 1}) { t.Fatalf("unexpected bits: %+v", bits) - } else if attrs := resp.Results[0].Bitmap.Attrs; len(attrs) != 3 { + } else if attrs := resp.Results[0].Row.Attrs; len(attrs) != 3 { t.Fatalf("unexpected attr length: %d", len(attrs)) } else if k, v := attrs[0].Key, attrs[0].StringValue; k != "a" || v != "b" { t.Fatalf("unexpected attr[0]: %s=%v", k, v) @@ -497,8 +497,8 @@ func TestHandler_Query_Bitmap_Protobuf(t *testing.T) { } } -// Ensure the handler can execute a query that returns a bitmap with column attributes as protobuf. -func TestHandler_Query_Bitmap_ColumnAttrs_Protobuf(t *testing.T) { +// Ensure the handler can execute a query that returns a row with column attributes as protobuf. +func TestHandler_Query_Row_ColumnAttrs_Protobuf(t *testing.T) { hldr := test.NewHolder() defer hldr.Close() @@ -514,9 +514,9 @@ func TestHandler_Query_Bitmap_ColumnAttrs_Protobuf(t *testing.T) { h.API.Holder = hldr.Holder h.API.Cluster = test.NewCluster(1) h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) { - bm := pilosa.NewBitmap(1, pilosa.SliceWidth+1) - bm.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true} - return []interface{}{bm}, nil + r := pilosa.NewRow(1, pilosa.SliceWidth+1) + r.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true} + return []interface{}{r}, nil } // Encode request body. @@ -541,11 +541,11 @@ func TestHandler_Query_Bitmap_ColumnAttrs_Protobuf(t *testing.T) { if err := proto.Unmarshal(w.Body.Bytes(), &resp); err != nil { t.Fatal(err) } - if bits := resp.Results[0].Bitmap.Bits; !reflect.DeepEqual(bits, []uint64{1, SliceWidth + 1}) { + if bits := resp.Results[0].Row.Bits; !reflect.DeepEqual(bits, []uint64{1, SliceWidth + 1}) { t.Fatalf("unexpected bits: %+v", bits) - } else if rt := resp.Results[0].Type; rt != pilosa.QueryResultTypeBitmap { + } else if rt := resp.Results[0].Type; rt != pilosa.QueryResultTypeRow { t.Fatalf("unexpected response type: %d", resp.Results[0].Type) - } else if attrs := resp.Results[0].Bitmap.Attrs; len(attrs) != 3 { + } else if attrs := resp.Results[0].Row.Attrs; len(attrs) != 3 { t.Fatalf("unexpected attr length: %d", len(attrs)) } else if k, v := attrs[0].Key, attrs[0].StringValue; k != "a" || v != "b" { t.Fatalf("unexpected attr[0]: %s=%v", k, v) diff --git a/internal/public.pb.go b/internal/public.pb.go index b94dbe6a0..22a46565b 100644 --- a/internal/public.pb.go +++ b/internal/public.pb.go @@ -8,7 +8,7 @@ public.proto It has these top-level messages: - Bitmap + Row Pair ValCount Bit @@ -42,32 +42,32 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package -type Bitmap struct { +type Row struct { Bits []uint64 `protobuf:"varint,1,rep,packed,name=Bits" json:"Bits,omitempty"` Keys []string `protobuf:"bytes,3,rep,name=Keys" json:"Keys,omitempty"` Attrs []*Attr `protobuf:"bytes,2,rep,name=Attrs" json:"Attrs,omitempty"` } -func (m *Bitmap) Reset() { *m = Bitmap{} } -func (m *Bitmap) String() string { return proto.CompactTextString(m) } -func (*Bitmap) ProtoMessage() {} -func (*Bitmap) Descriptor() ([]byte, []int) { return fileDescriptorPublic, []int{0} } +func (m *Row) Reset() { *m = Row{} } +func (m *Row) String() string { return proto.CompactTextString(m) } +func (*Row) ProtoMessage() {} +func (*Row) Descriptor() ([]byte, []int) { return fileDescriptorPublic, []int{0} } -func (m *Bitmap) GetBits() []uint64 { +func (m *Row) GetBits() []uint64 { if m != nil { return m.Bits } return nil } -func (m *Bitmap) GetKeys() []string { +func (m *Row) GetKeys() []string { if m != nil { return m.Keys } return nil } -func (m *Bitmap) GetAttrs() []*Attr { +func (m *Row) GetAttrs() []*Attr { if m != nil { return m.Attrs } @@ -356,7 +356,7 @@ func (m *QueryResponse) GetColumnAttrSets() []*ColumnAttrSet { type QueryResult struct { Type uint32 `protobuf:"varint,6,opt,name=Type,proto3" json:"Type,omitempty"` - Bitmap *Bitmap `protobuf:"bytes,1,opt,name=Bitmap" json:"Bitmap,omitempty"` + Row *Row `protobuf:"bytes,1,opt,name=Row" json:"Row,omitempty"` N uint64 `protobuf:"varint,2,opt,name=N,proto3" json:"N,omitempty"` Pairs []*Pair `protobuf:"bytes,3,rep,name=Pairs" json:"Pairs,omitempty"` ValCount *ValCount `protobuf:"bytes,5,opt,name=ValCount" json:"ValCount,omitempty"` @@ -375,9 +375,9 @@ func (m *QueryResult) GetType() uint32 { return 0 } -func (m *QueryResult) GetBitmap() *Bitmap { +func (m *QueryResult) GetRow() *Row { if m != nil { - return m.Bitmap + return m.Row } return nil } @@ -547,7 +547,7 @@ func (m *ImportValueRequest) GetValues() []int64 { } func init() { - proto.RegisterType((*Bitmap)(nil), "internal.Bitmap") + proto.RegisterType((*Row)(nil), "internal.Row") proto.RegisterType((*Pair)(nil), "internal.Pair") proto.RegisterType((*ValCount)(nil), "internal.ValCount") proto.RegisterType((*Bit)(nil), "internal.Bit") @@ -560,7 +560,7 @@ func init() { proto.RegisterType((*ImportRequest)(nil), "internal.ImportRequest") proto.RegisterType((*ImportValueRequest)(nil), "internal.ImportValueRequest") } -func (m *Bitmap) Marshal() (dAtA []byte, err error) { +func (m *Row) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalTo(dAtA) @@ -570,7 +570,7 @@ func (m *Bitmap) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *Bitmap) MarshalTo(dAtA []byte) (int, error) { +func (m *Row) MarshalTo(dAtA []byte) (int, error) { var i int _ = i var l int @@ -988,11 +988,11 @@ func (m *QueryResult) MarshalTo(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Bitmap != nil { + if m.Row != nil { dAtA[i] = 0xa i++ - i = encodeVarintPublic(dAtA, i, uint64(m.Bitmap.Size())) - n5, err := m.Bitmap.MarshalTo(dAtA[i:]) + i = encodeVarintPublic(dAtA, i, uint64(m.Row.Size())) + n5, err := m.Row.MarshalTo(dAtA[i:]) if err != nil { return 0, err } @@ -1260,7 +1260,7 @@ func encodeVarintPublic(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return offset + 1 } -func (m *Bitmap) Size() (n int) { +func (m *Row) Size() (n int) { var l int _ = l if len(m.Bits) > 0 { @@ -1439,8 +1439,8 @@ func (m *QueryResponse) Size() (n int) { func (m *QueryResult) Size() (n int) { var l int _ = l - if m.Bitmap != nil { - l = m.Bitmap.Size() + if m.Row != nil { + l = m.Row.Size() n += 1 + l + sovPublic(uint64(l)) } if m.N != 0 { @@ -1569,7 +1569,7 @@ func sovPublic(x uint64) (n int) { func sozPublic(x uint64) (n int) { return sovPublic(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *Bitmap) Unmarshal(dAtA []byte) error { +func (m *Row) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1592,10 +1592,10 @@ func (m *Bitmap) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Bitmap: wiretype end group for non-group") + return fmt.Errorf("proto: Row: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Bitmap: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Row: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2833,7 +2833,7 @@ func (m *QueryResult) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Bitmap", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Row", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -2857,10 +2857,10 @@ func (m *QueryResult) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Bitmap == nil { - m.Bitmap = &Bitmap{} + if m.Row == nil { + m.Row = &Row{} } - if err := m.Bitmap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Row.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -3795,50 +3795,50 @@ var ( func init() { proto.RegisterFile("public.proto", fileDescriptorPublic) } var fileDescriptorPublic = []byte{ - // 705 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xcb, 0x6e, 0xd3, 0x40, - 0x14, 0x65, 0x62, 0x27, 0x71, 0x6e, 0x92, 0xaa, 0x1a, 0x41, 0xb1, 0x10, 0x8a, 0x2c, 0x8b, 0x85, - 0x57, 0xa9, 0x14, 0xf6, 0x20, 0xd2, 0x87, 0x14, 0x55, 0x54, 0x30, 0x2d, 0x61, 0xed, 0xb6, 0xa3, - 0x62, 0xc9, 0x2f, 0xec, 0xb1, 0xda, 0x7c, 0x07, 0x1b, 0x3e, 0x81, 0x8f, 0x60, 0xc5, 0x0a, 0x76, - 0x7c, 0x02, 0x94, 0x1f, 0x41, 0xf7, 0x8e, 0x27, 0x76, 0x5a, 0x09, 0x58, 0xb0, 0x9b, 0x73, 0xce, - 0xcc, 0xf5, 0x9c, 0xb9, 0xe7, 0x26, 0x30, 0xca, 0xab, 0xb3, 0x38, 0x3a, 0x9f, 0xe6, 0x45, 0xa6, - 0x32, 0xee, 0x44, 0xa9, 0x92, 0x45, 0x1a, 0xc6, 0xfe, 0x12, 0x7a, 0xf3, 0x48, 0x25, 0x61, 0xce, - 0x39, 0xd8, 0xf3, 0x48, 0x95, 0x2e, 0xf3, 0xac, 0xc0, 0x16, 0xb4, 0xe6, 0x4f, 0xa0, 0xfb, 0x42, - 0xa9, 0xa2, 0x74, 0x3b, 0x9e, 0x15, 0x0c, 0x67, 0x5b, 0x53, 0x73, 0x6e, 0x8a, 0xb4, 0xd0, 0x22, - 0x9e, 0x3c, 0x92, 0xab, 0xd2, 0xb5, 0x3c, 0x2b, 0x18, 0x08, 0x5a, 0xfb, 0xcf, 0xc0, 0x7e, 0x15, - 0x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x14, 0x26, 0x47, - 0x18, 0xc8, 0xa7, 0xcd, 0x70, 0xd2, 0xeb, 0x0f, 0x67, 0xbc, 0x29, 0x61, 0x14, 0xd1, 0x0c, 0xb0, - 0x49, 0x33, 0xf6, 0x62, 0xac, 0xd3, 0xec, 0xff, 0x64, 0x30, 0x5e, 0x24, 0x79, 0x56, 0xa8, 0x56, - 0x42, 0x16, 0xe9, 0x85, 0xbc, 0x36, 0x09, 0x21, 0x80, 0xec, 0x61, 0x11, 0x26, 0x7a, 0x14, 0x06, - 0x42, 0x03, 0x64, 0x29, 0x29, 0x94, 0x0c, 0x5b, 0x68, 0x40, 0x99, 0xc0, 0x61, 0x2f, 0x5d, 0x5b, - 0xa7, 0x49, 0x23, 0xcc, 0xbe, 0x99, 0xf5, 0xd2, 0xed, 0x92, 0xd4, 0x10, 0x98, 0xfd, 0xf5, 0xb0, - 0x63, 0x5e, 0xac, 0xc0, 0x12, 0x2d, 0x06, 0xdf, 0x41, 0x64, 0x57, 0xf4, 0x0b, 0xd7, 0xa7, 0x5f, - 0x38, 0x03, 0xf1, 0xa4, 0x2e, 0x43, 0xa2, 0x43, 0x62, 0x8b, 0xf1, 0xbf, 0x30, 0xe0, 0xda, 0x23, - 0x4d, 0xd1, 0xff, 0x33, 0x8a, 0x7b, 0x23, 0x19, 0xeb, 0xc6, 0xe0, 0x5e, 0x04, 0x7f, 0xb1, 0xb9, - 0x03, 0x3d, 0xba, 0x85, 0xb1, 0x58, 0xa3, 0x5b, 0x26, 0xfa, 0xb7, 0x4d, 0xcc, 0xb7, 0xbf, 0xde, - 0x4c, 0xd8, 0xf7, 0x9b, 0x09, 0xfb, 0x71, 0x33, 0x61, 0x1f, 0x7f, 0x4d, 0xee, 0x9d, 0xf5, 0xe8, - 0x4f, 0xe4, 0xe9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7e, 0x3e, 0xba, 0x23, 0x54, 0x06, 0x00, - 0x00, + // 707 bytes of a gzipped FileDescriptorProto + 0x1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, 0xc4, 0xd8, 0x82, 0x91, 0x09, 0x71, 0xf0, 0x8d, 0xc1, 0x68, 0xbe, 0xcc, 0x54, + 0xae, 0x1b, 0xc1, 0x98, 0xa7, 0x57, 0xf2, 0xc6, 0x06, 0x83, 0x00, 0xb2, 0xc7, 0x79, 0xb4, 0x34, + 0x13, 0xd0, 0x17, 0x06, 0x20, 0x4b, 0x01, 0xa1, 0x40, 0xb8, 0xc2, 0x00, 0x8a, 0x02, 0xce, 0x78, + 0xe1, 0xb9, 0x26, 0x44, 0x06, 0x61, 0xe4, 0xed, 0x88, 0x17, 0x5e, 0x9b, 0xa4, 0x9a, 0xc0, 0xc8, + 0x6f, 0x66, 0x1c, 0x63, 0xe2, 0x84, 0x8e, 0x68, 0x30, 0xf8, 0x0e, 0x42, 0xad, 0xe8, 0x87, 0xad, + 0x4b, 0x3f, 0x6c, 0x16, 0xe2, 0x49, 0x53, 0x86, 0xc4, 0x1e, 0x89, 0x0d, 0x26, 0xf8, 0xc4, 0x80, + 0x1b, 0x8f, 0x34, 0x3c, 0x7f, 0xce, 0x28, 0xee, 0x8d, 0x65, 0x62, 0x1a, 0x83, 0x7b, 0x11, 0xfc, + 0xc2, 0xe6, 0x1e, 0x74, 0xe8, 0x16, 0xd6, 0x62, 0x85, 0xee, 0x98, 0xe8, 0xde, 0x35, 0x31, 0xdb, + 0xfd, 0x7c, 0x3b, 0x66, 0x5f, 0x6e, 0xc7, 0xec, 0xeb, 0xed, 0x98, 0xbd, 0xfb, 0x3e, 0xfe, 0xeb, + 0xa2, 0x43, 0x7f, 0x1c, 0x8f, 0x7e, 0x04, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x35, 0x66, 0x28, 0x48, + 0x06, 0x00, 0x00, } diff --git a/internal/public.proto b/internal/public.proto index 026a3748b..f2afdb7f9 100644 --- a/internal/public.proto +++ b/internal/public.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package internal; -message Bitmap { +message Row { repeated uint64 Bits = 1; repeated string Keys = 3; repeated Attr Attrs = 2; @@ -61,7 +61,7 @@ message QueryResponse { message QueryResult { uint32 Type = 6; - Bitmap Bitmap = 1; + Row Row = 1; uint64 N = 2; repeated Pair Pairs = 3; ValCount ValCount = 5; diff --git a/bitmap.go b/row.go similarity index 52% rename from bitmap.go rename to row.go index 0b805aa4a..740caa7d8 100644 --- a/bitmap.go +++ b/row.go @@ -22,30 +22,30 @@ import ( "github.com/pilosa/pilosa/roaring" ) -// Bitmap represents a set of bits. -type Bitmap struct { - segments []BitmapSegment +// Row represents a set of bits. +type Row struct { + segments []RowSegment - // Attributes associated with the bitmap. + // Attributes associated with the row. Attrs map[string]interface{} } -// NewBitmap returns a new instance of Bitmap. -func NewBitmap(bits ...uint64) *Bitmap { - bm := &Bitmap{} +// NewRow returns a new instance of Row. +func NewRow(bits ...uint64) *Row { + r := &Row{} for _, i := range bits { - bm.SetBit(i) + r.SetBit(i) } - return bm + return r } -// Merge merges data from other into b. -func (b *Bitmap) Merge(other *Bitmap) { - var segments []BitmapSegment +// Merge merges data from other into r. +func (r *Row) Merge(other *Row) { + var segments []RowSegment - itr := newMergeSegmentIterator(b.segments, other.segments) + itr := newMergeSegmentIterator(r.segments, other.segments) for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() { - // Use the other bitmap's data if segment is missing. + // Use the other row's data if segment is missing. if s0 == nil { segments = append(segments, *s1) continue @@ -59,15 +59,15 @@ func (b *Bitmap) Merge(other *Bitmap) { segments = append(segments, *s0) } - b.segments = segments - b.InvalidateCount() + r.segments = segments + r.InvalidateCount() } -// IntersectionCount returns the number of intersections between b and other. -func (b *Bitmap) IntersectionCount(other *Bitmap) uint64 { +// IntersectionCount returns the number of intersections between r and other. +func (r *Row) IntersectionCount(other *Row) uint64 { var n uint64 - itr := newMergeSegmentIterator(b.segments, other.segments) + itr := newMergeSegmentIterator(r.segments, other.segments) for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() { // Ignore non-overlapping segments. if s0 == nil || s1 == nil { @@ -79,11 +79,11 @@ func (b *Bitmap) IntersectionCount(other *Bitmap) uint64 { return n } -// Intersect returns the itersection of b and other. -func (b *Bitmap) Intersect(other *Bitmap) *Bitmap { - var segments []BitmapSegment +// Intersect returns the itersection of r and other. +func (r *Row) Intersect(other *Row) *Row { + var segments []RowSegment - itr := newMergeSegmentIterator(b.segments, other.segments) + itr := newMergeSegmentIterator(r.segments, other.segments) for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() { // Ignore non-overlapping segments. if s0 == nil || s1 == nil { @@ -92,14 +92,14 @@ func (b *Bitmap) Intersect(other *Bitmap) *Bitmap { segments = append(segments, *s0.Intersect(s1)) } - return &Bitmap{segments: segments} + return &Row{segments: segments} } -// Xor returns the xor of b and other. -func (b *Bitmap) Xor(other *Bitmap) *Bitmap { - var segments []BitmapSegment +// Xor returns the xor of r and other. +func (r *Row) Xor(other *Row) *Row { + var segments []RowSegment - itr := newMergeSegmentIterator(b.segments, other.segments) + itr := newMergeSegmentIterator(r.segments, other.segments) for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() { if s1 == nil { segments = append(segments, *s0) @@ -112,13 +112,13 @@ func (b *Bitmap) Xor(other *Bitmap) *Bitmap { segments = append(segments, *s0.Xor(s1)) } - return &Bitmap{segments: segments} + return &Row{segments: segments} } -// Union returns the bitwise union of b and other. -func (b *Bitmap) Union(other *Bitmap) *Bitmap { - var segments []BitmapSegment - itr := newMergeSegmentIterator(b.segments, other.segments) +// Union returns the bitwise union of r and other. +func (r *Row) Union(other *Row) *Row { + var segments []RowSegment + itr := newMergeSegmentIterator(r.segments, other.segments) for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() { if s1 == nil { segments = append(segments, *s0) @@ -130,14 +130,14 @@ func (b *Bitmap) Union(other *Bitmap) *Bitmap { segments = append(segments, *s0.Union(s1)) } - return &Bitmap{segments: segments} + return &Row{segments: segments} } -// Difference returns the diff of b and other. -func (b *Bitmap) Difference(other *Bitmap) *Bitmap { - var segments []BitmapSegment +// Difference returns the diff of r and other. +func (r *Row) Difference(other *Row) *Row { + var segments []RowSegment - itr := newMergeSegmentIterator(b.segments, other.segments) + itr := newMergeSegmentIterator(r.segments, other.segments) for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() { if s0 == nil { continue @@ -148,17 +148,17 @@ func (b *Bitmap) Difference(other *Bitmap) *Bitmap { segments = append(segments, *s0.Difference(s1)) } - return &Bitmap{segments: segments} + return &Row{segments: segments} } -// SetBit sets the i-th bit of the bitmap. -func (b *Bitmap) SetBit(i uint64) (changed bool) { - return b.createSegmentIfNotExists(i / SliceWidth).SetBit(i) +// SetBit sets the i-th bit of the row. +func (r *Row) SetBit(i uint64) (changed bool) { + return r.createSegmentIfNotExists(i / SliceWidth).SetBit(i) } -// ClearBit clears the i-th bit of the bitmap. -func (b *Bitmap) ClearBit(i uint64) (changed bool) { - s := b.segment(i / SliceWidth) +// ClearBit clears the i-th bit of the row. +func (r *Row) ClearBit(i uint64) (changed bool) { + s := r.segment(i / SliceWidth) if s == nil { return false } @@ -167,58 +167,58 @@ func (b *Bitmap) ClearBit(i uint64) (changed bool) { // segment returns a segment for a given slice. // Returns nil if segment does not exist. -func (b *Bitmap) segment(slice uint64) *BitmapSegment { - if i := sort.Search(len(b.segments), func(i int) bool { - return b.segments[i].slice >= slice - }); i < len(b.segments) && b.segments[i].slice == slice { - return &b.segments[i] +func (r *Row) segment(slice uint64) *RowSegment { + if i := sort.Search(len(r.segments), func(i int) bool { + return r.segments[i].slice >= slice + }); i < len(r.segments) && r.segments[i].slice == slice { + return &r.segments[i] } return nil } -func (b *Bitmap) createSegmentIfNotExists(slice uint64) *BitmapSegment { - i := sort.Search(len(b.segments), func(i int) bool { - return b.segments[i].slice >= slice +func (r *Row) createSegmentIfNotExists(slice uint64) *RowSegment { + i := sort.Search(len(r.segments), func(i int) bool { + return r.segments[i].slice >= slice }) // Return exact match. - if i < len(b.segments) && b.segments[i].slice == slice { - return &b.segments[i] + if i < len(r.segments) && r.segments[i].slice == slice { + return &r.segments[i] } // Insert new segment. - b.segments = append(b.segments, BitmapSegment{data: *roaring.NewBitmap()}) - if i < len(b.segments) { - copy(b.segments[i+1:], b.segments[i:]) + r.segments = append(r.segments, RowSegment{data: *roaring.NewBitmap()}) + if i < len(r.segments) { + copy(r.segments[i+1:], r.segments[i:]) } - b.segments[i] = BitmapSegment{ + r.segments[i] = RowSegment{ data: *roaring.NewBitmap(), slice: slice, writable: true, } - return &b.segments[i] + return &r.segments[i] } -// InvalidateCount updates the cached count in the bitmap. -func (b *Bitmap) InvalidateCount() { - for i := range b.segments { - b.segments[i].InvalidateCount() +// InvalidateCount updates the cached count in the row. +func (r *Row) InvalidateCount() { + for i := range r.segments { + r.segments[i].InvalidateCount() } } -// IncrementCount increments the bitmap cached counter, note this is an optimization that assumes that the caller is aware the size increased. -func (b *Bitmap) IncrementCount(i uint64) { - seg := b.segment(i / SliceWidth) +// IncrementCount increments the row cached counter, note this is an optimization that assumes that the caller is aware the size increased. +func (r *Row) IncrementCount(i uint64) { + seg := r.segment(i / SliceWidth) if seg != nil { seg.n++ } } -// DecrementCount decrements the bitmap cached counter. -func (b *Bitmap) DecrementCount(i uint64) { - seg := b.segment(i / SliceWidth) +// DecrementCount decrements the row cached counter. +func (r *Row) DecrementCount(i uint64) { + seg := r.segment(i / SliceWidth) if seg != nil { if seg.n > 0 { seg.n-- @@ -226,24 +226,24 @@ func (b *Bitmap) DecrementCount(i uint64) { } } -// Count returns the number of set bits in the bitmap. -func (b *Bitmap) Count() uint64 { +// Count returns the number of set bits in the row. +func (r *Row) Count() uint64 { var n uint64 - for i := range b.segments { - n += b.segments[i].Count() + for i := range r.segments { + n += r.segments[i].Count() } return n } -// MarshalJSON returns a JSON-encoded byte slice of b. -func (b *Bitmap) MarshalJSON() ([]byte, error) { +// MarshalJSON returns a JSON-encoded byte slice of r. +func (r *Row) MarshalJSON() ([]byte, error) { var o struct { Attrs map[string]interface{} `json:"attrs"` Bits []uint64 `json:"bits"` } - o.Bits = b.Bits() + o.Bits = r.Bits() - o.Attrs = b.Attrs + o.Attrs = r.Attrs if o.Attrs == nil { o.Attrs = make(map[string]interface{}) } @@ -251,54 +251,54 @@ func (b *Bitmap) MarshalJSON() ([]byte, error) { return json.Marshal(&o) } -// Bits returns the bits in b as a slice of ints. -func (b *Bitmap) Bits() []uint64 { - a := make([]uint64, 0, b.Count()) - for i := range b.segments { - a = append(a, b.segments[i].Bits()...) +// Bits returns the bits in r as a slice of ints. +func (r *Row) Bits() []uint64 { + a := make([]uint64, 0, r.Count()) + for i := range r.segments { + a = append(a, r.segments[i].Bits()...) } return a } -// encodeBitmap converts b into its internal representation. -func encodeBitmap(b *Bitmap) *internal.Bitmap { - if b == nil { +// encodeRow converts r into its internal representation. +func encodeRow(r *Row) *internal.Row { + if r == nil { return nil } - return &internal.Bitmap{ - Bits: b.Bits(), - Attrs: encodeAttrs(b.Attrs), + return &internal.Row{ + Bits: r.Bits(), + Attrs: encodeAttrs(r.Attrs), } } -// decodeBitmap converts b from its internal representation. -func decodeBitmap(pb *internal.Bitmap) *Bitmap { - if pb == nil { +// decodeRow converts r from its internal representation. +func decodeRow(pr *internal.Row) *Row { + if pr == nil { return nil } - b := NewBitmap() - b.Attrs = decodeAttrs(pb.Attrs) - for _, v := range pb.Bits { - b.SetBit(v) + r := NewRow() + r.Attrs = decodeAttrs(pr.Attrs) + for _, v := range pr.Bits { + r.SetBit(v) } - return b + return r } -// Union performs a union on a slice of bitmaps. -func Union(bitmaps []*Bitmap) *Bitmap { - other := bitmaps[0] - for _, bm := range bitmaps[1:] { - other = other.Union(bm) +// Union performs a union on a slice of rows. +func Union(rows []*Row) *Row { + other := rows[0] + for _, r := range rows[1:] { + other = other.Union(r) } return other } -// BitmapSegment holds a subset of a bitmap. +// RowSegment holds a subset of a row. // This could point to a mmapped roaring bitmap or an in-memory bitmap. The // width of the segment will always match the slice width. -type BitmapSegment struct { +type RowSegment struct { // Slice this segment belongs to slice uint64 @@ -314,7 +314,7 @@ type BitmapSegment struct { // Merge adds chunks from other to s. // Chunks in s are overwritten if they exist in other. -func (s *BitmapSegment) Merge(other *BitmapSegment) { +func (s *RowSegment) Merge(other *RowSegment) { s.ensureWritable() itr := other.data.Iterator() @@ -324,15 +324,15 @@ func (s *BitmapSegment) Merge(other *BitmapSegment) { } // IntersectionCount returns the number of intersections between s and other. -func (s *BitmapSegment) IntersectionCount(other *BitmapSegment) uint64 { +func (s *RowSegment) IntersectionCount(other *RowSegment) uint64 { return s.data.IntersectionCount(&other.data) } // Intersect returns the itersection of s and other. -func (s *BitmapSegment) Intersect(other *BitmapSegment) *BitmapSegment { +func (s *RowSegment) Intersect(other *RowSegment) *RowSegment { data := s.data.Intersect(&other.data) - return &BitmapSegment{ + return &RowSegment{ data: *data, slice: s.slice, n: data.Count(), @@ -340,10 +340,10 @@ func (s *BitmapSegment) Intersect(other *BitmapSegment) *BitmapSegment { } // Union returns the bitwise union of s and other. -func (s *BitmapSegment) Union(other *BitmapSegment) *BitmapSegment { +func (s *RowSegment) Union(other *RowSegment) *RowSegment { data := s.data.Union(&other.data) - return &BitmapSegment{ + return &RowSegment{ data: *data, slice: s.slice, n: data.Count(), @@ -351,10 +351,10 @@ func (s *BitmapSegment) Union(other *BitmapSegment) *BitmapSegment { } // Difference returns the diff of s and other. -func (s *BitmapSegment) Difference(other *BitmapSegment) *BitmapSegment { +func (s *RowSegment) Difference(other *RowSegment) *RowSegment { data := s.data.Difference(&other.data) - return &BitmapSegment{ + return &RowSegment{ data: *data, slice: s.slice, n: data.Count(), @@ -362,18 +362,18 @@ func (s *BitmapSegment) Difference(other *BitmapSegment) *BitmapSegment { } // Xor returns the xor of s and other. -func (s *BitmapSegment) Xor(other *BitmapSegment) *BitmapSegment { +func (s *RowSegment) Xor(other *RowSegment) *RowSegment { data := s.data.Xor(&other.data) - return &BitmapSegment{ + return &RowSegment{ data: *data, slice: s.slice, n: data.Count(), } } -// SetBit sets the i-th bit of the bitmap. -func (s *BitmapSegment) SetBit(i uint64) (changed bool) { +// SetBit sets the i-th bit of the row. +func (s *RowSegment) SetBit(i uint64) (changed bool) { s.ensureWritable() changed, _ = s.data.Add(i) if changed { @@ -382,8 +382,8 @@ func (s *BitmapSegment) SetBit(i uint64) (changed bool) { return changed } -// ClearBit clears the i-th bit of the bitmap. -func (s *BitmapSegment) ClearBit(i uint64) (changed bool) { +// ClearBit clears the i-th bit of the row. +func (s *RowSegment) ClearBit(i uint64) (changed bool) { s.ensureWritable() changed, _ = s.data.Remove(i) @@ -393,13 +393,13 @@ func (s *BitmapSegment) ClearBit(i uint64) (changed bool) { return changed } -// InvalidateCount updates the cached count in the bitmap. -func (s *BitmapSegment) InvalidateCount() { +// InvalidateCount updates the cached count in the row. +func (s *RowSegment) InvalidateCount() { s.n = s.data.Count() } // Bits returns a list of all bits set in the segment. -func (s *BitmapSegment) Bits() []uint64 { +func (s *RowSegment) Bits() []uint64 { a := make([]uint64, 0, s.Count()) itr := s.data.Iterator() for v, eof := itr.Next(); !eof; v, eof = itr.Next() { @@ -408,11 +408,11 @@ func (s *BitmapSegment) Bits() []uint64 { return a } -// Count returns the number of set bits in the bitmap. -func (s *BitmapSegment) Count() uint64 { return s.n } +// Count returns the number of set bits in the row. +func (s *RowSegment) Count() uint64 { return s.n } // ensureWritable clones the segment if it is pointing to non-writable data. -func (s *BitmapSegment) ensureWritable() { +func (s *RowSegment) ensureWritable() { if s.writable { return } @@ -423,16 +423,16 @@ func (s *BitmapSegment) ensureWritable() { // mergeSegmentIterator produces an iterator that loops through two sets of segments. type mergeSegmentIterator struct { - a0, a1 []BitmapSegment + a0, a1 []RowSegment } // newMergeSegmentIterator returns a new instance of mergeSegmentIterator. -func newMergeSegmentIterator(a0, a1 []BitmapSegment) mergeSegmentIterator { +func newMergeSegmentIterator(a0, a1 []RowSegment) mergeSegmentIterator { return mergeSegmentIterator{a0: a0, a1: a1} } // next returns the next set of segments. -func (itr *mergeSegmentIterator) next() (s0, s1 *BitmapSegment) { +func (itr *mergeSegmentIterator) next() (s0, s1 *RowSegment) { // Find current segments. if len(itr.a0) > 0 { s0 = &itr.a0[0] diff --git a/bitmap_test.go b/row_test.go similarity index 68% rename from bitmap_test.go rename to row_test.go index 7eed299fc..61eae8a81 100644 --- a/bitmap_test.go +++ b/row_test.go @@ -22,45 +22,45 @@ import ( "github.com/pilosa/pilosa" ) -// Ensure a bitmap can be merged -func TestBitmap_Merge(t *testing.T) { +// Ensure a row can be merged +func TestRow_Merge(t *testing.T) { tests := []struct { - bm1 *pilosa.Bitmap - bm2 *pilosa.Bitmap + r1 *pilosa.Row + r2 *pilosa.Row exp uint64 }{ { - bm1: pilosa.NewBitmap(1, 2, 3, SliceWidth+1, 2*SliceWidth), - bm2: pilosa.NewBitmap(3, 4, 5), + r1: pilosa.NewRow(1, 2, 3, SliceWidth+1, 2*SliceWidth), + r2: pilosa.NewRow(3, 4, 5), exp: 7, }, { - bm1: pilosa.NewBitmap(), - bm2: pilosa.NewBitmap(2, 66000, 70000, 70001, 70002, 70003, 70004), + r1: pilosa.NewRow(), + r2: pilosa.NewRow(2, 66000, 70000, 70001, 70002, 70003, 70004), exp: 7, }, } for i, test := range tests { t.Run(fmt.Sprintf("#%d:", i), func(t *testing.T) { - test.bm1.Merge(test.bm2) - if cnt := test.bm1.Count(); cnt != test.exp { + test.r1.Merge(test.r2) + if cnt := test.r1.Count(); cnt != test.exp { t.Fatalf("merged count %d is not %d", cnt, test.exp) } - if length := len(test.bm1.Bits()); uint64(length) != test.exp { + if length := len(test.r1.Bits()); uint64(length) != test.exp { t.Fatalf("merged length %d is not %d", length, test.exp) } }) } } -// Ensure a bitmap can Xor'ed -func TestBitmap_Xor(t *testing.T) { - bm1 := pilosa.NewBitmap(0, 1, SliceWidth) - bm2 := pilosa.NewBitmap(0, 2*SliceWidth) +// Ensure a row can Xor'ed +func TestRow_Xor(t *testing.T) { + r1 := pilosa.NewRow(0, 1, SliceWidth) + r2 := pilosa.NewRow(0, 2*SliceWidth) exp := []uint64{1, SliceWidth, 2 * SliceWidth} - res := bm1.Xor(bm2) + res := r1.Xor(r2) if res.Count() != 3 { t.Fatalf("Test 1 Count after xor %d != 3\n", res.Count()) } @@ -68,7 +68,7 @@ func TestBitmap_Xor(t *testing.T) { if !reflect.DeepEqual(res.Bits(), exp) { t.Fatalf("Test 2 Results %v != expected %v\n", res.Bits(), exp) } - res = bm2.Xor(bm1) + res = r2.Xor(r1) if res.Count() != 3 { t.Fatalf("Test 3 Count after xor %d != 3\n", res.Count()) } @@ -77,11 +77,11 @@ func TestBitmap_Xor(t *testing.T) { } } -func TestBitmap_Union_Segment(t *testing.T) { - bm1 := pilosa.NewBitmap(0, 1, SliceWidth) - bm2 := pilosa.NewBitmap(0, 2*SliceWidth) +func TestRow_Union_Segment(t *testing.T) { + r1 := pilosa.NewRow(0, 1, SliceWidth) + r2 := pilosa.NewRow(0, 2*SliceWidth) exp := []uint64{0, 1, SliceWidth, 2 * SliceWidth} - res := bm1.Union(bm2) + res := r1.Union(r2) if res.Count() != 4 { t.Fatalf("Test 1 Count after Union %d != 5\n", res.Count()) @@ -89,7 +89,7 @@ func TestBitmap_Union_Segment(t *testing.T) { if !reflect.DeepEqual(res.Bits(), exp) { t.Fatalf("Test 2 Union Results %v != expected %v\n", res.Bits(), exp) } - res = bm2.Union(bm1) + res = r2.Union(r1) if res.Count() != 4 { t.Fatalf("Test 3 Count after xor %d != 5\n", res.Count()) } @@ -98,11 +98,11 @@ func TestBitmap_Union_Segment(t *testing.T) { } } -func TestBitmap_Difference_Segment(t *testing.T) { - bm1 := pilosa.NewBitmap(0, 1, SliceWidth) - bm2 := pilosa.NewBitmap(0, 2*SliceWidth) +func TestRow_Difference_Segment(t *testing.T) { + r1 := pilosa.NewRow(0, 1, SliceWidth) + r2 := pilosa.NewRow(0, 2*SliceWidth) exp := []uint64{1, SliceWidth} - res := bm1.Difference(bm2) + res := r1.Difference(r2) if res.Count() != 2 { t.Fatalf("Test 1 Count after Difference %d != 5\n", res.Count()) diff --git a/view.go b/view.go index a3ce22661..e825aa8ef 100644 --- a/view.go +++ b/view.go @@ -346,7 +346,7 @@ func (v *View) SetFieldValue(columnID uint64, bitDepth uint, value uint64) (chan } // FieldSum returns the sum & count of a field. -func (v *View) FieldSum(filter *Bitmap, bitDepth uint) (sum, count uint64, err error) { +func (v *View) FieldSum(filter *Row, bitDepth uint) (sum, count uint64, err error) { for _, f := range v.Fragments() { fsum, fcount, err := f.FieldSum(filter, bitDepth) if err != nil { @@ -359,7 +359,7 @@ func (v *View) FieldSum(filter *Bitmap, bitDepth uint) (sum, count uint64, err e } // FieldMin returns the min and count of a field. -func (v *View) FieldMin(filter *Bitmap, bitDepth uint) (min, count uint64, err error) { +func (v *View) FieldMin(filter *Row, bitDepth uint) (min, count uint64, err error) { var minHasValue bool for _, f := range v.Fragments() { fmin, fcount, err := f.FieldMin(filter, bitDepth) @@ -387,7 +387,7 @@ func (v *View) FieldMin(filter *Bitmap, bitDepth uint) (min, count uint64, err e } // FieldMax returns the max and count of a field. -func (v *View) FieldMax(filter *Bitmap, bitDepth uint) (max, count uint64, err error) { +func (v *View) FieldMax(filter *Row, bitDepth uint) (max, count uint64, err error) { for _, f := range v.Fragments() { fmax, fcount, err := f.FieldMax(filter, bitDepth) if err != nil { @@ -401,31 +401,31 @@ func (v *View) FieldMax(filter *Bitmap, bitDepth uint) (max, count uint64, err e return max, count, nil } -// FieldRange returns bitmaps with a field value encoding matching the predicate. -func (v *View) FieldRange(op pql.Token, bitDepth uint, predicate uint64) (*Bitmap, error) { - bm := NewBitmap() +// FieldRange returns rows with a field value encoding matching the predicate. +func (v *View) FieldRange(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { + r := NewRow() for _, frag := range v.Fragments() { other, err := frag.FieldRange(op, bitDepth, predicate) if err != nil { return nil, err } - bm = bm.Union(other) + r = r.Union(other) } - return bm, nil + return r, nil } // FieldRangeBetween returns bitmaps with a field value encoding matching any // value between predicateMin and predicateMax. -func (v *View) FieldRangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Bitmap, error) { - bm := NewBitmap() +func (v *View) FieldRangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) { + r := NewRow() for _, frag := range v.Fragments() { other, err := frag.FieldRangeBetween(bitDepth, predicateMin, predicateMax) if err != nil { return nil, err } - bm = bm.Union(other) + r = r.Union(other) } - return bm, nil + return r, nil } // IsInverseView returns true if the view is used for storing an inverted representation.