Documentation
¶
Overview ¶
Package aggregation implements aggregation functions to statistic a range of values.
Index ¶
- func FromFieldValue[N Number](fieldValue *modelv1.FieldValue) (N, error)
- func PartialToFieldValues[N Number](af modelv1.AggregationFunction, p Partial[N]) ([]*modelv1.FieldValue, error)
- func ToFieldValue[N Number](value N) (*modelv1.FieldValue, error)
- type Distinct
- type Map
- type Number
- type Partial
- type RangeFolder
- type Reduce
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromFieldValue ¶ added in v0.3.0
func FromFieldValue[N Number](fieldValue *modelv1.FieldValue) (N, error)
FromFieldValue transforms modelv1.FieldValue to Number.
func PartialToFieldValues ¶ added in v0.10.0
func PartialToFieldValues[N Number](af modelv1.AggregationFunction, p Partial[N]) ([]*modelv1.FieldValue, error)
PartialToFieldValues converts a Partial to field values for wire transport. For MEAN it returns two values (Value/sum first, Count second); for others one value.
func ToFieldValue ¶ added in v0.3.0
func ToFieldValue[N Number](value N) (*modelv1.FieldValue, error)
ToFieldValue transforms Number to modelv1.FieldValue.
Types ¶
type Distinct ¶ added in v0.12.0
type Distinct interface {
// Contains reports whether key has already been recorded, without
// mutating the set. A caller that must reserve memory before growing
// the set (pkg/query/vectorized/measure's foldDistinct) checks this
// first and only calls In — which does mutate — once the reservation
// for a genuinely new key has succeeded. Checking via In itself would
// insert the key before the reservation is known to succeed, leaving a
// rejected value resident (and uncharged) in the set.
Contains(key []byte) bool
// In records key as seen. It returns true the first time a given key
// is seen, false for a repeat — the caller uses this to charge memory
// only for values that actually grow the set.
In(key []byte) (added bool)
// Val returns the number of distinct keys seen so far.
Val() int64
// Reset clears the set, discarding all keys seen so far.
Reset()
}
Distinct accumulates the distinct values of one group for COUNT_DISTINCT (design doc §7.3). Unlike Map/Reduce, it is not Number-parameterized — the target may be a string, bytes, or tag/field value, not just int64 or float64 — so callers encode a value to its byte key themselves (see pkg/query/vectorized/measure/groupby.go's appendKeyComponent, the same encoder BatchAggregation's group key already uses) and pass the encoded bytes here.
func NewDistinct ¶ added in v0.12.0
func NewDistinct() Distinct
NewDistinct returns a Distinct that tracks exact distinct byte keys in memory. There is no function-dispatch parameter — unlike NewMap/NewReduce, COUNT_DISTINCT has exactly one behavior regardless of the target's type.
type Map ¶ added in v0.10.0
Map accumulates raw values and produces aggregation results. It serves as the local accumulator for raw data points.
type Partial ¶ added in v0.10.0
type Partial[N Number] struct { Value N Count N }
Partial represents the intermediate result of a Map phase. For most functions only Value is meaningful; for MEAN both Value (sum) and Count are used.
func FieldValuesToPartial ¶ added in v0.10.0
func FieldValuesToPartial[N Number](af modelv1.AggregationFunction, fvs []*modelv1.FieldValue) (Partial[N], error)
FieldValuesToPartial converts field values from wire transport to a Partial. For MEAN expects two values (sum, count); for others one value (Count will be zero).
type RangeFolder ¶ added in v0.12.0
type RangeFolder[N Number] interface { // InSlice folds vals in order. InSlice(vals []N) // InSelected folds vals[sel[0]], vals[sel[1]], ... in that order. InSelected(vals []N, sel []uint16) }
RangeFolder is implemented by the Maps NewMap returns. It folds a run of values in one call. The result is exactly that of calling In once per value in the same order, so a float accumulator is bit-identical: the values are added left to right, never regrouped. Callers use it for a run that holds no nulls.