From c30f9bc192f009d55e66470c5ebb2eef8bf02f2e Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Fri, 18 Jan 2019 17:41:54 +0300 Subject: [PATCH] Rows accepts a fields param for backward compat. --- executor.go | 10 +++++++--- executor_test.go | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/executor.go b/executor.go index 1543e967e..34de879fe 100644 --- a/executor.go +++ b/executor.go @@ -1090,9 +1090,13 @@ func (e *executor) executeGroupByShard(ctx context.Context, index string, c *pql func (e *executor) executeRows(ctx context.Context, index string, c *pql.Call, shards []uint64, opt *execOptions) (RowIDs, error) { // Fetch field name from argument. - fieldName, ok := c.Args["_field"].(string) - if !ok { - return nil, errors.New("Rows() field required") + // Check "field" first for backwards compatibility + var fieldName string + var ok bool + if fieldName, ok = c.Args["field"].(string); !ok { + if fieldName, ok = c.Args["_field"].(string); !ok { + return nil, errors.New("Rows() field required") + } } if columnID, ok, err := c.UintArg("column"); err != nil { return nil, errors.Wrap(err, "getting column") diff --git a/executor_test.go b/executor_test.go index fda3c8d89..ac37055a6 100644 --- a/executor_test.go +++ b/executor_test.go @@ -3043,6 +3043,13 @@ func TestExecutor_Execute_Rows(t *testing.T) { t.Fatalf("unexpected rows: %+v", rows) } + // backwards compatibility + // TODO: remove at Pilosa 2.0 + rows = c.Query(t, "i", `Rows(field=general)`).Results[0].(pilosa.RowIdentifiers) + if !reflect.DeepEqual(rows, pilosa.RowIdentifiers{Rows: []uint64{10, 11, 12, 13}}) { + t.Fatalf("unexpected rows: %+v", rows) + } + rows = c.Query(t, "i", `Rows(general, limit=2)`).Results[0].(pilosa.RowIdentifiers) if !reflect.DeepEqual(rows, pilosa.RowIdentifiers{Rows: []uint64{10, 11}}) { t.Fatalf("unexpected rows: %+v", rows) @@ -3154,10 +3161,22 @@ func TestExecutor_Execute_Rows_Keys(t *testing.T) { q: `Rows(f)`, exp: []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, }, + // backwards compatibility + // TODO: remove at Pilosa 2.0 + { + q: `Rows(field=f)`, + exp: []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, + }, { q: `Rows(f, limit=2)`, exp: []string{"0", "1"}, }, + // backwards compatibility + // TODO: remove at Pilosa 2.0 + { + q: `Rows(field=f, limit=2)`, + exp: []string{"0", "1"}, + }, { q: `Rows(f, previous="15")`, exp: []string{"16", "17", "18"},