Skip to content

Commit

Permalink
Merge pull request #32 from takashabe/fix-chain-filter
Browse files Browse the repository at this point in the history
Fix ChainFilter when only one filter is used
  • Loading branch information
takashabe authored Nov 6, 2018
2 parents c8a51d9 + 481fb1e commit dfd80d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions api/interfaces/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (e *Executor) readWithOptions(table string, args ...string) {
ctx := context.Background()
rows, err := e.rowsInteractor.GetRows(ctx, table, rr, ro...)
if err != nil {
fmt.Fprintf(e.errStream, "%v", err)
fmt.Fprintf(e.errStream, "%v\n", err)
return
}

Expand Down Expand Up @@ -261,7 +261,10 @@ func readOption(parsedArgs map[string]string) ([]bigtable.ReadOption, error) {
// opts = append(opts, bigtable.RowFilter(bigtable.LatestNFilter(int(n))))
fils = append(fils, bigtable.LatestNFilter(int(n)))
}
if len(fils) > 0 {

if len(fils) == 1 {
opts = append(opts, bigtable.RowFilter(fils[0]))
} else if len(fils) > 1 {
opts = append(opts, bigtable.RowFilter(bigtable.ChainFilters(fils...)))
}

Expand Down
8 changes: 4 additions & 4 deletions api/interfaces/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestReadOption(t *testing.T) {
"regex": "a",
},
[]bigtable.ReadOption{
chainFilters(bigtable.RowKeyFilter("a")),
bigtable.RowFilter(bigtable.RowKeyFilter("a")),
bigtable.LimitRows(1),
},
},
Expand All @@ -67,7 +67,7 @@ func TestReadOption(t *testing.T) {
"family": "d",
},
[]bigtable.ReadOption{
chainFilters(bigtable.FamilyFilter("^d$")),
bigtable.RowFilter(bigtable.FamilyFilter("^d$")),
},
},
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestDoReadRowExecutor(t *testing.T) {
gomock.Any(),
"table",
"a",
chainFilters(bigtable.LatestNFilter(1)),
bigtable.RowFilter(bigtable.LatestNFilter(1)),
).Return(
&domain.Bigtable{
Table: "table",
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestDoReadRowExecutor(t *testing.T) {
gomock.Any(),
"table",
bigtable.PrefixRange("a"),
chainFilters(bigtable.LatestNFilter(1)),
bigtable.RowFilter(bigtable.LatestNFilter(1)),
).Return(
&domain.Bigtable{
Table: "table",
Expand Down

0 comments on commit dfd80d3

Please sign in to comment.