Skip to main content

Aggregation

The

Aggregation module facilitates creation of statically typed functional data Expression's, as well as providing a set of standard libraries for common Expression patterns.

Aggregation

AggregationDefinition

Ƭ AggregationDefinition<T>:

CustomAggregationDefinition<T> | StandardAggregationDefinition<T>

A

AggregationDefinition is either a CustomAggregationDefinition or StandardAggregationDefinition.

Type parameters

NameType
Textends EastType = EastType

CustomAggregationDefinition

Ƭ CustomAggregationDefinition<T, U>: Object

An

CustomAggregationDefinition represents a reduction over rows followed by an optional final transformation.

Type parameters

NameType
Textends EastType = EastType
Uextends EastType = EastType

Type declaration

NameType
aggregation_type"Custom"
finalizerEastFunction<T>
initialEastFunction<U>
inverse_reducerEastFunction<U>
previousVariable<U>
reducerEastFunction<U>
typeT

StandardAggregationDefinition

Ƭ StandardAggregationDefinition<T, U>: Object

A

StandardAggregationDefinition calculates one of a handful of built-in reductions over rows.

Type parameters

NameType
Textends EastType = EastType
Uextends StandardAggregationType = StandardAggregationType

Type declaration

NameType
aggregation_typeU
key?EastFunction
typeT
valueEastFunction

Any

Any(value):

StandardAggregationDefinition<BooleanType>

Create an

AggregationDefinition that returns true if one or more value is true.

Parameters

NameTypeDescription
valueEastFunction<BooleanType>the value to aggregate

Returns

StandardAggregationDefinition<BooleanType>

the

Any StandardAggregationDefinition

Example

 // ...
aggregations: {
// return true if a category value is null
CategoryMissing: fields => Any(IsNull(fields.Category)),
// ...
}

CollectDict

CollectDict<K, T>(key, value):

StandardAggregationDefinition<DictType<K, T>>

Create an

AggregationDefinition to create a dictionary of distinct key-value pairs. If multiple distinct, non-null values exist for a given key, then the value is null for that key.

Type parameters

NameType
Kextends StringType
Textends EastType

Parameters

NameTypeDescription
keyEastFunction<K>the dict key value
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<DictType<K, T>>

the

CollectDict StandardAggregationDefinition

Example

 // ...
aggregations: {
// collect all non-null HourlyRate's into a dictionary by EmployeeId
HourlyRatePerEmployee: fields => CollectDict(
fields.EmployeeId,
fields.HourlyRate
),
// ...
}

CollectDictCount

CollectDictCount(value):

StandardAggregationDefinition<DictType<StringType, IntegerType>>

Create an

AggregationDefinition to create a dictionary of the count of non-null keys

Parameters

NameTypeDescription
valueEastFunction<StringType>the dict key value

Returns

StandardAggregationDefinition<DictType<StringType, IntegerType>>

the

CollectDictCount StandardAggregationDefinition

Example

 // ...
aggregations: {
// create a dictionary with the count of products by Category
ProductsPerCategory: fields => CollectDictCount(
fields.Category,
),
// ...
}

CollectDictMax

CollectDictMax<T>(key, value):

StandardAggregationDefinition<DictType<StringType, T>>

Create an

AggregationDefinition to create a dictionary of the maximum of non-null values for key-value pairs.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
keyEastFunction<StringType>the dict key value
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<DictType<StringType, T>>

the

CollectDictMean StandardAggregationDefinition

Example

 // ...
aggregations: {
// create a dictionary with the min of Price per Category
MaxPricePerCategory: fields => CollectDictMax(
fields.Category,
fields.Price
),
// ...
}

CollectDictMean

CollectDictMean(key, value):

StandardAggregationDefinition<DictType<StringType, FloatType>>

Create an

AggregationDefinition to create a dictionary of the sum of non-null values for key-value pairs.

Parameters

NameTypeDescription
keyEastFunction<StringType>the dict key value
valueEastFunction<IntegerType | FloatType>the value to aggregate

Returns

StandardAggregationDefinition<DictType<StringType, FloatType>>

the

