From 773d661b684777610961ea0cb628804c69bb947d Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 21 Jan 2019 18:02:51 +0300 Subject: [PATCH] GroupBy legacy Rows --- executor.go | 13 ++++++++++--- executor_test.go | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/executor.go b/executor.go index f390f41af..fdc19b7a7 100644 --- a/executor.go +++ b/executor.go @@ -1090,7 +1090,8 @@ 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. - // Check "field" first for backwards compatibility + // Check "field" first for backwards compatibility. + // TODO: remove at Pilosa 2.0 var fieldName string var ok bool if fieldName, ok = c.Args["field"].(string); ok { @@ -2763,10 +2764,16 @@ func newGroupByIterator(rowIDs []RowIDs, children []*pql.Call, filter *Row, inde fields: make([]FieldRow, len(children)), } + var fieldName string + var ok bool ignorePrev := false for i, call := range children { - fieldName, ok := call.Args["_field"].(string) - if !ok { + // Check "field" first for backwards compatibility. + // TODO: remove at Pilosa 2.0 + if fieldName, ok = call.Args["field"].(string); ok { + call.Args["_field"] = fieldName + } + if fieldName, ok = call.Args["_field"].(string); !ok { return nil, errors.Errorf("%s call must have field with valid (string) field name. Got %v of type %[2]T", call.Name, call.Args["_field"]) } if holder.Field(index, fieldName) == nil { diff --git a/executor_test.go b/executor_test.go index 4c2bbedd7..110717971 100644 --- a/executor_test.go +++ b/executor_test.go @@ -3300,6 +3300,20 @@ func TestExecutor_Execute_GroupBy(t *testing.T) { } }) + // backwards compatibility + // TODO: remove at Pilosa 2.0 + t.Run("BasicLegacy", func(t *testing.T) { + expected := []pilosa.GroupCount{ + {Group: []pilosa.FieldRow{{Field: "general", RowID: 10}, {Field: "sub", RowID: 100}}, Count: 3}, + {Group: []pilosa.FieldRow{{Field: "general", RowID: 10}, {Field: "sub", RowID: 110}}, Count: 1}, + {Group: []pilosa.FieldRow{{Field: "general", RowID: 11}, {Field: "sub", RowID: 110}}, Count: 1}, + {Group: []pilosa.FieldRow{{Field: "general", RowID: 12}, {Field: "sub", RowID: 110}}, Count: 1}, + } + + results := c.Query(t, "i", `GroupBy(Rows(field=general), Rows(sub))`).Results[0].([]pilosa.GroupCount) + test.CheckGroupBy(t, expected, results) + }) + t.Run("Basic", func(t *testing.T) { expected := []pilosa.GroupCount{ {Group: []pilosa.FieldRow{{Field: "general", RowID: 10}, {Field: "sub", RowID: 100}}, Count: 3},