From 6fcde573b90fc5f180a79726edfb98f350b4e6e1 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Thu, 20 Jun 2024 10:48:56 -0700 Subject: [PATCH] Backup --- .../org/partiql/eval/internal/Accumulator.kt | 2 +- .../org/partiql/eval/internal/Aggregation.kt | 9 +- .../org/partiql/eval/internal/Routines.kt | 12 ++ .../partiql/eval/internal/SqlAggregations.kt | 13 ++ .../partiql/eval/internal/routines/AggAny.kt | 6 +- .../partiql/eval/internal/routines/AggAvg.kt | 30 +-- .../partiql/eval/internal/routines/AggMax.kt | 157 +++------------ .../partiql/eval/internal/routines/AggMin.kt | 157 +++------------ .../eval/internal/routines/FnIsNull.kt | 19 +- .../org/partiql/planner/intern/SqlTypes.kt | 90 ++++----- .../planner/intern/validate/SqlTyper.kt | 18 +- .../planner/intern/validate/StaticTypes.kt | 186 ------------------ .../spi/connector/sql/builtins/FnIsNull.kt | 32 --- 13 files changed, 171 insertions(+), 560 deletions(-) create mode 100644 partiql-eval/src/main/kotlin/org/partiql/eval/internal/Routines.kt create mode 100644 partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlAggregations.kt delete mode 100644 partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/StaticTypes.kt delete mode 100644 partiql-spi/src/main/kotlin/org/partiql/spi/connector/sql/builtins/FnIsNull.kt diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Accumulator.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Accumulator.kt index 5f9e7bea5..55a414da3 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Accumulator.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Accumulator.kt @@ -7,7 +7,7 @@ import org.partiql.eval.value.Datum * * TODO consider a `done()` method for short-circuiting. */ -internal interface Accumulator { +interface Accumulator { /** * Apply args to the accumulator. diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Aggregation.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Aggregation.kt index d5e10b124..c244f60ac 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Aggregation.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Aggregation.kt @@ -1,13 +1,14 @@ package org.partiql.eval.internal -interface Aggregation { - - public fun getKey(): String +/** + * + */ +internal fun interface Aggregation { /** * Instantiates a stateful accumulator for this aggregation function. * * @return */ - public fun accumulator(): Accumulator + fun accumulator(): Accumulator } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Routines.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Routines.kt new file mode 100644 index 000000000..602bde0f3 --- /dev/null +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Routines.kt @@ -0,0 +1,12 @@ +package org.partiql.eval.internal + +import org.partiql.spi.fn.Agg + +internal class Routines( + private val functions: Map, + private val aggregations: Map, +) { + + + +} \ No newline at end of file diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlAggregations.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlAggregations.kt new file mode 100644 index 000000000..829943b1b --- /dev/null +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlAggregations.kt @@ -0,0 +1,13 @@ +package org.partiql.eval.internal + +internal class SqlAggregations private constructor(private val map: Map) { + + fun get(specific: String): Aggregation? = map[specific] + + companion object { + + + + } + +} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAny.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAny.kt index 63678ab61..0c267e61b 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAny.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAny.kt @@ -7,10 +7,10 @@ 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 +import org.partiql.types.PType /** - * Note that SOME is normalized to ANY. + * Note that SOME(v) is normalized to ANY(v). */ internal object AGG_ANY__BOOL__BOOL : Aggregation { @@ -32,7 +32,7 @@ internal object AGG_ANY__BOOL__BOOL : Aggregation { } override fun value(): Datum = when (result) { - null -> Datum.nullValue(PartiQLValueType.BOOL) + null -> Datum.nullValue(PType.typeBool()) else -> Datum.boolValue(result!!) } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAvg.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAvg.kt index aad9543b3..c4ec92c77 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAvg.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggAvg.kt @@ -5,29 +5,15 @@ 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" +internal class AggAvg { + const val + +} + +internal + +internal val AGG_AVG__TINYINT__TINYINT : Aggregation("AGG_AVG__TINYINT___TINYINT") { override fun accumulator() = TODO("Accumulator not implemented") } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMax.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMax.kt index 7cc147d94..581aaa182 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMax.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMax.kt @@ -1,162 +1,69 @@ // ktlint-disable filename -@file:Suppress("ClassName") +@file:Suppress("ClassName", "unused") package org.partiql.eval.internal.routines -import org.partiql.spi.connector.sql.builtins.internal.AccumulatorMax -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.DECIMAL_ARBITRARY -import org.partiql.value.PType.Kind.FLOAT32 -import org.partiql.value.PType.Kind.FLOAT64 -import org.partiql.value.PType.Kind.INT -import org.partiql.value.PType.Kind.SMALLINT -import org.partiql.value.PType.Kind.INT -import org.partiql.value.PType.Kind.BIGINT -import org.partiql.value.PType.Kind.TINYINT - - -internal object Agg_MAX__TINYINT__TINYINT : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "max", - returns = TINYINT, - parameters = listOf( - FnParameter("value", TINYINT), - ), - isNullable = true, - isDecomposable = true - ) - - override fun accumulator(): Accumulator = AccumulatorMax() -} - +import org.partiql.eval.internal.Aggregation -internal object Agg_MAX__SMALLINT__SMALLINT : Aggregation { +internal object AGG_MAX__TINYINT__TINYINT : Aggregation { - override val signature: AggSignature = AggSignature( - name = "max", - returns = SMALLINT, - parameters = listOf( - FnParameter("value", SMALLINT), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MAX__TINYINT___TINYINT" - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MAX__SMALLINT__SMALLINT : Aggregation { -internal object Agg_MAX__INT__INT : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "max", - returns = INT, - parameters = listOf( - FnParameter("value", INT), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MAX__SMALLINT___SMALLINT" - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MAX__INT__INT : Aggregation { -internal object Agg_MAX__BIGINT__BIGINT : Aggregation { + override fun getKey(): String = "AGG_MAX__INT___INT" - override val signature: AggSignature = AggSignature( - name = "max", - returns = BIGINT, - parameters = listOf( - FnParameter("value", BIGINT), - ), - isNullable = true, - isDecomposable = true - ) - - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MAX__BIGINT__BIGINT : Aggregation { -internal object Agg_MAX__NUMERIC__INT : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "max", - returns = INT, - parameters = listOf( - FnParameter("value", INT), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MAX__BIGINT___BIGINT" - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MAX__NUMERIC__INT : Aggregation { -internal object Agg_MAX__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "max", - returns = DECIMAL_ARBITRARY, - parameters = listOf( - FnParameter("value", DECIMAL_ARBITRARY), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MAX__NUMERIC___NUMERIC" - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MAX__DECIMAL__DECIMAL : Aggregation { -internal object Agg_MAX__FLOAT32__FLOAT32 : Aggregation { + override fun getKey(): String = "AGG_MAX__NUMERIC___NUMERIC" - override val signature: AggSignature = AggSignature( - name = "max", - returns = FLOAT32, - parameters = listOf( - FnParameter("value", FLOAT32), - ), - isNullable = true, - isDecomposable = true - ) - - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MAX__REAL__REAL : Aggregation { -internal object Agg_MAX__FLOAT64__FLOAT64 : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "max", - returns = FLOAT64, - parameters = listOf( - FnParameter("value", FLOAT64), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MAX__REAL___REAL" - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MAX__DOUBLE__DOUBLE : Aggregation { + + override fun getKey(): String = "AGG_MAX__SMALLINT___SMALLINT" + + override fun accumulator() = TODO("Accumulator not implemented") +} -internal object Agg_MAX__DYNAMIC__DYNAMIC : Aggregation { +internal object AGG_MAX__DYNAMIC__DYNAMIC : Aggregation { - override val signature: AggSignature = AggSignature( - name = "max", - returns = DYNAMIC, - parameters = listOf( - FnParameter("value", DYNAMIC), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MAX__SMALLINT___SMALLINT" - override fun accumulator(): Accumulator = AccumulatorMax() + override fun accumulator() = TODO("Accumulator not implemented") } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMin.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMin.kt index 945f87c86..afac4fe00 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMin.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/AggMin.kt @@ -1,162 +1,69 @@ // ktlint-disable filename -@file:Suppress("ClassName") +@file:Suppress("ClassName", "unused") package org.partiql.eval.internal.routines -import org.partiql.spi.connector.sql.builtins.internal.AccumulatorMin -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.DECIMAL_ARBITRARY -import org.partiql.value.PType.Kind.FLOAT32 -import org.partiql.value.PType.Kind.FLOAT64 -import org.partiql.value.PType.Kind.INT -import org.partiql.value.PType.Kind.SMALLINT -import org.partiql.value.PType.Kind.INT -import org.partiql.value.PType.Kind.BIGINT -import org.partiql.value.PType.Kind.TINYINT - - -internal object Agg_MIN__TINYINT__TINYINT : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "min", - returns = TINYINT, - parameters = listOf( - FnParameter("value", TINYINT), - ), - isNullable = true, - isDecomposable = true - ) - - override fun accumulator(): Accumulator = AccumulatorMin() -} - +import org.partiql.eval.internal.Aggregation -internal object Agg_MIN__SMALLINT__SMALLINT : Aggregation { +internal object AGG_MIN__TINYINT__TINYINT : Aggregation { - override val signature: AggSignature = AggSignature( - name = "min", - returns = SMALLINT, - parameters = listOf( - FnParameter("value", SMALLINT), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MIN__TINYINT___TINYINT" - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MIN__SMALLINT__SMALLINT : Aggregation { -internal object Agg_MIN__INT__INT : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "min", - returns = INT, - parameters = listOf( - FnParameter("value", INT), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MIN__SMALLINT___SMALLINT" - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MIN__INT__INT : Aggregation { -internal object Agg_MIN__BIGINT__BIGINT : Aggregation { + override fun getKey(): String = "AGG_MIN__INT___INT" - override val signature: AggSignature = AggSignature( - name = "min", - returns = BIGINT, - parameters = listOf( - FnParameter("value", BIGINT), - ), - isNullable = true, - isDecomposable = true - ) - - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MIN__BIGINT__BIGINT : Aggregation { -internal object Agg_MIN__NUMERIC__INT : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "min", - returns = INT, - parameters = listOf( - FnParameter("value", INT), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MIN__BIGINT___BIGINT" - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MIN__NUMERIC__INT : Aggregation { -internal object Agg_MIN__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "min", - returns = DECIMAL_ARBITRARY, - parameters = listOf( - FnParameter("value", DECIMAL_ARBITRARY), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MIN__NUMERIC___NUMERIC" - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MIN__DECIMAL__DECIMAL : Aggregation { -internal object Agg_MIN__FLOAT32__FLOAT32 : Aggregation { + override fun getKey(): String = "AGG_MIN__NUMERIC___NUMERIC" - override val signature: AggSignature = AggSignature( - name = "min", - returns = FLOAT32, - parameters = listOf( - FnParameter("value", FLOAT32), - ), - isNullable = true, - isDecomposable = true - ) - - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MIN__REAL__REAL : Aggregation { -internal object Agg_MIN__FLOAT64__FLOAT64 : Aggregation { - - override val signature: AggSignature = AggSignature( - name = "min", - returns = FLOAT64, - parameters = listOf( - FnParameter("value", FLOAT64), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MIN__REAL___REAL" - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } +internal object AGG_MIN__DOUBLE__DOUBLE : Aggregation { + + override fun getKey(): String = "AGG_MIN__SMALLINT___SMALLINT" + + override fun accumulator() = TODO("Accumulator not implemented") +} -internal object Agg_MIN__DYNAMIC__DYNAMIC : Aggregation { +internal object AGG_MIN__DYNAMIC__DYNAMIC : Aggregation { - override val signature: AggSignature = AggSignature( - name = "min", - returns = DYNAMIC, - parameters = listOf( - FnParameter("value", DYNAMIC), - ), - isNullable = true, - isDecomposable = true - ) + override fun getKey(): String = "AGG_MIN__SMALLINT___SMALLINT" - override fun accumulator(): Accumulator = AccumulatorMin() + override fun accumulator() = TODO("Accumulator not implemented") } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/FnIsNull.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/FnIsNull.kt index a0207c000..92def58e1 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/FnIsNull.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/routines/FnIsNull.kt @@ -3,27 +3,30 @@ package org.partiql.eval.internal.routines +import org.partiql.spi.fn.Fn +import org.partiql.spi.fn.FnExperimental import org.partiql.spi.fn.FnParameter import org.partiql.spi.fn.FnSignature -import org.partiql.value.Datum -import org.partiql.value.PType.Kind.DYNAMIC -import org.partiql.value.PType.Kind.BOOL +import org.partiql.value.PartiQLValue +import org.partiql.value.PartiQLValueExperimental +import org.partiql.value.PartiQLValueType.ANY +import org.partiql.value.PartiQLValueType.BOOL import org.partiql.value.boolValue - -internal object Fn_IS_NULL__DYNAMIC__BOOL : Routine { +@OptIn(PartiQLValueExperimental::class, FnExperimental::class) +internal object Fn_IS_NULL__ANY__BOOL : Fn { override val signature = FnSignature( name = "is_null", returns = BOOL, - parameters = listOf(FnParameter("value", DYNAMIC)), + parameters = listOf(FnParameter("value", ANY)), isNullable = false, isNullCall = false, isMissable = false, - isMissingCall = false, + isMissingCall = true, ) - override fun invoke(args: Array): Datum { + override fun invoke(args: Array): PartiQLValue { return boolValue(args[0].isNull) } } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/intern/SqlTypes.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/intern/SqlTypes.kt index fab8d634f..3e0a33b6c 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/intern/SqlTypes.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/intern/SqlTypes.kt @@ -6,240 +6,240 @@ import org.partiql.value.PartiQLValueType /** * Facade for instantiating types; we can drop T once the switch from StaticType to PType is complete. */ -internal interface SqlTypes { +internal object SqlTypes { /** * Create a type from the enum. */ - fun create(type: PartiQLValueType): T + fun create(type: PartiQLValueType): PType /** * Create a type form the enum with the given arguments. */ - fun create(type: PartiQLValueType, vararg args: Any): T + fun create(type: PartiQLValueType, vararg args: Any): PType /** * The `dynamic` type. */ - fun dynamic(): T + fun dynamic(): PType /** * The `dynamic` type with known variants. */ - fun dynamic(variants: Set): T + fun dynamic(variants: Set): PType /** * The `dynamic` type with known variants. */ - fun dynamic(variants: List): T = dynamic(variants.toSet()) + fun dynamic(variants: List): PType = dynamic(variants.toSet()) /** * The `dynamic` type with known variants. */ - fun dynamic(vararg variants: T): T = dynamic(variants.toSet()) + fun dynamic(vararg variants: PType): PType = dynamic(variants.toSet()) /** * Boolean type. */ - fun bool(): T + fun bool(): PType /** * Signed 8-bit integer. * - * Aliases: TINYINT, INT1. + * Aliases: PTypeINYINT, INT1. */ - fun tinyint(): T + fun tinyint(): PType /** * Signed 16-bit integer. * * Aliases: SMALLINT, INT2. */ - fun smallint(): T + fun smallint(): PType /** * Signed 32-bit integer. * * Aliases: INTEGER, INT, INT4. */ - fun int(): T + fun int(): PType /** * Signed 64-bit integer. * * Aliases: BIGINT, INT8. */ - fun bigint(): T + fun bigint(): PType /** * Exact numeric type with arbitrary precision and scale zero (0). * * Aliases: NUMERIC. */ - fun numeric(): T + fun numeric(): PType /** * Exact numeric type with the given decimal precision and scale zero (0). * * Aliases: NUMERIC(p), DECIMAL(p). */ - fun decimal(precision: Int): T + fun decimal(precision: Int): PType /** * Numeric value with the given decimal precision and scale. * * Aliases: NUMERIC(p, s), DECIMAL(p, s). */ - fun decimal(precision: Int, scale: Int): T + fun decimal(precision: Int, scale: Int): PType /** * Exact numeric type with arbitrary precision and scale. * * Aliases: DECIMAL. */ - fun decimal(): T + fun decimal(): PType /** * Approximate numeric type with binary precision equal to or greater than the given precision. * * Aliases: FLOAT(p). */ - fun float(precision: Int): T + fun float(precision: Int): PType /** * Approximate numeric type for the IEEE-754 32-bit floating point. * * Aliases: REAL, FLOAT4. */ - fun real(): T + fun real(): PType /** * Approximate numeric type for the IEEE-754 64-bit floating point. * * Aliases: DOUBLE, DOUBLE PRECISION, FLOAT8. */ - fun double(): T + fun double(): PType /** * Unicode codepoint sequence with fixed length. * * Aliases: CHAR. */ - fun char(length: Int): T + fun char(length: Int): PType /** * Unicode codepoint sequence with arbitrary length. * * Aliases: VARCHAR, STRING. */ - fun varchar(): T + fun varchar(): PType /** * Unicode codepoint sequence with max length. * * Aliases: VARCHAR(N). */ - fun varchar(length: Int): T + fun varchar(length: Int): PType /** * TODO */ - fun date(): T + fun date(): PType /** * TODO */ - fun time(): T + fun time(): PType /** * TODO */ - fun time(precision: Int): T + fun time(precision: Int): PType /** * TODO */ - fun timestamp(): T + fun timestamp(): PType /** * */ - fun timestamp(precision: Int): T + fun timestamp(precision: Int): PType /** * Aliases: CLOB */ - fun clob(): T + fun clob(): PType /** * Aliases: BLOB */ - fun blob(): T + fun blob(): PType /** * Variable-length, ordered collection of elements with type DYNAMIC. * * Aliases: ARRAY, LIST */ - fun array(): T + fun array(): PType /** * Variable-length, ordered collection of elements with the given type. * - * Aliases: T ARRAY, ARRAY. + * Aliases: PType ARRAY, ARRAY. */ - fun array(element: T): T + fun array(element: PType): PType /** * Fixed-length, ordered collection of elements with the given type. * - * Aliases: T ARRAY[N], ARRAY[N]. + * Aliases: PType ARRAY[N], ARRAY[N]. */ - fun array(element: T, size: Int): T + fun array(element: PType, size: Int): PType /** * Variable-length, unordered collection of elements with type DYNAMIC. * * Aliases: BAG */ - fun bag(): T + fun bag(): PType /** * Variable-length, unordered collection of elements with the given type. * - * Aliases: T BAG, BAG. + * Aliases: PType BAG, BAG. */ - fun bag(element: T): T + fun bag(element: PType): PType /** * Fixed-length, unordered collection of elements with the given type. * - * Aliases: T BAG[N], BAG[N]. + * Aliases: PType BAG[N], BAG[N]. */ - fun bag(element: T, size: Int): T + fun bag(element: PType, size: Int): PType /** * Ordered collection of name-value pairs with some known fields; always open. */ - fun row(attributes: List>): T + fun row(attributes: List>): PType /** * Ordered collection of name-value pairs with some known fields; always open. */ - fun row(vararg attributes: Pair): T = row(attributes.toList()) + fun row(vararg attributes: Pair): PType = row(attributes.toList()) /** * Unordered collection of name-value pairs; always open. */ - fun struct(): T + fun struct(): PType /** * Unordered collection of name-value pairs with some known fields; always open. */ - fun struct(attributes: Collection>): T + fun struct(attributes: Collection>): PType /** * Unordered collection of name-value pairs with some known fields; always open. */ - fun struct(vararg attributes: Pair): T = row(attributes.toList()) + fun struct(vararg attributes: Pair): PType = row(attributes.toList()) } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/SqlTyper.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/SqlTyper.kt index 311a929f3..adb591709 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/SqlTyper.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/SqlTyper.kt @@ -7,8 +7,8 @@ import org.partiql.types.CollectionType import org.partiql.types.ListType import org.partiql.types.MissingType import org.partiql.types.SexpType -import org.partiql.types.StaticType -import org.partiql.types.StaticType.Companion.MISSING +import org.partiql.types.CompilerType +import org.partiql.types.CompilerType.Companion.MISSING import org.partiql.types.StructType import org.partiql.types.TupleConstraint @@ -25,12 +25,12 @@ internal object SqlTyper { /** * TODO hardcoded for now; shouldn't be needed with PType. */ - private val factory = StaticTypes + private val factory = CompilerTypes /** * Compute a FROM Clause return type. */ - fun getScanType(type: StaticType): StaticType = when (type) { + fun getScanType(type: CompilerType): CompilerType = when (type) { is BagType -> type.elementType is ListType -> type.elementType is AnyType -> factory.dynamic() @@ -41,7 +41,7 @@ internal object SqlTyper { /** * Compute an UNPIVOT Clause return type. */ - fun getUnpivotType(type: StaticType): StaticType { + fun getUnpivotType(type: CompilerType): CompilerType { val variants = type.allTypes.map { variant -> if (variant !is StructType) { return variant @@ -58,15 +58,15 @@ internal object SqlTyper { /** * Compute the return type for a Rex.Op.Path.Index */ - fun getPathIndexType(rootT: StaticType, keyT: StaticType): StaticType { + fun getPathIndexType(rootT: CompilerType, keyT: CompilerType): CompilerType { val elementTypes = rootT.allTypes.map { type -> if (type !is ListType && type !is SexpType) { - return@map StaticType.MISSING + return@map CompilerType.MISSING } (type as CollectionType).elementType }.toSet() if (elementTypes.all { it is MissingType }) { - return StaticType.MISSING + return CompilerType.MISSING } return factory.dynamic(elementTypes) } @@ -74,7 +74,7 @@ internal object SqlTyper { /** * Compute the return type for a Rex.Op.Path.Key */ - fun getPathKeyType(rootT: StaticType, keyT: StaticType): StaticType { + fun getPathKeyType(rootT: CompilerType, keyT: CompilerType): CompilerType { TODO() } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/StaticTypes.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/StaticTypes.kt deleted file mode 100644 index e9b999bcc..000000000 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/intern/validate/StaticTypes.kt +++ /dev/null @@ -1,186 +0,0 @@ -package org.partiql.planner.intern.validate - -import org.partiql.planner.intern.SqlTypes -import org.partiql.types.AnyOfType -import org.partiql.types.AnyType -import org.partiql.types.BagType -import org.partiql.types.DecimalType -import org.partiql.types.FloatType -import org.partiql.types.ListType -import org.partiql.types.NumberConstraint -import org.partiql.types.StaticType -import org.partiql.types.StringType -import org.partiql.types.StructType -import org.partiql.types.TimeType -import org.partiql.types.TimestampType -import org.partiql.types.TupleConstraint -import org.partiql.value.PartiQLTimestampExperimental -import org.partiql.value.PartiQLValueType - -internal object StaticTypes : SqlTypes { - - override fun create(type: PartiQLValueType): StaticType = TODO("Not yet implemented") - - override fun create(type: PartiQLValueType, vararg args: Any): StaticType = TODO("Not yet implemented") - - override fun dynamic(): StaticType = StaticType.ANY - - /** - * If ANY is one of the types in the variants, we return ANY. Else, return a UNION type. - */ - override fun dynamic(variants: Set): StaticType { - return if (variants.any { it is AnyType }) dynamic() else AnyOfType(variants).flatten() - } - - override fun bool() = StaticType.BOOL - - override fun tinyint(): StaticType = error("StaticTypes does not support 'tinyint'") - - override fun smallint(): StaticType = StaticType.INT2 - - override fun int(): StaticType = StaticType.INT4 - - override fun bigint(): StaticType = StaticType.INT8 - - override fun numeric(): StaticType = StaticType.INT - - override fun decimal(precision: Int): StaticType { - return DecimalType( - DecimalType.PrecisionScaleConstraint.Constrained( - precision = precision, - scale = 0, - ) - ) - } - - override fun decimal(precision: Int, scale: Int): StaticType { - return DecimalType( - DecimalType.PrecisionScaleConstraint.Constrained( - precision = precision, - scale = scale, - ) - ) - } - - override fun decimal(): StaticType { - return DecimalType( - DecimalType.PrecisionScaleConstraint.Unconstrained - ) - } - - override fun float(precision: Int): StaticType = FloatType() - - override fun real(): StaticType = FloatType() - - override fun double(): StaticType = FloatType() - - override fun char(length: Int): StaticType { - return StringType( - StringType.StringLengthConstraint.Constrained( - NumberConstraint.Equals(length) - ) - ) - } - - override fun varchar(): StaticType { - return StringType( - StringType.StringLengthConstraint.Unconstrained - ) - } - - override fun varchar(length: Int): StaticType { - return StringType( - StringType.StringLengthConstraint.Constrained( - NumberConstraint.UpTo(length) - ) - ) - } - - override fun date(): StaticType = StaticType.DATE - - override fun time(): StaticType = StaticType.TIME - - override fun time(precision: Int): StaticType = TimeType(precision) - - override fun timestamp(): StaticType = StaticType.TIMESTAMP - - @OptIn(PartiQLTimestampExperimental::class) - override fun timestamp(precision: Int): StaticType = TimestampType(precision) - - override fun clob(): StaticType = StaticType.CLOB - - override fun blob(): StaticType = StaticType.BLOB - - override fun array(): StaticType = ListType(StaticType.ANY) - - override fun array(element: StaticType): StaticType = ListType(element) - - override fun array(element: StaticType, size: Int): StaticType { - error("StaticTypes does not support length-constrained arrays") - } - - override fun bag(): StaticType = BagType(StaticType.ANY) - - override fun bag(element: StaticType): StaticType = BagType(element) - - override fun bag(element: StaticType, size: Int): StaticType { - error("StaticTypes does not support length-constrained bags") - } - - override fun row(attributes: List>): StaticType { - val seen = mutableSetOf() - val fields = attributes.map { - val attr = it.first - val type = it.second - if (seen.contains(attr)) { - error("row cannot contain duplicate attributes, `$attr`") - } else { - seen.add(attr) - } - StructType.Field(attr, type) - } - return StructType( - fields = fields, - contentClosed = true, - constraints = setOf( - TupleConstraint.Ordered, - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - ) - ) - } - - override fun row(vararg attributes: Pair): StaticType = row(attributes.toList()) - - override fun struct(): StaticType { - return StructType( - fields = emptyList(), - contentClosed = false, - constraints = setOf(TupleConstraint.Open(true)) - ) - } - - override fun struct(attributes: Collection>): StaticType { - var uniq = true - val seen = mutableSetOf() - val fields = attributes.map { - val attr = it.first - val type = it.second - if (seen.contains(attr)) { - uniq = false - } - seen.add(attr) - StructType.Field(attr, type) - } - return StructType( - fields = fields, - contentClosed = false, - constraints = setOf( - TupleConstraint.Open(true), - TupleConstraint.UniqueAttrs(uniq), - ) - ) - } - - override fun struct(vararg attributes: Pair): StaticType = struct(attributes.toList()) -} diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/connector/sql/builtins/FnIsNull.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/connector/sql/builtins/FnIsNull.kt deleted file mode 100644 index 6c1a8ff7c..000000000 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/connector/sql/builtins/FnIsNull.kt +++ /dev/null @@ -1,32 +0,0 @@ -// ktlint-disable filename -@file:Suppress("ClassName") - -package org.partiql.spi.connector.sql.builtins - -import org.partiql.spi.fn.Fn -import org.partiql.spi.fn.FnExperimental -import org.partiql.spi.fn.FnParameter -import org.partiql.spi.fn.FnSignature -import org.partiql.value.PartiQLValue -import org.partiql.value.PartiQLValueExperimental -import org.partiql.value.PartiQLValueType.ANY -import org.partiql.value.PartiQLValueType.BOOL -import org.partiql.value.boolValue - -@OptIn(PartiQLValueExperimental::class, FnExperimental::class) -internal object Fn_IS_NULL__ANY__BOOL : Fn { - - override val signature = FnSignature( - name = "is_null", - returns = BOOL, - parameters = listOf(FnParameter("value", ANY)), - isNullable = false, - isNullCall = false, - isMissable = false, - isMissingCall = true, - ) - - override fun invoke(args: Array): PartiQLValue { - return boolValue(args[0].isNull) - } -}