CollectDictMean StandardAggregationDefinition

Example

 // ...
aggregations: {
// create a dictionary with the average of Price per Category
MeanPricePerCategory: fields => CollectDictMean(
fields.Category,
fields.Price
),
// ...
}

CollectDictMin

CollectDictMin<T>(key, value):

StandardAggregationDefinition<DictType<StringType, T>>

Create an

AggregationDefinition to create a dictionary of the minimum of non-null values for key-value pairs.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
keyEastFunction<StringType>the dict key value
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<DictType<StringType, T>>

the

CollectDictMean StandardAggregationDefinition

Example

 // ...
aggregations: {
// create a dictionary with the min of Price per Category
MinPricePerCategory: fields => CollectDictMin(
fields.Category,
fields.Price
),
// ...
}

CollectDictSum

CollectDictSum<T>(key, value): T extends

NullType ? StandardAggregationDefinition<DictType<StringType, NonNullable<T>>> : StandardAggregationDefinition<DictType<StringType, T>>

Create an

AggregationDefinition to create a dictionary of the sum of non-null values for key-value pairs.

Type parameters

NameType
Textends IntegerType | FloatType

Parameters

NameTypeDescription
keyEastFunction<StringType>the dict key value
valueEastFunction<T>the value to aggregate

Returns

T extends

NullType ? StandardAggregationDefinition<DictType<StringType, NonNullable<T>>> : StandardAggregationDefinition<DictType<StringType, T>>

the

CollectDictSum StandardAggregationDefinition

Example

 // ...
aggregations: {
// create a dictionary with the sum of Qty's by Category
QtyPerCategory: fields => CollectDictSum(
fields.Category,
fields.Qty
),
// ...
}

CollectSet

CollectSet<K>(value):

StandardAggregationDefinition<SetType<K>>

Create an

AggregationDefinition to find the set of the non-null string values of value (which defaults to field).

Type parameters

NameType
Kextends StringType

Parameters

NameTypeDescription
valueEastFunction<K>the value to aggregate

Returns

StandardAggregationDefinition<SetType<K>>

the

CollectSet StandardAggregationDefinition

Example

 // ...
aggregations: {
// collect all non-null Categorie's into a set
Categories: fields => CollectSet(fields.Category),
// ...
}

Count

Count(value?):

StandardAggregationDefinition<IntegerType>

Create an Aggregation to count the number of rows where value is not null.

Parameters

NameTypeDescription
value?EastFunctionthe value to aggregate

Returns

StandardAggregationDefinition<IntegerType>

the

Count StandardAggregationDefinition

Example

 // ...
aggregations: {
// count the number of Category's that aren't null
ValidCategories: fields => Count(fields.Category),
// ...
}

DistinctCount

DistinctCount(value):

StandardAggregationDefinition<IntegerType>

Create an Aggregation to count the number of distinct, non-null values of value.

Parameters

NameTypeDescription
valueEastFunctionthe value to aggregate

Returns

StandardAggregationDefinition<IntegerType>

the

DistinctCount StandardAggregationDefinition

Example

 // ...
aggregations: {
// count the number of distinct non-null Category's
Categories: fields => DistinctCount(fields.Category),
// ...
}

Every

Every(value):

StandardAggregationDefinition<BooleanType>

Create an

AggregationDefinition that returns true if all values are true

Parameters

NameTypeDescription
valueEastFunction<BooleanType>the value to aggregate

Returns

StandardAggregationDefinition<BooleanType>

the

Every StandardAggregationDefinition

Example

 // ...
aggregations: {
// return true if all category values are null
AllCategoriesMissing: fields => Every(
IsNull(fields.Category)
),
// ...
}

FindMaximum

FindMaximum<K, T>(value, key): K extends

NullType ? T extends NullType ? StandardAggregationDefinition<T> : StandardAggregationDefinition<Nullable<T>> : StandardAggregationDefinition<T>

Create an

AggregationDefinition to find the value of key, in the key-value pair that has the largest, non-null value of value (which defaults to field).

Type parameters

NameType
Kextends EastType
Textends EastType

Parameters

