aggregation

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package aggregation implements aggregation functions to statistic a range of values.

Index

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

type Map[N Number] interface {
	In(N)
	Val() N
	Partial() Partial[N]
	Reset()
}

Map accumulates raw values and produces aggregation results. It serves as the local accumulator for raw data points.

func NewMap added in v0.10.0

func NewMap[N Number](af modelv1.AggregationFunction) (Map[N], error)

NewMap returns a Map aggregation function for the given type.

type Number added in v0.3.0

type Number interface {
	~int64 | ~float64
}

Number denotes the supported number types.

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.

type Reduce added in v0.10.0

type Reduce[N Number] interface {
	Combine(Partial[N])
	Val() N
	Reset()
}

Reduce combines intermediate results from Map phases into a final value.

func NewReduce added in v0.10.0

func NewReduce[N Number](af modelv1.AggregationFunction) (Reduce[N], error)

NewReduce returns a Reduce aggregation function for the given type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL