aggregators

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: UPL-1.0 Imports: 4 Imported by: 0

Documentation

Overview

Package aggregators provides various aggregator functions and types.

Index

Constants

View Source
const (

	// Explain produces a QueryRecord object that contains an estimated cost  of the query execution.
	Explain = "EXPLAIN"

	// Trace produces a QueryRecord object that contains the actual cost of the query execution.
	Trace = "TRACE"

	// TimoutNone indicate that this task or request can run indefinitely.
	TimoutNone = -1

	// TimeoutDefault indicates that the corresponding service's default timeout value should be used.
	TimeoutDefault = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregationResult

type AggregationResult[K comparable, V any] struct {
	Entries []Entry[K, V] `json:"entries"`
}

AggregationResult wraps a result which returns a slice of entries. The type parameters are K = type of the key and V= type of the value.

type Aggregator

type Aggregator[R any] interface {
	// AndThen performs an additional aggregation step.
	AndThen(next Aggregator[R]) Aggregator[R]
}

Aggregator acts as a common interface for all Aggregators.

func Average

func Average[E processors.Number](extractor extractors.ValueExtractor[any, E]) Aggregator[big.Rat]

Average calculates an average for values of any numeric type extracted from a set of entries in a NamedMap or NamedCache. If the set of entries is empty, a nil value is returned. The type parameter is E = type of the value to average.

func Count

func Count() Aggregator[int64]

Count calculates the number of values in an entry set.

func Distinct

func Distinct[R any](extractor extractors.ValueExtractor[any, R]) Aggregator[[]R]

Distinct returns an aggregator to get the set of unique values extracted from a set of entries in a NamedMap or NamedCache. If the set of entries is empty, an empty array is returned. The type parameters is R = the type of the result. The type parameter is R = type of the distinct value.

func GroupBy

func GroupBy[G comparable, T any](extractor extractors.ValueExtractor[any, G], agg Aggregator[T]) Aggregator[AggregationResult[G, T]]

GroupBy provides an ability to split a subset of entries in a NamedMap or NamedCache into a collection of non-intersecting subsets and then aggregate them separately and independently. The splitting (grouping) is performed using the results of the underlying property in such a way that two entries will belong to the same group if and only if the result of the corresponding property call produces the same value or tuple (list of values).

After the entries are split into the groups, the underlying aggregator is applied separately to each group. The result of the aggregation by the GroupAggregator is a Map that has distinct values (or tuples) as keys and results of the individual aggregation as values. Additionally, those results could be further reduced using an optional. The type parameters are G = type to group by value, T = type of the aggregator result.

For example, the following example returns the maximum salary by department.

salaryResult, err = coherence.Aggregate(ctx, namedMap,
    aggregators.GroupBy(extractors.Extract[string]("department"), aggregators.Max(extractors.Extract[float32]("salary"))))

func Max

func Max[E processors.Number](extractor extractors.ValueExtractor[any, E]) Aggregator[E]

Max calculates a maximum of numeric values of any numeric type extracted from a set of entries in a NamedMap or NamedCache. If the set of entries is empty, a nil value is returned. The type parameter is E = type to extract.

func Min

func Min[E processors.Number](extractor extractors.ValueExtractor[any, E]) Aggregator[E]

Min calculates a minimum of numeric values of any numeric type extracted from a set of entries in a NamedMap or NamedCache. If the set of entries is empty, a nil value is returned. The type parameter is E = type to extract.

func Priority

func Priority[R any](executionTimeout, requestTimeout, schedulingPriority int64, aggregator Aggregator[R]) Aggregator[R]

Priority returns an aggregator to explicitly control the scheduling priority and timeouts for execution of Aggregators. You can use Timeout_None or TimeoutDefault for execution request timeout values. The type parameter is R = the type of the result.

func QueryRecorder

func QueryRecorder(explainType string) Aggregator[map[string]interface{}]

QueryRecorder returns and aggregator to return an estimated or actual cost of the query execution for a given filter. The result is a JSON struct map[string]interface{}.

func Reducer

Reducer returns an aggregator to return a portion of values from a NamedMap or NamedCache based on an extractor. If the set of entries is empty, an empty map is returned. The type parameters is K = the type of the key. The type parameter is K = type of the key.

func Sum

Sum calculates a sum of numeric values of any numeric type extracted from a set of entries in a NamedMap or NamedCache. If the set of entries is empty, a nil value is returned. The return type of the aggregator is a big.Rat and must be converted to the required type before use. The type parameter is E = type to extract.

func TopN

func TopN[E, R any](extractor extractors.ValueExtractor[any, E], ascending bool, results int) Aggregator[[]R]

The TopN aggregates the top N extracted values into an array. The extracted values must not be null, but do not need to be unique. The type parameters are E = the type of the extracted value and R = the type of the result.

type Entry

type Entry[K comparable, V any] struct {
	Type  string `json:"@type"`
	Key   K      `json:"key"`
	Value V      `json:"value"`
}

Entry wraps a Key and a Value. The type parameters are K = type of the key and V= type of the value.

type EnumType

type EnumType struct {
	Enum string `json:"enum"`
}

EnumType defines a type for a QueryRecorder. This is an internal class (exported only for serialization purpose).

type ReducerResult

type ReducerResult[K comparable] struct {
	Entries []Entry[K, []any] `json:"entries"`
}

ReducerResult wraps a result which returns a map of slice of entries. The type parameter is K = the type of the key.

Jump to

Keyboard shortcuts

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