diff --git a/executor.go b/executor.go index ce30a32c6..41077168e 100644 --- a/executor.go +++ b/executor.go @@ -2536,6 +2536,16 @@ func (e *executor) translateGroupByCall(index string, idx *Index, c *pql.Call) e } } + if filter, ok, err := c.CallArg("filter"); ok { + if err != nil { + return errors.Wrap(err, "getting filter call") + } + err = e.translateCall(index, idx, filter) + if err != nil { + return errors.Wrap(err, "translating filter call") + } + } + prev, ok := c.Args["previous"] if !ok { return nil // nothing else to be translated diff --git a/executor_test.go b/executor_test.go index ce84d04c4..fd3090401 100644 --- a/executor_test.go +++ b/executor_test.go @@ -3262,23 +3262,35 @@ func TestExecutor_GroupByStrings(t *testing.T) { } tests := []struct { - query string + query string + expected []pilosa.GroupCount }{ + { + query: "GroupBy(Rows(generals))", + expected: []pilosa.GroupCount{ + {Group: []pilosa.FieldRow{{Field: "generals", RowID: 1, RowKey: "r1"}}, Count: 5}, + {Group: []pilosa.FieldRow{{Field: "generals", RowID: 2, RowKey: "r2"}}, Count: 5}, + }, + }, { query: "GroupBy(Rows(generals), filter=Row(generals=r2))", + expected: []pilosa.GroupCount{ + {Group: []pilosa.FieldRow{{Field: "generals", RowID: 2, RowKey: "r2"}}, Count: 5}, + }, }, } - for i, test := range tests { + for i, tst := range tests { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { r, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{ Index: "istring", - Query: test.query, + Query: tst.query, }) if err != nil { t.Fatalf("got an error %v", err) } - fmt.Println(r) + results := r.Results[0].([]pilosa.GroupCount) + test.CheckGroupBy(t, tst.expected, results) }) } }