Some reducers
This commit is contained in:
parent
d6ecd1fb4b
commit
31151a9a7f
@ -0,0 +1,20 @@
|
||||
package ru.landgrafhomyak.db.serdha0.user_commons.reducers
|
||||
|
||||
import ru.landgrafhomyak.db.serdha0.api.misc.Reducer
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.InputRow
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.OutputRow
|
||||
import ru.landgrafhomyak.db.serdha0.user_commons.types.U_INT_64
|
||||
|
||||
public class Count private constructor(context: Reducer.Constructor.Scope<Count>) : Reducer.Action<Count> {
|
||||
@Suppress("PropertyName", "MemberVisibilityCanBePrivate")
|
||||
public val C_Counter: Reducer.OutputColumn<ULong, U_INT_64, Count> = context.outputColumn("counter", context.types.U_INT_64, 0u)
|
||||
|
||||
override fun calculate(acc: OutputRow<Count>, row: OutputRow<Count>, newAcc: InputRow<Count>) {
|
||||
newAcc[this.C_Counter] = acc[this.C_Counter] + 1u
|
||||
}
|
||||
|
||||
public object Constructor : Reducer.Constructor<Count> {
|
||||
override fun createReducer(context: Reducer.Constructor.Scope<Count>): Reducer.Action<Count> =
|
||||
Count(context)
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package ru.landgrafhomyak.db.serdha0.user_commons.reducers
|
||||
|
||||
import ru.landgrafhomyak.db.serdha0.api.misc.DatabaseType
|
||||
import ru.landgrafhomyak.db.serdha0.api.misc.Reducer
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.InputRow
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.OutputRow
|
||||
|
||||
public class HasRows private constructor(context: Reducer.Constructor.Scope<HasRows>) : Reducer.Action<HasRows> {
|
||||
@Suppress("PropertyName", "MemberVisibilityCanBePrivate")
|
||||
public val C_HasRows: Reducer.OutputColumn<Boolean, DatabaseType.BOOLEAN, HasRows> =
|
||||
context.outputColumn("flag", context.types.BOOLEAN, false)
|
||||
|
||||
override fun calculate(acc: OutputRow<HasRows>, row: OutputRow<HasRows>, newAcc: InputRow<HasRows>) {
|
||||
newAcc[this.C_HasRows] = true
|
||||
}
|
||||
|
||||
public object Constructor : Reducer.Constructor<HasRows> {
|
||||
override fun createReducer(context: Reducer.Constructor.Scope<HasRows>): Reducer.Action<HasRows> =
|
||||
HasRows(context)
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package ru.landgrafhomyak.db.serdha0.user_commons.reducers
|
||||
|
||||
import ru.landgrafhomyak.db.serdha0.api.misc.DatabaseType
|
||||
import ru.landgrafhomyak.db.serdha0.api.misc.Reducer
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.InputRow
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.OutputRow
|
||||
|
||||
public class Max<RT, DT : DatabaseType._VirtualType<RT, *, *>> private constructor(
|
||||
context: Reducer.Constructor.Scope<Max<RT, DT>>,
|
||||
private val _type: DT
|
||||
) : Reducer.Action<Max<RT, DT>> {
|
||||
@Suppress("PropertyName", "MemberVisibilityCanBePrivate")
|
||||
public val C_MaxValue: Reducer.BidirectionalColumn<RT, DT, Max<RT, DT>> = context.bidirectionalColumn("max_value", this._type)
|
||||
|
||||
override fun calculate(acc: OutputRow<Max<RT, DT>>, row: OutputRow<Max<RT, DT>>, newAcc: InputRow<Max<RT, DT>>) {
|
||||
val accumulatedValue = acc[this.C_MaxValue]
|
||||
val newValue = row[this.C_MaxValue]
|
||||
if (this._type._compare(accumulatedValue, newValue) < 0)
|
||||
newAcc[this.C_MaxValue] = newValue
|
||||
else
|
||||
newAcc[this.C_MaxValue] = accumulatedValue
|
||||
}
|
||||
|
||||
public class Constructor<RT, DT : DatabaseType._VirtualType<RT, *, *>>(private val type: DT) : Reducer.Constructor<Max<RT, DT>> {
|
||||
override fun createReducer(context: Reducer.Constructor.Scope<Max<RT, DT>>): Reducer.Action<Max<RT, DT>> =
|
||||
Max(context, this.type)
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package ru.landgrafhomyak.db.serdha0.user_commons.reducers
|
||||
|
||||
import ru.landgrafhomyak.db.serdha0.api.misc.DatabaseType
|
||||
import ru.landgrafhomyak.db.serdha0.api.misc.Reducer
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.InputRow
|
||||
import ru.landgrafhomyak.db.serdha0.api.runtime.OutputRow
|
||||
|
||||
public class Min<RT, DT : DatabaseType._VirtualType<RT, *, *>> private constructor(
|
||||
context: Reducer.Constructor.Scope<Min<RT, DT>>,
|
||||
private val _type: DT
|
||||
) : Reducer.Action<Min<RT, DT>> {
|
||||
@Suppress("PropertyName", "MemberVisibilityCanBePrivate")
|
||||
public val C_MinValue: Reducer.BidirectionalColumn<RT, DT, Min<RT, DT>> = context.bidirectionalColumn("min_value", this._type)
|
||||
|
||||
override fun calculate(acc: OutputRow<Min<RT, DT>>, row: OutputRow<Min<RT, DT>>, newAcc: InputRow<Min<RT, DT>>) {
|
||||
val accumulatedValue = acc[this.C_MinValue]
|
||||
val newValue = row[this.C_MinValue]
|
||||
if (this._type._compare(accumulatedValue, newValue) > 0)
|
||||
newAcc[this.C_MinValue] = newValue
|
||||
else
|
||||
newAcc[this.C_MinValue] = accumulatedValue
|
||||
}
|
||||
|
||||
public class Constructor<RT, DT : DatabaseType._VirtualType<RT, *, *>>(private val type: DT) : Reducer.Constructor<Min<RT, DT>> {
|
||||
override fun createReducer(context: Reducer.Constructor.Scope<Min<RT, DT>>): Reducer.Action<Min<RT, DT>> =
|
||||
Min(context, this.type)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user