From 481fb1ecab3b7bad54eca500f3e6f50b0180a246 Mon Sep 17 00:00:00 2001 From: takashabe Date: Tue, 6 Nov 2018 18:35:06 +0900 Subject: [PATCH] Fix ChainFilter when only one filter is used --- api/interfaces/executor.go | 7 +++++-- api/interfaces/executor_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/interfaces/executor.go b/api/interfaces/executor.go index 6c8b730..0b38eb1 100644 --- a/api/interfaces/executor.go +++ b/api/interfaces/executor.go @@ -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 } @@ -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...))) } diff --git a/api/interfaces/executor_test.go b/api/interfaces/executor_test.go index 5eb8f86..1c9b077 100644 --- a/api/interfaces/executor_test.go +++ b/api/interfaces/executor_test.go @@ -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), }, }, @@ -67,7 +67,7 @@ func TestReadOption(t *testing.T) { "family": "d", }, []bigtable.ReadOption{ - chainFilters(bigtable.FamilyFilter("^d$")), + bigtable.RowFilter(bigtable.FamilyFilter("^d$")), }, }, } @@ -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", @@ -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",