English | 简体中文

api-docs / org.ktorm.entity / EntityGrouping

EntityGrouping

class EntityGrouping<E : Any, T : BaseTable<E>, K : Any> (source code)

Wraps an EntitySequence with a keySelector function, which can be applied to each record to get its key,
or used as the group by clause of the generated SQL.

An EntityGrouping structure serves as an intermediate step in group-and-fold operations: they group elements
by their keys and then fold each group with some aggregation operation.

Entity groups are created by attaching keySelector: (T) -> ColumnDeclaring<K> function to an entity sequence.
To get an instance of EntityGrouping, use the extension function EntitySequence.groupingBy.

For the list of group-and-fold operations available, see the extension functions below.

Constructors

NameSummary

<init>

EntityGrouping(
    sequence: EntitySequence<E, T>,
    keySelector: (T) -> ColumnDeclaring<K>)

Wraps an EntitySequence with a keySelector function, which can be applied to each record to get its key,
or used as the group by clause of the generated SQL.

Properties

NameSummary

keySelector

val keySelector: (T) -> ColumnDeclaring<K>

a function used to extract the key of a record in the source table.

sequence

val sequence: EntitySequence<E, T>

the source entity sequence of this grouping.

Functions

NameSummary

asKotlinGrouping

fun asKotlinGrouping(): Grouping<E, K?>

Create a kotlin.collections.Grouping instance that wraps this original entity grouping returning all the
elements in the source sequence when being iterated.

Extension Functions

NameSummary

aggregate

fun <E : Any, K : Any, R> EntityGrouping<E, *, K>.aggregate(
    operation: (key: K?, accumulator: R?, element: E, first: Boolean) -> R
): Map<K?, R>

Groups elements from the source sequence by key and applies operation to the elements of each group sequentially,
passing the previously accumulated value and the current element as arguments, and stores the results in a new map.

aggregateColumns

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

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.

aggregateColumnsTo

fun <E : Any, T : BaseTable<E>, K : Any, C : Any, M : MutableMap<in K?, in C?>> EntityGrouping<E, T, K>.aggregateColumnsTo(
    destination: M,
    aggregationSelector: (T) -> ColumnDeclaring<C>
): M

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

aggregateTo

fun <E : Any, K : Any, R, M : MutableMap<in K?, R>> EntityGrouping<E, *, K>.aggregateTo(
    destination: M,
    operation: (key: K?, accumulator: R?, element: E, first: Boolean) -> R
): M

Groups elements from the source sequence by key and applies operation to the elements of each group sequentially,
passing the previously accumulated value and the current element as arguments, and stores the results in the given
destination map.

eachAverageBy

fun <E : Any, T : BaseTable<E>, K : Any> EntityGrouping<E, T, K>.eachAverageBy(
    columnSelector: (T) -> ColumnDeclaring<out Number>
): Map<K?, Double?>

Group elements from the source sequence by key and average the columns or expressions provided by the
columnSelector function for elements in each group.

eachAverageByTo

fun <E : Any, T : BaseTable<E>, K : Any, M : MutableMap<in K?, in Double?>> EntityGrouping<E, T, K>.eachAverageByTo(
    destination: M,
    columnSelector: (T) -> ColumnDeclaring<out Number>
): M

Group elements from the source sequence by key and average the columns or expressions provided by the
columnSelector function for elements in each group, then store the results in the destination map.

eachCount

fun <E : Any, T : BaseTable<E>, K : Any> EntityGrouping<E, T, K>.eachCount(): Map<K?, Int>

Group elements from the source sequence by key and count elements in each group.

eachCountTo

fun <E : Any, T : BaseTable<E>, K : Any, M : MutableMap<in K?, Int>> EntityGrouping<E, T, K>.eachCountTo(
    destination: M
): M

Group elements from the source sequence by key and count elements in each group,
then store the results in the destination map.

eachMaxBy

fun <E : Any, T : BaseTable<E>, K : Any, C : Comparable<C>> EntityGrouping<E, T, K>.eachMaxBy(
    columnSelector: (T) -> ColumnDeclaring<C>
): Map<K?, C?>

Group elements from the source sequence by key and get the max value of the columns or expressions provided by the
columnSelector function for elements in each group.

eachMaxByTo

fun <E : Any, T : BaseTable<E>, K : Any, C : Comparable<C>, M : MutableMap<in K?, in C?>> EntityGrouping<E, T, K>.eachMaxByTo(
    destination: M,
    columnSelector: (T) -> ColumnDeclaring<C>
): M