NameTypeDescription
valueEastFunction<K>the value to aggregate
keyEastFunction<T>the value to find the minimum of

Returns

K extends

NullType ? T extends NullType ? StandardAggregationDefinition<T> : StandardAggregationDefinition<Nullable<T>> : StandardAggregationDefinition<T>

the

FindMaximum StandardAggregationDefinition

Example

 // ...
aggregations: {
// return Product with the lowest Price
HighestPriceProduct: fields => FindMaximum(
fields.Price,
fields.Product
),
// ...
}

FindMinimum

FindMinimum<K, T>(value, key): K extends

NullType ? T extends NullType ? StandardAggregationDefinition<T> : StandardAggregationDefinition<Nullable<T>> : StandardAggregationDefinition<T>

Create an

AggregationDefinition to find the value of key, in the key-value pair that has the smallest, non-null value of value (which defaults to field).

Type parameters

NameType
Kextends EastType
Textends EastType

Parameters

NameTypeDescription
valueEastFunction<K>the value to aggregate
keyEastFunction<T>the value to find the minimum of

Returns

K extends

NullType ? T extends NullType ? StandardAggregationDefinition<T> : StandardAggregationDefinition<Nullable<T>> : StandardAggregationDefinition<T>

the

FindMinimum StandardAggregationDefinition

Example

 // ...
aggregations: {
// return Product with the lowest Price
LowestPriceProduct: fields => FindMinimum(
fields.Price,
fields.Product
),
// ...
}

Maximum

Maximum<T>(value):

StandardAggregationDefinition<T>

Create an

AggregationDefinition to find the largest, non-null value of value (which defaults to field).

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<T>

the

Maximum StandardAggregationDefinition

Example

 // ...
aggregations: {
// return the highest Price
MaxPrice: fields => Maximum(fields.Price),
// ...
}

Mean

Mean(value):

StandardAggregationDefinition<FloatType>

Create an

AggregationDefinition to find the mean of the non-null values of value (which defaults to field).

Parameters

NameTypeDescription
valueEastFunction<IntegerType | FloatType>the value to aggregate

Returns

StandardAggregationDefinition<FloatType>

the

Mean StandardAggregationDefinition

Example

 // ...
aggregations: {
// find the mean Qty's
MeanQty: fields => Mean(fields.Qty),
// ...
}

Median

Median<T>(value):

StandardAggregationDefinition<T>

Create an

AggregationDefinition to find the median of the non-null values of value (which defaults to field). In case of a tie, the greater number is returned.

Type parameters

NameType
Textends IntegerType | FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<T>

the

Median StandardAggregationDefinition

Example

 // ...
aggregations: {
// return the middle Price
MedianPrice: fields => Median(fields.Price),
// ...
}

Minimum

Minimum<T>(value):

StandardAggregationDefinition<T>

Create an

AggregationDefinition to find the smallest, non-null value of value (which defaults to field).

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<T>

the

Minimum StandardAggregationDefinition

Example

 // ...
aggregations: {
// return the lowest Price
MinPrice: fields => Minimum(fields.Price),
// ...
}

Mode

Mode<T>(value):

StandardAggregationDefinition<T>

Create an

AggregationDefinition to find the most common, non-null value of value (which defaults to field). If a tie is encountered, any one of the most-common values is chosen.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<T>

the

Mode StandardAggregationDefinition

Example

 // ...
aggregations: {
// return the mode of prices
ModalPrice: fields => Mode(fields.Price),
// ...
}

Span

Span<T>(value):

StandardAggregationDefinition<T>

Create an

AggregationDefinition to find the span of the non-null values of value (which defaults to field), meaning the difference between the largest and smallest values.

Type parameters

NameType
Textends IntegerType | FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the value to aggregate

Returns

StandardAggregationDefinition<T>

the

Span StandardAggregationDefinition

Example

 // ...
aggregations: {
// return the Price span
PriceSpan: fields => Span(fields.Price),
// ...
}

SparseDictCovariance

SparseDictCovariance(value_expr):

AggregationDefinition<DictType<StringType, DictType<StringType, FloatType>>>

Create an

