Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(bigtable/bttest): Cells per row offset filters didn't implement t…
…ruthiness correctly, breaking conditional filters (#4287)

Co-authored-by: Christopher Wilcox <crwilcox@google.com>
  • Loading branch information
jimfulton and crwilcox committed Jul 27, 2021
1 parent 3d6c6c7 commit a1a2a77
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bigtable/bttest/inmem.go
Expand Up @@ -612,7 +612,10 @@ func filterRow(f *btpb.RowFilter, r *row) (bool, error) {
offset -= len(cs)
}
}
return true, nil
// If we get here, we have to have consumed all of the cells,
// otherwise, we would have returned above. We're not generating
// a row, so false.
return false, nil
case *btpb.RowFilter_RowSampleFilter:
// The row sample filter "matches all cells from a row with probability
// p, and matches no cells from the row with probability 1-p."
Expand Down
37 changes: 37 additions & 0 deletions bigtable/bttest/inmem_test.go
Expand Up @@ -2033,3 +2033,40 @@ func TestValueFilterRowWithAlternationInRegex(t *testing.T) {
t.Fatalf("Response chunks mismatch: got: + want -\n%s", diff)
}
}

func TestFilterRowCellsPerRowLimitFilterTruthiness(t *testing.T) {
row := &row{
key: "row",
families: map[string]*family{
"fam": {
name: "fam",
cells: map[string][]cell{
"col1": {{ts: 1000, value: []byte("val2")}},
"col2": {
{ts: 1000, value: []byte("val2")},
{ts: 1000, value: []byte("val3")},
},
},
colNames: []string{"col1", "col2"},
},
},
}
for _, test := range []struct {
filter *btpb.RowFilter
want bool
}{
// The regexp-based filters perform whole-string, case-sensitive matches.
{&btpb.RowFilter{Filter: &btpb.RowFilter_CellsPerRowOffsetFilter{1}}, true},
{&btpb.RowFilter{Filter: &btpb.RowFilter_CellsPerRowOffsetFilter{2}}, true},
{&btpb.RowFilter{Filter: &btpb.RowFilter_CellsPerRowOffsetFilter{3}}, false},
{&btpb.RowFilter{Filter: &btpb.RowFilter_CellsPerRowOffsetFilter{4}}, false},
} {
got, err := filterRow(test.filter, row.copy())
if err != nil {
t.Errorf("%s: got unexpected error: %v", proto.CompactTextString(test.filter), err)
}
if got != test.want {
t.Errorf("%s: got %t, want %t", proto.CompactTextString(test.filter), got, test.want)
}
}
}

0 comments on commit a1a2a77

Please sign in to comment.