Group elements from the source sequence by key and get the max value of the columns or expressions provided by the
columnSelector function for elements in each group, then store the results in the destination map.

eachMinBy

fun <E : Any, T : BaseTable<E>, K : Any, C : Comparable<C>> EntityGrouping<E, T, K>.eachMinBy(
    columnSelector: (T) -> ColumnDeclaring<C>
): Map<K?, C?>

Group elements from the source sequence by key and get the min value of the columns or expressions provided by the
columnSelector function for elements in each group.

eachMinByTo

fun <E : Any, T : BaseTable<E>, K : Any, C : Comparable<C>, M : MutableMap<in K?, in C?>> EntityGrouping<E, T, K>.eachMinByTo(
    destination: M,
    columnSelector: (T) -> ColumnDeclaring<C>
): M

Group elements from the source sequence by key and get the min value of the columns or expressions provided by the
columnSelector function for elements in each group, then store the results in the destination map.

eachSumBy

fun <E : Any, T : BaseTable<E>, K : Any, C : Number> EntityGrouping<E, T, K>.eachSumBy(
    columnSelector: (T) -> ColumnDeclaring<C>
): Map<K?, C?>

Group elements from the source sequence by key and sum the columns or expressions provided by the columnSelector
function for elements in each group.

eachSumByTo

fun <E : Any, T : BaseTable<E>, K : Any, C : Number, M : MutableMap<in K?, in C?>> EntityGrouping<E, T, K>.eachSumByTo(
    destination: M,
    columnSelector: (T) -> ColumnDeclaring<C>
): M

Group elements from the source sequence by key and sum the columns or expressions provided by the columnSelector
function for elements in each group, then store the results in the destination map.

eq

infix fun <T : Any> T.eq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

Equal operator, translated to = in SQL.

fold

fun <E : Any, K : Any, R> EntityGrouping<E, *, K>.fold(
    initialValueSelector: (key: K?, element: E) -> R,
    operation: (key: K?, accumulator: R, element: E) -> R
): Map<K?, R>

Groups elements from the source sequence by key and applies operation to the elements of each group sequentially,
passing the previously accumulated value and the current element as arguments, and stores the results in a new map.
An initial value of accumulator is provided by initialValueSelector function.

fun <E : Any, K : Any, R> EntityGrouping<E, *, K>.fold(
    initialValue: R,
    operation: (accumulator: R, element: E) -> R
): Map<K?, R>

Groups elements from the source sequence by key and applies operation to the elements of each group sequentially,
passing the previously accumulated value and the current element as arguments, and stores the results in a new map.
An initial value of accumulator is the same initialValue for each group.

foldTo

fun <E : Any, K : Any, R, M : MutableMap<in K?, R>> EntityGrouping<E, *, K>.foldTo(
    destination: M,
    initialValueSelector: (key: K?, element: E) -> R,
    operation: (key: K?, accumulator: R, element: E) -> R
): M

Groups elements from the source sequence by key and applies operation to the elements of each group sequentially,
passing the previously accumulated value and the current element as arguments, and stores the results in the given
destination map. An initial value of accumulator is provided by initialValueSelector function.

fun <E : Any, K : Any, R, M : MutableMap<in K?, R>> EntityGrouping<E, *, K>.foldTo(
    destination: M,
    initialValue: R,
    operation: (accumulator: R, element: E) -> R
): M

Groups elements from the source sequence by key and applies operation to the elements of each group sequentially,
passing the previously accumulated value and the current element as arguments, and stores the results in the given
destination map. An initial value of accumulator is the same initialValue for each group.

neq

infix fun <T : Any> T.neq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

Not-equal operator, translated to <> in SQL.

notEq

infix fun <T : Any> T.notEq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

Not-equal operator, translated to <> in SQL.

reduce

fun <E : Any, K : Any> EntityGrouping<E, *, K>.reduce(
    operation: (key: K?, accumulator: E, element: E) -> E
): Map<K?, E>

Groups elements from the source sequence by key and applies the reducing operation to the elements of each group
sequentially starting from the second element of the group, passing the previously accumulated value and the current
element as arguments, and stores the results in a new map. An initial value of accumulator is the first element of
the group.

reduceTo

fun <E : Any, K : Any, M : MutableMap<in K?, E>> EntityGrouping<E, *, K>.reduceTo(
    destination: M,
    operation: (key: K?, accumulator: E, element: E) -> E
): M

Groups elements from the source sequence by key and applies the reducing operation to the elements of each group
sequentially starting from the second element of the group, passing the previously accumulated value and the current
element as arguments, and stores the results in the given destination map. An initial value of accumulator is the
first element of the group.