mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 05:43:36 -05:00
sum/min/max/avg over a numeric field: bleve folds the accumulators from doc values, OpenSearch reads them from a stats aggregation, the service layer reduces them to the value of the kind after the cross-space merge. The proto gains MetricDefinition, MetricKind and Metric, which travels as accumulators (sum, count, min, max) so the merge works whatever the kind; value is set after the merge and absent for a metric without a single value. A metric is only valid on a numeric field, and only one of bucketDefinition and metricDefinition at a time. AGG-06, 18 and 21 in the parity suite.
31 lines
917 B
Go
31 lines
917 B
Go
package aggregation_test
|
|
|
|
import (
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
|
|
searchsvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/search/v0"
|
|
"github.com/opencloud-eu/opencloud/services/search/pkg/aggregation"
|
|
)
|
|
|
|
var _ = Describe("Observe", func() {
|
|
It("keeps every accumulator, whatever the kind", func() {
|
|
m := &searchsvc.Metric{Kind: searchsvc.MetricKind_METRIC_KIND_MAX}
|
|
for _, v := range []float64{1982, 1971, 2001} {
|
|
aggregation.Observe(m, v)
|
|
}
|
|
Expect(m.GetCount()).To(Equal(int64(3)))
|
|
Expect(m.GetSum()).To(Equal(5954.0))
|
|
Expect(m.GetMin()).To(Equal(1971.0))
|
|
Expect(m.GetMax()).To(Equal(2001.0))
|
|
Expect(m.Value).To(BeNil())
|
|
})
|
|
|
|
It("takes the first value as minimum and maximum, a negative one too", func() {
|
|
m := &searchsvc.Metric{}
|
|
aggregation.Observe(m, -3)
|
|
Expect(m.GetMin()).To(Equal(-3.0))
|
|
Expect(m.GetMax()).To(Equal(-3.0))
|
|
})
|
|
})
|