diff --git a/client_test.go b/client_test.go index 6456ef386..84037d374 100644 --- a/client_test.go +++ b/client_test.go @@ -212,7 +212,7 @@ func TestClient_Import(t *testing.T) { // Load bitmap into cache to ensure cache gets updated. hldr.SetBit("i", "f", 1, 0) // set a bit so the view gets created. - hldr.Row("i", "f", 0, 0) + hldr.Row("i", "f", 0) s := test.NewServer() defer s.Close() @@ -231,10 +231,10 @@ func TestClient_Import(t *testing.T) { } // Verify data. - if a := hldr.Row("i", "f", 0, 0).Columns(); !reflect.DeepEqual(a, []uint64{1, 5}) { + if a := hldr.Row("i", "f", 0).Columns(); !reflect.DeepEqual(a, []uint64{1, 5}) { t.Fatalf("unexpected columns: %+v", a) } - if a := hldr.Row("i", "f", 0, 200).Columns(); !reflect.DeepEqual(a, []uint64{6}) { + if a := hldr.Row("i", "f", 200).Columns(); !reflect.DeepEqual(a, []uint64{6}) { t.Fatalf("unexpected columns: %+v", a) } } diff --git a/executor_test.go b/executor_test.go index a94f7e2fe..221a554e8 100644 --- a/executor_test.go +++ b/executor_test.go @@ -241,7 +241,7 @@ func TestExecutor_Execute_SetBit(t *testing.T) { hldr.SetBit("i", "f", 1, 0) e := test.NewExecutor(hldr.Holder, test.NewCluster(1)) - if n := hldr.Row("i", "f", 0, 11).Count(); n != 0 { + if n := hldr.Row("i", "f", 11).Count(); n != 0 { t.Fatalf("unexpected bitmap count: %d", n) } @@ -253,7 +253,7 @@ func TestExecutor_Execute_SetBit(t *testing.T) { } } - if n := hldr.Row("i", "f", 0, 11).Count(); n != 1 { + if n := hldr.Row("i", "f", 11).Count(); n != 1 { t.Fatalf("unexpected bitmap count: %d", n) } if res, err := e.Execute(context.Background(), "i", test.MustParse(`SetBit(row=11, field=f, col=1)`), nil, nil); err != nil { @@ -1080,7 +1080,7 @@ func TestExecutor_Execute_Remote_SetBit(t *testing.T) { } // Verify that one column is set on both node's holder. - if n := hldr.Row("i", "f", 0, 10).Count(); n != 1 { + if n := hldr.Row("i", "f", 10).Count(); n != 1 { t.Fatalf("unexpected local count: %d", n) } if !remoteCalled { @@ -1134,7 +1134,7 @@ func TestExecutor_Execute_Remote_SetBit_With_Timestamp(t *testing.T) { } // Verify that one column is set on both node's holder. - if n := hldr.ViewRow("i", "f", "standard_2016", 0, 10).Count(); n != 1 { + if n := hldr.ViewRow("i", "f", "standard_2016", 10).Count(); n != 1 { t.Fatalf("unexpected local count: %d", n) } if !remoteCalled { diff --git a/field.go b/field.go index 132458652..8d35de8fa 100644 --- a/field.go +++ b/field.go @@ -620,8 +620,8 @@ func (f *Field) DeleteView(name string) error { return nil } -// Row returns a row for a slice of the standard view. -func (f *Field) Row(slice, rowID uint64) (*Row, error) { +// Row returns a row of the standard view. +func (f *Field) Row(rowID uint64) (*Row, error) { if f.Type() != FieldTypeSet { return nil, errors.Errorf("row method unsupported for field type: %s", f.Type()) } @@ -629,17 +629,17 @@ func (f *Field) Row(slice, rowID uint64) (*Row, error) { if view == nil { return nil, ErrInvalidView } - return view.row(slice, rowID), nil + return view.row(rowID), nil } // ViewRow returns a row for a view and slice. // TODO: unexport this with views (it's only used in tests). -func (f *Field) ViewRow(viewName string, slice, rowID uint64) (*Row, error) { +func (f *Field) ViewRow(viewName string, rowID uint64) (*Row, error) { view := f.View(viewName) if view == nil { return nil, ErrInvalidView } - return view.row(slice, rowID), nil + return view.row(rowID), nil } // SetBit sets a bit on a view within the field. diff --git a/holder_test.go b/holder_test.go index 25d6b5105..9739de65d 100644 --- a/holder_test.go +++ b/holder_test.go @@ -430,23 +430,23 @@ func TestHolderSyncer_SyncHolder(t *testing.T) { // Verify data is the same on both nodes. for i, hldr := range []*test.Holder{hldr0, hldr1} { - if a := hldr.Row("i", "f", 0, 0).Columns(); !reflect.DeepEqual(a, []uint64{10, 4000}) { + if a := hldr.Row("i", "f", 0).Columns(); !reflect.DeepEqual(a, []uint64{10, 4000}) { t.Fatalf("unexpected columns(%d/0): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 2).Columns(); !reflect.DeepEqual(a, []uint64{20}) { + } else if a := hldr.Row("i", "f", 2).Columns(); !reflect.DeepEqual(a, []uint64{20}) { t.Fatalf("unexpected columns(%d/2): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 3).Columns(); !reflect.DeepEqual(a, []uint64{10}) { + } else if a := hldr.Row("i", "f", 3).Columns(); !reflect.DeepEqual(a, []uint64{10}) { t.Fatalf("unexpected columns(%d/3): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 120).Columns(); !reflect.DeepEqual(a, []uint64{10}) { + } else if a := hldr.Row("i", "f", 120).Columns(); !reflect.DeepEqual(a, []uint64{10}) { t.Fatalf("unexpected columns(%d/120): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 200).Columns(); !reflect.DeepEqual(a, []uint64{4}) { + } else if a := hldr.Row("i", "f", 200).Columns(); !reflect.DeepEqual(a, []uint64{4}) { t.Fatalf("unexpected columns(%d/200): %+v", i, a) } - if a := hldr.Row("i", "f0", 1, 9).Columns(); !reflect.DeepEqual(a, []uint64{SliceWidth + 5}) { + if a := hldr.Row("i", "f0", 9).Columns(); !reflect.DeepEqual(a, []uint64{SliceWidth + 5}) { t.Fatalf("unexpected columns(%d/d/f0): %+v", i, a) } - if a := hldr.Row("y", "z", 3, 10).Columns(); !reflect.DeepEqual(a, []uint64{(3 * SliceWidth) + 4, (3 * SliceWidth) + 5, (3 * SliceWidth) + 7}) { + if a := hldr.Row("y", "z", 10).Columns(); !reflect.DeepEqual(a, []uint64{(3 * SliceWidth) + 4, (3 * SliceWidth) + 5, (3 * SliceWidth) + 7}) { t.Fatalf("unexpected columns(%d/y/z): %+v", i, a) } } @@ -506,23 +506,23 @@ func TestHolderCleaner_CleanHolder(t *testing.T) { // Verify data is the same on both nodes. for i, hldr := range []*test.Holder{hldr0} { - if a := hldr.Row("i", "f", 0, 0).Columns(); !reflect.DeepEqual(a, []uint64{10, 4000}) { + if a := hldr.Row("i", "f", 0).Columns(); !reflect.DeepEqual(a, []uint64{10, 4000}) { t.Fatalf("unexpected columns(%d/0): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 2).Columns(); !reflect.DeepEqual(a, []uint64{20}) { + } else if a := hldr.Row("i", "f", 2).Columns(); !reflect.DeepEqual(a, []uint64{20}) { t.Fatalf("unexpected columns(%d/2): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 3).Columns(); !reflect.DeepEqual(a, []uint64{10}) { + } else if a := hldr.Row("i", "f", 3).Columns(); !reflect.DeepEqual(a, []uint64{10}) { t.Fatalf("unexpected columns(%d/3): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 120).Columns(); !reflect.DeepEqual(a, []uint64{10}) { + } else if a := hldr.Row("i", "f", 120).Columns(); !reflect.DeepEqual(a, []uint64{10}) { t.Fatalf("unexpected columns(%d/120): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 200).Columns(); !reflect.DeepEqual(a, []uint64{4}) { + } else if a := hldr.Row("i", "f", 200).Columns(); !reflect.DeepEqual(a, []uint64{4}) { t.Fatalf("unexpected columns(%d/200): %+v", i, a) } - if a := hldr.Row("i", "f0", 1, 9).Columns(); !reflect.DeepEqual(a, []uint64{SliceWidth + 5}) { + if a := hldr.Row("i", "f0", 9).Columns(); !reflect.DeepEqual(a, []uint64{SliceWidth + 5}) { t.Fatalf("unexpected columns(%d/d/f0): %+v", i, a) } - if a := hldr.Row("y", "z", 2, 10).Columns(); !reflect.DeepEqual(a, []uint64{(2 * SliceWidth) + 4, (2 * SliceWidth) + 5, (2 * SliceWidth) + 7}) { + if a := hldr.Row("y", "z", 10).Columns(); !reflect.DeepEqual(a, []uint64{(2 * SliceWidth) + 4, (2 * SliceWidth) + 5, (2 * SliceWidth) + 7}) { t.Fatalf("unexpected columns(%d/y/z): %+v", i, a) } } @@ -543,15 +543,15 @@ func TestHolderCleaner_CleanHolder(t *testing.T) { // Verify data is the same on both nodes. for i, hldr := range []*test.Holder{hldr0} { - if a := hldr.Row("i", "f", 0, 0).Columns(); !reflect.DeepEqual(a, []uint64{10, 4000}) { + if a := hldr.Row("i", "f", 0).Columns(); !reflect.DeepEqual(a, []uint64{10, 4000}) { t.Fatalf("unexpected columns(%d/0): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 2).Columns(); !reflect.DeepEqual(a, []uint64{20}) { + } else if a := hldr.Row("i", "f", 2).Columns(); !reflect.DeepEqual(a, []uint64{20}) { t.Fatalf("unexpected columns(%d/2): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 3).Columns(); !reflect.DeepEqual(a, []uint64{10}) { + } else if a := hldr.Row("i", "f", 3).Columns(); !reflect.DeepEqual(a, []uint64{10}) { t.Fatalf("unexpected columns(%d/3): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 120).Columns(); !reflect.DeepEqual(a, []uint64{10}) { + } else if a := hldr.Row("i", "f", 120).Columns(); !reflect.DeepEqual(a, []uint64{10}) { t.Fatalf("unexpected columns(%d/120): %+v", i, a) - } else if a := hldr.Row("i", "f", 0, 200).Columns(); !reflect.DeepEqual(a, []uint64{4}) { + } else if a := hldr.Row("i", "f", 200).Columns(); !reflect.DeepEqual(a, []uint64{4}) { t.Fatalf("unexpected columns(%d/200): %+v", i, a) } @@ -560,7 +560,7 @@ func TestHolderCleaner_CleanHolder(t *testing.T) { t.Fatalf("expected fragment to be deleted: (%d/i/f0): %+v", i, f) } - if a := hldr.Row("y", "z", 2, 10).Columns(); !reflect.DeepEqual(a, []uint64{(2 * SliceWidth) + 4, (2 * SliceWidth) + 5, (2 * SliceWidth) + 7}) { + if a := hldr.Row("y", "z", 10).Columns(); !reflect.DeepEqual(a, []uint64{(2 * SliceWidth) + 4, (2 * SliceWidth) + 5, (2 * SliceWidth) + 7}) { t.Fatalf("unexpected columns(%d/y/z): %+v", i, a) } } diff --git a/test/holder.go b/test/holder.go index 59c024afc..f49613fb0 100644 --- a/test/holder.go +++ b/test/holder.go @@ -126,13 +126,13 @@ func (h *Holder) MustCreateRankedFragmentIfNotExists(index, field, view string, } // Row returns a Row for a given field. -func (h *Holder) Row(index, field string, slice, rowID uint64) *pilosa.Row { +func (h *Holder) Row(index, field string, rowID uint64) *pilosa.Row { idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{}) f, err := idx.CreateFieldIfNotExists(field, pilosa.FieldOptions{}) if err != nil { panic(err) } - row, err := f.Row(slice, rowID) + row, err := f.Row(rowID) if err != nil { panic(err) } @@ -140,13 +140,13 @@ func (h *Holder) Row(index, field string, slice, rowID uint64) *pilosa.Row { } // ViewRow returns a Row for a given field and view. -func (h *Holder) ViewRow(index, field, view string, slice, rowID uint64) *pilosa.Row { +func (h *Holder) ViewRow(index, field, view string, rowID uint64) *pilosa.Row { idx := h.MustCreateIndexIfNotExists(index, pilosa.IndexOptions{}) f, err := idx.CreateFieldIfNotExists(field, pilosa.FieldOptions{}) if err != nil { panic(err) } - row, err := f.ViewRow(view, slice, rowID) + row, err := f.ViewRow(view, rowID) if err != nil { panic(err) } diff --git a/view.go b/view.go index 181562995..0049edaa1 100644 --- a/view.go +++ b/view.go @@ -304,9 +304,17 @@ func (v *View) DeleteFragment(slice uint64) error { } // row returns a row for a slice of the view. -func (v *View) row(slice, rowID uint64) *Row { - frag := v.Fragment(slice) - return frag.row(rowID) +func (v *View) row(rowID uint64) *Row { + row := NewRow() + for _, frag := range v.Fragments() { + fr := frag.row(rowID) + if fr == nil { + continue + } + row.Merge(fr) + } + return row + } // SetBit sets a bit within the view.