AggregationDefinition to calculate the covariance of the values of a "sparse" dictionary where missing elements are presumed to have value of zero.

Parameters

NameTypeDescription
value_exprExpression<DictType<StringType, FloatType>>the value to aggregate

Returns

AggregationDefinition<DictType<StringType, DictType<StringType, FloatType>>>

the

SparseDictMean CustomAggregationDefinition

Example

 // ...
aggregations: {
// return the ...
PriceCardCoVariance: fields => SparseDictCovariance(fields.PriceCard, DictType(StringType,FloatType))),
// ...
}

SparseDictMean

SparseDictMean(value_expr):

AggregationDefinition<DictType<StringType, FloatType>>

Create an

AggregationDefinition to calculate the average values of a "sparse" dictionary where missing elements are presumed to have value of zero.

Parameters

NameTypeDescription
value_exprExpression<DictType<StringType, IntegerType>>the value to aggregate

Returns

AggregationDefinition<DictType<StringType, FloatType>>

the

SparseDictMean CustomAggregationDefinition

Example

 // ...
aggregations: {
// return the ...
PriceCardAvg: fields => SparseDictMean(fields.PriceCard, DictType(StringType,FloatType))),
// ...
}

SparseDictSum

SparseDictSum(value_expr):

AggregationDefinition<DictType<StringType, FloatType>>

Create an

AggregationDefinition to calculate the sum of the values of a "sparse" dictionary where missing elements are presumed to have value of zero.

Parameters

NameTypeDescription
value_exprExpression<DictType<StringType, FloatType>>the value to aggregate

Returns

AggregationDefinition<DictType<StringType, FloatType>>

the

SparseDictSum CustomAggregationDefinition

Example

 // ...
aggregations: {
// return the ...
PriceCardTotal: fields => SparseDictSum(fields.PriceCard, DictType(StringType,FloatType))),
// ...
}

SparseDictVariance

SparseDictVariance(value_expr):

AggregationDefinition<DictType<StringType, FloatType>>

Create an

AggregationDefinition to calculate the variance of the values of a "sparse" dictionary where missing elements are presumed to have value of zero.

Parameters

NameTypeDescription
value_exprExpression<DictType<StringType, FloatType>>the value to aggregate

Returns

AggregationDefinition<DictType<StringType, FloatType>>

the

SparseDictMean CustomAggregationDefinition

Example

 // ...
aggregations: {
// return the ...
PriceCardVariance: fields => SparseDictVariance(fields.PriceCard, DictType(StringType,FloatType))),
// ...
}

StdDev

StdDev(value):

StandardAggregationDefinition<FloatType>

Create an

AggregationDefinition to find the standard deviation of the non-null values of value (which defaults to field).

Parameters

NameTypeDescription
valueEastFunction<IntegerType | FloatType>the value to aggregate

Returns

StandardAggregationDefinition<FloatType>

the

StdDev StandardAggregationDefinition

Example

 // ...
aggregations: {
// find the std deviation of Qty's
StdDevQty: fields => StdDev(fields.Qty),
// ...
}

Sum

Sum(value):

StandardAggregationDefinition<IntegerType>

Create an

AggregationDefinition to find the sum of the non-null values of value (which defaults to field).

Parameters

NameTypeDescription
valueEastFunction<IntegerType>the value to aggregate

Returns

StandardAggregationDefinition<IntegerType>

the

Sum StandardAggregationDefinition

Example

 // ...
aggregations: {
// sum all Qty's to find the total
TotalQty: fields => Sum(fields.Qty),
// ...
}

Unique

Unique<T>(value): T extends

NullType ? StandardAggregationDefinition<T> : StandardAggregationDefinition<Nullable<T>>

Create an Aggregation to find the unique non-null value of value. If multiple non-null values are encountered, it returns null.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
valueEastFunction<T>the value to aggregate

Returns

T extends

NullType ? StandardAggregationDefinition<T> : StandardAggregationDefinition<Nullable<T>>

the

Unique StandardAggregationDefinition

Example

 // ...
aggregations: {
// count the number of unique non-null Category's
Categories: fields => Unique(fields.Category),
// ...
}