add test case and bug fix for distinct code

The "seenThisRow" value was never getting cleared, which meant that
if the first container on a row didn't happen to contain any post-filter
bits, the rest of the row wouldn't get evaluated.
This commit is contained in:
Seebs 2020-10-23 16:18:19 -05:00
parent a2151358ba
commit 765d28bf9d
2 changed files with 16 additions and 6 deletions

View file

@ -1460,10 +1460,14 @@ func executeDistinctShardSet(ctx context.Context, qcx *Qcx, idx *Index, fieldNam
for fragData.Next() {
k, c := fragData.Value()
row := k >> shardVsContainerExponent
if row == prevRow && seenThisRow {
continue
if row == prevRow {
if seenThisRow {
continue
}
} else {
seenThisRow = false
prevRow = row
}
prevRow = row
if filterBitmap != nil {
if roaring.IntersectionAny(c, filter[k%(1<<shardVsContainerExponent)]) {
_, err = rows.Add(row)

View file

@ -6435,19 +6435,25 @@ func TestExecutor_BareDistinct(t *testing.T) {
pilosa.OptFieldTypeInt(0, math.MaxInt64),
)
c.CreateField(t, "i", pilosa.IndexOptions{}, "set")
c.CreateField(t, "i", pilosa.IndexOptions{}, "filter")
// Populate integer data.
c.Query(t, "i", fmt.Sprintf(`
Set(0, ints=1)
Set(%d, ints=2)
`, ShardWidth))
c.Query(t, "i", `Set(0, set=1)
Set(1, set=2)`)
c.Query(t, "i", fmt.Sprintf(`
Set(0, set=1)
Set(1, set=2)
Set(%d, set=2)
Set(0, filter=1)
Set(%d, filter=1)
`, 65537, 65537))
for _, pql := range []string{
`Distinct(field="ints")`,
`Distinct(index="i", field="ints")`,
`Distinct(field="set")`,
`Distinct(Row(filter=1), field="set")`,
} {
exp := []uint64{1, 2}
res := c.Query(t, "i", pql).Results[0].(pilosa.SignedRow)