Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigtable/bttest): Cells per row offset filters didn't implement truthiness correctly, breaking conditional filters #4287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}
}
}