Aggregator

This class is the main entry-point for creating an aggregator.

Aggregators are used to compute a single value from a Sequence of values, a single DataColumn, or multiple DataColumns.

Aggregator follows a dependency injection pattern:

Using the constructor or Aggregator.invoke function, you can create an Aggregator instance with a choice of:

  • AggregatorInputHandler - The input handler of the aggregator, which handles type checks, conversions, and preprocessing of a single sequence of input values. It can also calculate a specific value type from the input values or input types if the (specific) type is not known.

Options: NumberInputHandler, AnyInputHandler

  • AggregatorAggregationHandler - The base functionality of the aggregator, which defines how the aggregation of a single Sequence or column is done. It also provides information on which return type will be given, as KType, given a value type. It can also provide the index of the result in the input values if it is a selecting aggregator.

Options: ReducingAggregationHandler, SelectingAggregationHandler

Options: FlatteningMultipleColumnsHandler, TwoStepMultipleColumnsHandler, NoMultipleColumnsHandler

Type Parameters

Value

The non-null type of the values to be aggregated. The input can always have nulls, they are filtered out.

Return

The type of the resulting value. Can optionally be nullable.

See also

Constructors

Link copied to clipboard
constructor(aggregationHandler: AggregatorAggregationHandler<Value, Return>, inputHandler: AggregatorInputHandler<Value, Return>, multipleColumnsHandler: AggregatorMultipleColumnsHandler<Value, Return>, name: String, statisticsParameters: Map<String, Any>)

Types

Link copied to clipboard
internal object Companion

Properties

Link copied to clipboard
open override var aggregator: Aggregator<Value, Return>?

Reference to the aggregator instance.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val valueTypeIfEmpty: KType

The type of the value if the input is empty.

Functions

Link copied to clipboard

Aggregates the data in the given columns and computes a single resulting value.

Aggregates the data in the given column and computes a single resulting value.

internal fun <Value : Any, Return> Aggregator<Value, Return>.aggregate(values: Sequence<Value?>, valueType: KType): Return

Performs aggregation on the given values, taking valueType into account. If valueType is unknown, see calculateValueType or aggregateCalculatingValueType.

Link copied to clipboard
internal fun <T, C, R> Aggregator<*, R>.aggregateAll(data: DataFrame<T>, columns: ColumnsSelector<T, C>): R
internal fun <T, C, R> Aggregator<*, R>.aggregateAll(data: PivotGroupBy<T>, columns: ColumnsSelector<T, C>): DataFrame<T>
internal fun <T, C, R> Aggregator<*, R>.aggregateAll(data: Grouped<T>, name: String?, columns: ColumnsSelector<T, C>): DataFrame<T>
Link copied to clipboard
internal inline fun <T, reified V : R, R> Aggregator<V & Any, R>.aggregateBy(values: Iterable<T>, crossinline selector: (T) -> V): Result<T>

Selects the best matching value in the iterable using the provided Aggregator by the provided selector.

internal inline fun <T, reified V : R, R> Aggregator<V & Any, R>.aggregateBy(values: Sequence<T>, crossinline selector: (T) -> V): Result<T>

Selects the best matching value in the sequence using the provided Aggregator by the provided selector.

internal inline fun <T, reified V : R, R> Aggregator<V & Any, R>.aggregateBy(column: DataColumn<T>, crossinline selector: (T) -> V): Result<T>

Selects the best matching value in the column using the provided Aggregator by the provided selector.

Link copied to clipboard
internal inline fun <T, reified V : R, R> Aggregator<V & Any, R>.aggregateByOrNull(data: DataFrame<T>, crossinline rowExpression: RowExpression<T, V>): DataRow<T>?

Selects the best matching value in the dataframe using the provided Aggregator by the provided rowExpression.

internal inline fun <T, reified V : R, R> Aggregator<V & Any, R>.aggregateByOrNull(data: DataFrame<T>, column: ColumnReference<V>): DataRow<T>?

Selects the best matching value in the dataframe using the provided Aggregator by the provided column.

Link copied to clipboard
internal fun <Value : Any, Return> Aggregator<Value, Return>.aggregateCalculatingValueType(values: Sequence<Value?>, valueTypes: Set<KType>? = null): Return

If the specific ValueType of the input is not known, but you still want to call aggregate, this function can be called to calculate it by combining the set of known valueTypes or by gathering the types from values and then aggregating them.

Link copied to clipboard
internal fun <T, C, R> Aggregator<*, R>.aggregateFor(data: DataFrame<T>, columns: ColumnsForAggregateSelector<T, C?>): DataRow<T>
internal fun <T, C, R> Aggregator<*, R>.aggregateFor(data: Grouped<T>, columns: ColumnsForAggregateSelector<T, C?>): DataFrame<T>
internal fun <T, C, R> Aggregator<*, R>.aggregateFor(data: PivotGroupBy<T>, separate: Boolean, columns: ColumnsForAggregateSelector<T, C?>): DataFrame<T>
Link copied to clipboard
open override fun aggregateMultipleColumns(columns: Sequence<DataColumn<Value?>>): Return

