fix logic bug applying limit to group by rows

check in failing test showing how applying the limit to each rows query can
cause the query to falsely return no results
This commit is contained in:
Matt Jaffee 2018-10-09 19:27:10 -05:00
parent 578c594755
commit 603b0e5369
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 22 additions and 2 deletions

View file

@ -851,7 +851,7 @@ func (e *executor) executeGroupBy(ctx context.Context, index string, c *pql.Call
}
if limit, hasLimit, err := child.UintArg("limit"); err != nil {
return nil, err
} else if hasLimit && int(limit) > gbLimit {
} else if !hasLimit || int(limit) > gbLimit {
child.Args["limit"] = uint64(gbLimit)
}
var err error

View file

@ -2416,6 +2416,26 @@ func TestExecutor_Execute_GroupBy(t *testing.T) {
checkGroupBy(t, expected, results)
})
c.CreateField(t, "i", pilosa.IndexOptions{}, "a")
c.CreateField(t, "i", pilosa.IndexOptions{}, "b")
c.ImportBits(t, "i", "a", [][2]uint64{
{0, 1},
{1, ShardWidth + 1},
})
c.ImportBits(t, "i", "b", [][2]uint64{
{0, ShardWidth + 1},
{1, 1},
})
t.Run("tricky data", func(t *testing.T) {
expected := []pilosa.GroupCount{
{Group: []pilosa.FieldRow{{Field: "a", RowID: 0}, {Field: "b", RowID: 1}}, Count: 1},
}
results := c.Query(t, "i", `GroupBy(Rows(field=a), Rows(field=b), limit=1)`).Results[0].([]pilosa.GroupCount)
checkGroupBy(t, expected, results)
})
}
func checkGroupBy(t *testing.T, expected, results []pilosa.GroupCount) {
@ -2434,7 +2454,7 @@ func checkGroupBy(t *testing.T, expected, results []pilosa.GroupCount) {
}
for _, result := range results {
if notIn(result, expected) {
t.Fatalf("unexpected grouping: \n%+v\n\n\n%+v\n", result, expected)
t.Fatalf("unexpected results: \n got:%+v\nwant:%+v\n", results, expected)
}
}
}