English | 简体中文

api-docs / org.ktorm.entity / aggregateColumns

aggregateColumns

inline fun <E : Any, T : BaseTable<E>, K : Any, C : Any> EntityGrouping<E, T, K>.aggregateColumns(
    aggregationSelector: (T) -> ColumnDeclaring<C>
): Map<K?, C?>
(source code)

Group elements from the source sequence by key and perform the given aggregation for elements in each group,
then store the results in a new Map.

The key for each group is provided by the EntityGrouping.keySelector function, and the generated SQL is like:
select key, aggregation from source group by key.

Ktorm also supports aggregating two or more columns, we just need to wrap our aggregate expressions by tupleOf
in the closure, then the function’s return type becomes Map<K?, TupleN<C1?, C2?, .. Cn?>>.

Parameters

aggregationSelector - a function that accepts the source table and returns the aggregate expression.

Return
a Map associating the key of each group with the result of aggregation of the group elements.

inline fun <E : Any, T : BaseTable<E>, C : Any> EntitySequence<E, T>.aggregateColumns(
    aggregationSelector: (T) -> ColumnDeclaring<C>
): C?
(source code)

Perform an aggregation given by aggregationSelector for all elements in the sequence,
and return the aggregate result.

Ktorm also supports aggregating two or more columns, we just need to wrap our aggregate expressions by
tupleOf in the closure, then the function’s return type becomes TupleN<C1?, C2?, .. Cn?>.

The operation is terminal.

Parameters

aggregationSelector - a function that accepts the source table and returns the aggregate expression.

Return
the aggregate result.