-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
168 changed files
with
4,720 additions
and
4,480 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
partiql-eval/src/main/kotlin/org/partiql/eval/internal/Accumulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
13 changes: 13 additions & 0 deletions
13
partiql-eval/src/main/kotlin/org/partiql/eval/internal/Aggregation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
partiql-eval/src/main/kotlin/org/partiql/eval/internal/Routine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
39 changes: 39 additions & 0 deletions
39
partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAny.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!) | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAvg.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
27 changes: 27 additions & 0 deletions
27
partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggCount.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggGroupAs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
Oops, something went wrong.