This commit is contained in:
Kuba Podgórski 2020-04-01 15:19:05 +02:00 committed by GitHub
parent c6083d6816
commit b0f1ee3fce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View file

@ -1362,6 +1362,7 @@ func (e *executor) executeTopN(ctx context.Context, index string, c *pql.Call, s
}, nil
}
// Only the original caller should refetch the full counts.
// TODO(@kuba--): ...but do we really need `Clone` here?
other := c.Clone()
ids := Pairs(pairs.Pairs).Keys()

View file

@ -5111,3 +5111,53 @@ func TestExecutor_BareDistinct(t *testing.T) {
}
}
}
func TestExecutor_Execute_TopNDistinct(t *testing.T) {
data, err := ioutil.ReadFile("testdata/schema.json")
if err != nil {
t.Fatal(err)
}
c := test.MustRunCluster(t, 1)
defer c.Close()
api := c[0].API
schema := &pilosa.Schema{}
if err := json.NewDecoder(bytes.NewReader(data)).Decode(schema); err != nil {
t.Fatal(err)
}
if err := api.ApplySchema(context.TODO(), schema, false); err != nil {
t.Fatal(err)
}
writeQuery := `Set(100, type=AntidotePoint)Set(100, equip_id=100)Set(100, site_id=100)Set(100, id=100)`
for _, i := range schema.Indexes {
if _, err := api.Query(context.TODO(), &pilosa.QueryRequest{Index: i.Name, Query: writeQuery}); err != nil {
t.Fatal(err)
}
}
pql := `TopN(type, Distinct(Row(type=AntidotePoint), index=power_ts, field=equip_id))`
// Check if test query gives correct results (one column 100)
t.Run("TopN", func(t *testing.T) {
resp, err := api.Query(context.TODO(), &pilosa.QueryRequest{
Index: "equipment",
Query: pql,
})
if err != nil {
t.Fatal(err)
}
pf, ok := resp.Results[0].(*pilosa.PairsField)
if !ok {
t.Fatalf("invalid response type, expected: *pilosa.PairsField, got: %T", resp.Results[0])
}
if len(pf.Pairs) != 1 {
t.Fatalf("invalid Pairs length, expected: 1, got: %v", len(pf.Pairs))
}
if pf.Pairs[0].Count != 1 {
t.Fatalf("invalid Pairs count, expected: 1, got: %v", pf.Pairs[0].Count)
}
})
}

View file

@ -690,6 +690,11 @@ func (c *Call) Clone() *Call {
other.Children[i] = c.Children[i].Clone()
}
}
// @seebs "...it should be safe,
// because nothing should be writing to Precomputed
// once it's gotten created in the first place."
other.Precomputed = c.Precomputed
return other
}