Aggregates the data in the multiple given columns and computes a single resulting value. Calls Aggregator.aggregateSequence or Aggregator.aggregateSingleColumn.

Link copied to clipboard
internal inline fun <T, reified V, R> Aggregator<*, R>.aggregateOf(frame: DataFrame<T>, crossinline expression: RowExpression<T, V>): R

Aggregates frame by first applying expression to each row of the frame and then applying the Aggregator (this) to the resulting sequence.

internal inline fun <T, reified C, reified R> Aggregator<*, R>.aggregateOf(data: PivotGroupBy<T>, crossinline expression: RowExpression<T, C>): DataFrame<T>

internal inline fun <C, reified V, R> Aggregator<V & Any, R>.aggregateOf(values: Sequence<C>, crossinline transform: (C) -> V): R

Aggregates values by first applying transform to each element of the sequence and then applying the Aggregator (this) to the resulting sequence.

internal inline fun <C, reified V, R> Aggregator<V & Any, R>.aggregateOf(column: DataColumn<C>, crossinline transform: (C) -> V): R

Aggregates column by first applying transform to each element of the column and then applying the Aggregator (this) to the resulting sequence.

internal inline fun <T, reified C, reified R> Aggregator<*, R>.aggregateOf(data: Grouped<T>, resultName: String? = null, crossinline expression: RowExpression<T, C>): DataFrame<T>

Aggregates data by first applying expression to each row of the frame and then

Link copied to clipboard
internal fun <T, C, R> Aggregator<*, R>.aggregateOfDelegated(frame: Grouped<T>, name: String?, body: AggregateBody<T, C>): DataFrame<T>
Link copied to clipboard
internal fun <T, V, R> Aggregator<V & Any, R>.aggregateOfRow(row: DataRow<T>, columns: ColumnsSelector<T, V>): R

Generic function to apply an Aggregator (this) to aggregate values of a row.

Link copied to clipboard
open override fun aggregateSequence(values: Sequence<Value?>, valueType: ValueType): Return

Base function of Aggregator.

Link copied to clipboard
open override fun aggregateSingleColumn(column: DataColumn<Value?>): Return

Aggregates the data in the given column and computes a single resulting value. Calls aggregateSequence. It tries to exploit a cache for statistics which can be accessed by ValueColumnInternal

Link copied to clipboard
open override fun calculateReturnType(valueType: KType, emptyInput: Boolean): KType

Function that can give the return type of aggregateSequence as KType, given the type of the input. This allows aggregators to avoid runtime type calculations.

Link copied to clipboard
open override fun calculateReturnTypeMultipleColumns(colTypes: Set<KType>, colsEmpty: Boolean): KType

Function that can give the return type of aggregateMultipleColumns, given types of the columns. This allows aggregators to avoid runtime type calculations.

Link copied to clipboard
open override fun calculateValueType(valueTypes: Set<KType>): ValueType

If the specific ValueType of the input is not known, but you still want to call aggregate, this function can be called to calculate it by combining the set of known valueTypes.

open override fun calculateValueType(values: Sequence<Value?>): ValueType

WARNING: HEAVY!

Link copied to clipboard
internal fun <Value : Any, Return> Aggregator<Value, Return>.calculateValueType(values: Sequence<Value?>, valueTypes: Set<KType>? = null): ValueType

If the specific ValueType of the input is not known, but you still want to call aggregate, this function can be called to calculate it by combining the set of known valueTypes or by gathering the types from values.

Link copied to clipboard
internal fun <Type> Aggregator<*, *>.cast(): Aggregator<Type & Any, Type>
Link copied to clipboard
Link copied to clipboard

Gives the index of the aggregation result in the input values, if it applies. This is used for aggregators with an AggregatorAggregationHandler where Value== Return, and where the result exists in the input.

Link copied to clipboard
open override fun indexOfAggregationResultSingleSequence(values: Sequence<Value?>, valueType: ValueType): Int

Function that can give the index of the aggregation result in the input values, if it applies. This is used for AggregatorAggregationHandlers where Value== Return, and where the result exists in the input.

Link copied to clipboard
open override fun init(aggregator: Aggregator<Value, Return>)
Link copied to clipboard
open override fun preprocessAggregation(values: Sequence<Value?>, valueType: ValueType): Pair<Sequence<Value?>, KType>

Preprocesses the input values before aggregation. It's expected that this function converts values to the right valueType.kType if valueType.needsFullConversion.

Link copied to clipboard
open override fun toString(): String