fix count on distinctTimestamp

adds the ability to get the count of a distinct call to a timestamp field
This commit is contained in:
reesporte 2021-12-06 11:57:17 -06:00
parent a8b1b93fa7
commit 4f03228968
2 changed files with 25 additions and 0 deletions

View file

@ -5027,6 +5027,8 @@ func (e *executor) executeCount(ctx context.Context, qcx *Qcx, index string, c *
return row.Count(), nil
case SignedRow:
return row.Pos.Count() + row.Neg.Count(), nil
case DistinctTimestamp:
return uint64(len(row.Values)), nil
default:
return 0, errors.Errorf("cannot count result of type %T from call %q", row, child.String())
}

View file

@ -6756,6 +6756,29 @@ func TestExecutor_Execute_CountDistinct(t *testing.T) {
})
}
func TestExecutor_Execute_CountDistinctTimestamp(t *testing.T) {
index := "test_index"
field := "ts"
c := test.MustRunCluster(t, 1)
defer c.Close()
// create an index and timestamp field
c.CreateField(t, index, pilosa.IndexOptions{}, field, pilosa.OptFieldTypeTimestamp(time.Unix(0, 0), "s"))
// add some data
data := []string{"2010-01-02T12:32:00Z", "2010-04-20T12:32:00Z", "2011-04-20T12:32:00Z"}
for i, datum := range data {
c.Query(t, index, fmt.Sprintf("Set(%d, ts=\"%s\")", i+10, datum))
}
// query the Count of Distinct vals in field ts
count := c.Query(t, index, "Count(Distinct(field=ts))").Results[0]
if count != len(data) {
t.Fatalf("expected %v got %v", len(data), count)
}
}
// Ensure that a top-level, bare distinct on multiple nodes
// is handled correctly.
func TestExecutor_BareDistinct(t *testing.T) {