add translation for groupby filter arg, improve test

This commit is contained in:
Matt Jaffee 2019-05-10 14:15:06 -05:00
parent de61d04172
commit e185a01e67
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 26 additions and 4 deletions

View file

@ -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

View file

@ -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)
})
}
}