From 4f032289681be86051a83e1655674e2115cbd88f Mon Sep 17 00:00:00 2001 From: reesporte Date: Mon, 6 Dec 2021 11:57:17 -0600 Subject: [PATCH] fix count on distinctTimestamp adds the ability to get the count of a distinct call to a timestamp field --- executor.go | 2 ++ executor_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/executor.go b/executor.go index 20af2da4a..0ea3a8f8e 100644 --- a/executor.go +++ b/executor.go @@ -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()) } diff --git a/executor_test.go b/executor_test.go index ed4ffa735..68d490465 100644 --- a/executor_test.go +++ b/executor_test.go @@ -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) {