Skip to content

Commit

Permalink
Backup function moves
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Jun 18, 2024
1 parent 870f7c6 commit 60b77ff
Show file tree
Hide file tree
Showing 168 changed files with 4,720 additions and 4,480 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.partiql.eval.internal

import org.partiql.eval.value.Datum

/**
* Aggregation function state.
*
* TODO consider a `done()` method for short-circuiting.
*/
internal interface Accumulator {

/**
* Apply args to the accumulator.
*
* @param args
* @return
*/
fun next(args: Array<Datum>)

/**
* Return the accumulator value.
*
* @return
*/
fun value(): Datum
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.partiql.eval.internal

interface Aggregation {

public fun getKey(): String

/**
* Instantiates a stateful accumulator for this aggregation function.
*
* @return
*/
public fun accumulator(): Accumulator
}
14 changes: 14 additions & 0 deletions partiql-eval/src/main/kotlin/org/partiql/eval/internal/Routine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.partiql.eval.internal

import org.partiql.eval.value.Datum

internal interface Routine {

/**
* Invoke the routine with the given arguments.
*
* @param args
* @return
*/
fun invoke(args: Array<Datum>): Datum
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ktlint-disable filename
@file:Suppress("ClassName")

package org.partiql.eval.internal.routines

import org.partiql.eval.internal.Accumulator
import org.partiql.eval.internal.Aggregation
import org.partiql.eval.internal.routines.internal.isAbsent
import org.partiql.eval.value.Datum
import org.partiql.value.PartiQLValueType

/**
* Note that SOME is normalized to ANY.
*/
internal object AGG_ANY__BOOL__BOOL : Aggregation {

override fun getKey(): String = "AGG_ANY__BOOL___BOOL"

override fun accumulator() = object : Accumulator {

private var result: Boolean? = null

override fun next(args: Array<Datum>) {
if (result == true) {
return // short-circuit
}
val arg = args[0]
if (arg.isAbsent()) {
return
}
result = arg.boolean
}

override fun value(): Datum = when (result) {
null -> Datum.nullValue(PartiQLValueType.BOOL)
else -> Datum.boolValue(result!!)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ktlint-disable filename
@file:Suppress("ClassName", "unused")

package org.partiql.eval.internal.routines

import org.partiql.eval.internal.Aggregation

// internal class AccumulatorAvg(
// private val targetType: PartiQLValueType = PartiQLValueType.DYNAMIC
// ) : Accumulator() {
//
// var sum: Number = 0.0
// var count: Long = 0L
//
// override fun nextValue(value: Datum) {
// checkIsNumberType(funcName = "AVG", value = value)
// this.sum += value.numberValue()
// this.count += 1L
// }
//
// override fun value(): Datum = when (count) {
// 0L -> nullToTargetType(targetType)
// else -> (sum / bigDecimalOf(count)).toTargetType(targetType)
// }
// }

internal object AGG_AVG__TINYINT__TINYINT : Aggregation {

override fun getKey(): String = "AGG_AVG__TINYINT___TINYINT"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__SMALLINT__SMALLINT : Aggregation {

override fun getKey(): String = "AGG_AVG__SMALLINT___SMALLINT"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__INT__INT : Aggregation {

override fun getKey(): String = "AGG_AVG__INT___INT"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__BIGINT__BIGINT : Aggregation {

override fun getKey(): String = "AGG_AVG__BIGINT___BIGINT"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__NUMERIC__INT : Aggregation {

override fun getKey(): String = "AGG_AVG__NUMERIC___NUMERIC"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__DECIMAL__DECIMAL : Aggregation {

override fun getKey(): String = "AGG_AVG__NUMERIC___NUMERIC"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__REAL__REAL : Aggregation {

override fun getKey(): String = "AGG_AVG__REAL___REAL"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__DOUBLE__DOUBLE : Aggregation {

override fun getKey(): String = "AGG_AVG__SMALLINT___SMALLINT"

override fun accumulator() = TODO("Accumulator not implemented")
}

internal object AGG_AVG__DYNAMIC__DYNAMIC : Aggregation {

override fun getKey(): String = "AGG_AVG__SMALLINT___SMALLINT"

override fun accumulator() = TODO("Accumulator not implemented")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ktlint-disable filename
@file:Suppress("ClassName")

package org.partiql.eval.internal.routines

import org.partiql.spi.connector.sql.builtins.internal.AccumulatorCount
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.AggSignature
import org.partiql.spi.fn.FnParameter
import org.partiql.value.PType.Kind.DYNAMIC
import org.partiql.value.PType.Kind.BIGINT


internal object Agg_COUNT__DYNAMIC__BIGINT : Aggregation {

override val signature: AggSignature = AggSignature(
name = "count",
returns = BIGINT,
parameters = listOf(
FnParameter("value", DYNAMIC),
),
isNullable = false,
isDecomposable = true
)

override fun accumulator(): Accumulator = AccumulatorCount()
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// ktlint-disable filename
@file:Suppress("ClassName")

package org.partiql.spi.connector.sql.builtins
package org.partiql.eval.internal.routines

import org.partiql.spi.connector.sql.builtins.internal.AccumulatorEvery
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.AggSignature
import org.partiql.spi.fn.FnExperimental
import org.partiql.spi.fn.FnParameter
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.PartiQLValueType.ANY
import org.partiql.value.PartiQLValueType.BOOL
import org.partiql.value.PType.Kind.DYNAMIC
import org.partiql.value.PType.Kind.BOOL

@OptIn(PartiQLValueExperimental::class, FnExperimental::class)
public object Agg_EVERY__BOOL__BOOL : Agg {

internal object Agg_EVERY__BOOL__BOOL : Aggregation {

override val signature: AggSignature = AggSignature(
name = "every",
Expand All @@ -25,21 +23,21 @@ public object Agg_EVERY__BOOL__BOOL : Agg {
isDecomposable = true
)

override fun accumulator(): Agg.Accumulator = AccumulatorEvery()
override fun accumulator(): Accumulator = AccumulatorEvery()
}

@OptIn(PartiQLValueExperimental::class, FnExperimental::class)
public object Agg_EVERY__ANY__BOOL : Agg {

internal object Agg_EVERY__DYNAMIC__BOOL : Aggregation {

override val signature: AggSignature = AggSignature(
name = "every",
returns = BOOL,
parameters = listOf(
FnParameter("value", ANY),
FnParameter("value", DYNAMIC),
),
isNullable = true,
isDecomposable = true
)

override fun accumulator(): Agg.Accumulator = AccumulatorEvery()
override fun accumulator(): Accumulator = AccumulatorEvery()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ktlint-disable filename
@file:Suppress("ClassName")

package org.partiql.eval.internal.routines

import org.partiql.spi.connector.sql.builtins.internal.AccumulatorGroupAs
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.AggSignature
import org.partiql.spi.fn.FnParameter
import org.partiql.value.PType.Kind


internal object Agg_GROUP_AS__DYNAMIC__DYNAMIC : Aggregation {

override val signature: AggSignature = AggSignature(
name = "group_as",
returns = PType.Kind.DYNAMIC,
parameters = listOf(
FnParameter("value", PType.Kind.DYNAMIC),
),
isNullable = true,
isDecomposable = true
)

override fun accumulator(): Accumulator = AccumulatorGroupAs()
}
Loading

0 comments on commit 60b77ff

Please sign in to comment.