mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
Adjust bare-distinct logic.
If an index is provided to a bare distinct which happens to be the index handling the query, then the query needs to behave as if no index argument was provided. For example: When querying against index `i`, ``` Distinct(index="i", field="ints")` ``` should behave exactly like ``` Distinct(field="ints") ```
This commit is contained in:
parent
a495b6c227
commit
0374bda45f
2 changed files with 30 additions and 1 deletions
|
|
@ -438,7 +438,7 @@ func (e *executor) execute(ctx context.Context, index string, q *pql.Query, shar
|
|||
// still need to handle them. Since everything else was
|
||||
// already precomputed by handlePreCallChildren, though,
|
||||
// we don't need this logic in executeCall.
|
||||
if newIndex := call.CallIndex(); newIndex != "" {
|
||||
if newIndex := call.CallIndex(); newIndex != "" && newIndex != index {
|
||||
v, err = e.executeCall(ctx, newIndex, call, nil, opt)
|
||||
} else {
|
||||
v, err = e.executeCall(ctx, index, call, shards, opt)
|
||||
|
|
|
|||
|
|
@ -5082,3 +5082,32 @@ func TestExecutor_Execute_CountDistinct(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Ensure that a top-level, bare distinct on multiple nodes
|
||||
// is handled correctly.
|
||||
func TestExecutor_BareDistinct(t *testing.T) {
|
||||
t.Helper()
|
||||
c := test.MustRunCluster(t, 2)
|
||||
defer c.Close()
|
||||
|
||||
c.CreateField(t, "i", pilosa.IndexOptions{}, "ints",
|
||||
pilosa.OptFieldTypeInt(0, math.MaxInt64),
|
||||
)
|
||||
|
||||
// Populate integer data.
|
||||
c.Query(t, "i", fmt.Sprintf(`
|
||||
Set(0, ints=1)
|
||||
Set(%d, ints=2)
|
||||
`, ShardWidth))
|
||||
|
||||
for _, pql := range []string{
|
||||
`Distinct(field="ints")`,
|
||||
`Distinct(index="i", field="ints")`,
|
||||
} {
|
||||
exp := []uint64{1, 2}
|
||||
res := c.Query(t, "i", pql).Results[0].(pilosa.SignedRow)
|
||||
if got := res.Pos.Columns(); !reflect.DeepEqual(exp, got) {
|
||||
t.Fatalf("expected: %v, but got: %v", exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue