From 951ff852e0c703ca7aaa5476de740dc2774ac482 Mon Sep 17 00:00:00 2001 From: John Ed Quinn Date: Mon, 18 Nov 2024 11:31:06 -0800 Subject: [PATCH 1/2] Removes sexp and symbol from PType and Datum --- .../internal/compiler/StandardCompiler.kt | 2 +- .../eval/internal/helpers/ValueUtility.kt | 2 +- .../internal/operator/rel/RelOpExclude.kt | 5 +- .../internal/operator/rel/RelOpIterate.kt | 2 +- .../operator/rel/RelOpIteratePermissive.kt | 2 +- .../eval/internal/operator/rel/RelOpScan.kt | 2 +- .../operator/rel/RelOpScanPermissive.kt | 2 +- .../eval/internal/operator/rex/CastTable.kt | 131 +- .../internal/operator/rex/ExprCallDynamic.kt | 14 +- .../internal/operator/rex/ExprPathIndex.kt | 3 +- .../operator/rex/ExprStructPermissive.kt | 2 +- .../eval/internal/PartiQLEvaluatorTest.kt | 9 +- .../operator/rex/ExprCallDynamicTest.kt | 30 +- .../parser/internal/PartiQLParserDefault.kt | 3 +- .../org/partiql/plan/builder/PlanFactory.kt | 2 +- .../org/partiql/plan/rex/RexCallDynamic.kt | 6 +- .../partiql/planner/internal/FnComparator.kt | 3 - .../planner/internal/casts/CastTable.kt | 61 +- .../internal/transforms/PlanTransform.kt | 13 +- .../internal/transforms/RexConverter.kt | 21 +- .../planner/internal/typer/CompilerType.kt | 1 - .../planner/internal/typer/DynamicTyper.kt | 47 +- .../planner/internal/typer/PlanTyper.kt | 15 +- .../planner/internal/typer/TypeUtils.kt | 3 +- .../internal/typer/PartiQLTyperTestBase.kt | 25 +- .../internal/typer/PlanTyperTestsPorted.kt | 454 +++-- .../partiql/planner/internal/typer/Utils.kt | 36 +- .../internal/typer/functions/NullIfTest.kt | 10 +- .../typer/operator/OpArithmeticTest.kt | 28 +- .../typer/operator/OpBitwiseAndTest.kt | 34 +- .../internal/typer/operator/OpConcatTest.kt | 26 +- .../internal/typer/predicate/OpBetweenTest.kt | 54 +- .../typer/predicate/OpComparisonTest.kt | 56 +- .../internal/typer/predicate/OpInTest.kt | 32 +- .../typer/predicate/OpIsMissingTest.kt | 12 +- .../internal/typer/predicate/OpIsNullTest.kt | 12 +- .../internal/typer/predicate/OpLikeTest.kt | 34 +- .../OpTypeUnexpectedAssertionTest.kt | 15 +- .../planner/plugins/local/LocalSchema.kt | 2 +- .../kotlin/org/partiql/planner/util/Utils.kt | 169 +- .../resources/catalogs/default/pql/t_item.ion | 7 - .../resources/inputs/basics/operator.sql | 22 +- partiql-spi/api/partiql-spi.api | 2 - .../java/org/partiql/spi/value/Datum.java | 34 +- .../partiql/spi/value/DatumCollection.java | 3 +- .../partiql/spi/value/DatumComparator.java | 31 +- .../org/partiql/spi/value/DatumDecimal.java | 1 - .../java/org/partiql/spi/value/DatumNull.java | 6 +- .../org/partiql/spi/function/Builtins.kt | 125 +- .../spi/function/builtins/FnBetween.kt | 23 +- .../spi/function/builtins/FnBitLength.kt | 14 - .../spi/function/builtins/FnCardinality.kt | 13 - .../spi/function/builtins/FnCharLength.kt | 13 - .../partiql/spi/function/builtins/FnConcat.kt | 33 +- .../partiql/spi/function/builtins/FnExists.kt | 14 - .../org/partiql/spi/function/builtins/FnGt.kt | 19 +- .../partiql/spi/function/builtins/FnGte.kt | 19 +- .../spi/function/builtins/FnInCollection.kt | 1474 ----------------- .../spi/function/builtins/FnIsDecimal.kt | 2 +- .../function/builtins/FnIsDecimalArbitrary.kt | 19 - .../partiql/spi/function/builtins/FnIsSexp.kt | 19 - .../spi/function/builtins/FnIsSymbol.kt | 19 - .../partiql/spi/function/builtins/FnLike.kt | 22 - .../spi/function/builtins/FnLikeEscape.kt | 30 - .../partiql/spi/function/builtins/FnLower.kt | 12 - .../org/partiql/spi/function/builtins/FnLt.kt | 19 +- .../partiql/spi/function/builtins/FnLte.kt | 19 +- .../spi/function/builtins/FnOctetLength.kt | 14 - .../partiql/spi/function/builtins/FnPlus.kt | 4 +- .../spi/function/builtins/FnPosition.kt | 16 - .../partiql/spi/function/builtins/FnSize.kt | 13 - .../spi/function/builtins/FnSubstring.kt | 35 - .../partiql/spi/function/builtins/FnTrim.kt | 12 - .../spi/function/builtins/FnTrimChars.kt | 16 - .../spi/function/builtins/FnTrimLeading.kt | 12 - .../function/builtins/FnTrimLeadingChars.kt | 16 - .../spi/function/builtins/FnTrimTrailing.kt | 12 - .../function/builtins/FnTrimTrailingChars.kt | 16 - .../partiql/spi/function/builtins/FnUpper.kt | 12 - .../function/builtins/internal/Accumulator.kt | 4 +- .../org/partiql/spi/internal/SqlTypeFamily.kt | 3 - .../org/partiql/value/PartiQLValueType.kt | 7 +- .../partiql/value/io/PartiQLValueIonReader.kt | 50 +- .../partiql/eval/value/DatumComparatorTest.kt | 31 - .../value/io/PartiQLValueIonSerdeTest.kt | 81 +- partiql-types/api/partiql-types.api | 6 - .../main/java/org/partiql/types/PType.java | 87 +- .../org/partiql/types/FromStaticType.kt | 5 +- 88 files changed, 789 insertions(+), 3057 deletions(-) delete mode 100644 partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimalArbitrary.kt delete mode 100644 partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSexp.kt delete mode 100644 partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSymbol.kt diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt index 1d9b20d15..c12e3a3f7 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt @@ -350,7 +350,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { // Compile the candidates val candidates = Array(functions.size) { val fn = functions[it] - val fnArity = fn.parameters.size + val fnArity = fn.getParameters().size if (arity == -1) { // set first arity = fnArity diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/ValueUtility.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/ValueUtility.kt index 909854af1..de9344cef 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/ValueUtility.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/ValueUtility.kt @@ -51,7 +51,7 @@ internal object ValueUtility { */ fun Datum.getText(): String { return when (this.type.kind) { - PType.Kind.STRING, PType.Kind.SYMBOL, PType.Kind.CHAR -> this.string + PType.Kind.STRING, PType.Kind.CHAR -> this.string else -> throw TypeCheckException("Expected text, but received ${this.type}.") } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt index e63cc1d99..195ea637a 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt @@ -81,7 +81,7 @@ internal class RelOpExclude( */ private fun Datum.exclude(exclusions: List): Datum = when (this.type.kind) { PType.Kind.ROW, PType.Kind.STRUCT -> this.structExclude(exclusions) - PType.Kind.BAG, PType.Kind.ARRAY, PType.Kind.SEXP -> this.collExclude(exclusions) + PType.Kind.BAG, PType.Kind.ARRAY -> this.collExclude(exclusions) else -> this } @@ -140,7 +140,6 @@ internal class RelOpExclude( return when (type.kind) { PType.Kind.ARRAY -> Datum.array(coll) PType.Kind.BAG -> Datum.bag(coll) - PType.Kind.SEXP -> Datum.sexp(coll) else -> error("Collection type required") } } @@ -173,7 +172,7 @@ internal class RelOpExclude( // apply exclusions to subtree var value = element // apply collection index exclusions at deeper levels for lists and sexps - if (type.kind == PType.Kind.ARRAY || type.kind == PType.Kind.SEXP) { + if (type.kind == PType.Kind.ARRAY) { branches.getCollIndex(i)?.let { value = value.exclude(it.getItems()) } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt index 577dd8bd4..b2a1adc2f 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt @@ -23,7 +23,7 @@ internal class RelOpIterate( close() throw TypeCheckException() } - PType.Kind.ARRAY, PType.Kind.SEXP -> r.iterator() + PType.Kind.ARRAY -> r.iterator() else -> { close() throw TypeCheckException() diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt index 350cbf8db..1af0b8aaf 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt @@ -23,7 +23,7 @@ internal class RelOpIteratePermissive( isIndexable = false r.iterator() } - PType.Kind.ARRAY, PType.Kind.SEXP -> r.iterator() + PType.Kind.ARRAY -> r.iterator() else -> { isIndexable = false iterator { yield(r) } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt index 613b1d4d8..a176fad46 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt @@ -17,7 +17,7 @@ internal class RelOpScan( override fun open(env: Environment) { val r = expr.eval(env.push(Row())) records = when (r.type.kind) { - PType.Kind.ARRAY, PType.Kind.BAG, PType.Kind.SEXP -> RecordValueIterator(r.iterator()) + PType.Kind.ARRAY, PType.Kind.BAG -> RecordValueIterator(r.iterator()) else -> { close() throw TypeCheckException("Unexpected type for scan: ${r.type}") diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt index 986752c71..85d6306d6 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt @@ -16,7 +16,7 @@ internal class RelOpScanPermissive( override fun open(env: Environment) { val r = expr.eval(env.push(Row())) records = when (r.type.kind) { - PType.Kind.BAG, PType.Kind.ARRAY, PType.Kind.SEXP -> RecordValueIterator(r.iterator()) + PType.Kind.BAG, PType.Kind.ARRAY -> RecordValueIterator(r.iterator()) else -> iterator { yield(Row(arrayOf(r))) } } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/CastTable.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/CastTable.kt index b36e4bfc5..df371d16e 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/CastTable.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/CastTable.kt @@ -15,17 +15,14 @@ import org.partiql.types.PType.Kind.CHAR import org.partiql.types.PType.Kind.CLOB import org.partiql.types.PType.Kind.DATE import org.partiql.types.PType.Kind.DECIMAL -import org.partiql.types.PType.Kind.DECIMAL_ARBITRARY import org.partiql.types.PType.Kind.DOUBLE import org.partiql.types.PType.Kind.DYNAMIC import org.partiql.types.PType.Kind.INTEGER import org.partiql.types.PType.Kind.NUMERIC import org.partiql.types.PType.Kind.REAL -import org.partiql.types.PType.Kind.SEXP import org.partiql.types.PType.Kind.SMALLINT import org.partiql.types.PType.Kind.STRING import org.partiql.types.PType.Kind.STRUCT -import org.partiql.types.PType.Kind.SYMBOL import org.partiql.types.PType.Kind.TIME import org.partiql.types.PType.Kind.TIMESTAMP import org.partiql.types.PType.Kind.TIMESTAMPZ @@ -82,11 +79,11 @@ internal object CastTable { } } - private val TYPES = PType.Kind.values() + private val TYPES = PType.Kind.entries.toTypedArray() private val SIZE = TYPES.size private val TYPE_NAME_MAX_LENGTH = TYPES.maxOf { it.name.length } - private val _table: CastLookupTable = Array(PType.Kind.values().size) { - Array(PType.Kind.values().size) { + private val _table: CastLookupTable = Array(PType.Kind.entries.size) { + Array(PType.Kind.entries.size) { null } } @@ -99,15 +96,12 @@ internal object CastTable { registerBigInt() registerIntArbitrary() registerDecimal() - registerDecimalArbitrary() registerReal() registerDoublePrecision() registerStruct() registerString() - registerSymbol() registerBag() registerList() - registerSexp() registerTimestamp() registerDate() registerTime() @@ -175,17 +169,12 @@ internal object CastTable { BOOL, DECIMAL ) { x, t -> Datum.decimal(if (x.boolean) BigDecimal.ONE else BigDecimal.ZERO, t.precision, t.scale) } - register( - BOOL, - DECIMAL_ARBITRARY - ) { x, _ -> Datum.decimal(if (x.boolean) BigDecimal.ONE else BigDecimal.ZERO) } register(BOOL, REAL) { x, _ -> Datum.real(if (x.boolean) 1F else 0F) } register( BOOL, DOUBLE ) { x, _ -> Datum.doublePrecision(if (x.boolean) 1.0 else 0.0) } register(BOOL, STRING) { x, _ -> Datum.string(if (x.boolean) "true" else "false") } - register(BOOL, SYMBOL) { x, _ -> Datum.symbol(if (x.boolean) "true" else "false") } register(BOOL, VARCHAR) { x, t -> Datum.varchar(if (x.boolean) "true" else "false", t.length) } register(BOOL, CHAR) { x, t -> Datum.character(if (x.boolean) "true" else "false", t.length) } register(BOOL, CLOB) { x, t -> Datum.clob((if (x.boolean) "true" else "false").toByteArray(), t.length) } @@ -212,15 +201,9 @@ internal object CastTable { t.scale ) } - register(TINYINT, DECIMAL_ARBITRARY) { x, _ -> - Datum.decimal( - x.byte.toInt().toBigDecimal() - ) - } register(TINYINT, REAL) { x, _ -> Datum.real(x.byte.toFloat()) } register(TINYINT, DOUBLE) { x, _ -> Datum.doublePrecision(x.byte.toDouble()) } register(TINYINT, STRING) { x, _ -> Datum.string(x.byte.toString()) } - register(TINYINT, SYMBOL) { x, _ -> Datum.symbol(x.byte.toString()) } register(TINYINT, VARCHAR) { x, t -> Datum.varchar(x.byte.toString(), t.length) } register(TINYINT, CHAR) { x, t -> Datum.character(x.byte.toString(), t.length) } register(TINYINT, CLOB) { x, t -> Datum.clob(x.byte.toString().toByteArray(), t.length) } @@ -247,15 +230,9 @@ internal object CastTable { t.scale ) } - register(SMALLINT, DECIMAL_ARBITRARY) { x, _ -> - Datum.decimal( - x.short.toInt().toBigDecimal() - ) - } register(SMALLINT, REAL) { x, _ -> Datum.real(x.short.toFloat()) } register(SMALLINT, DOUBLE) { x, _ -> Datum.doublePrecision(x.short.toDouble()) } register(SMALLINT, STRING) { x, _ -> Datum.string(x.short.toString()) } - register(SMALLINT, SYMBOL) { x, _ -> Datum.symbol(x.short.toString()) } register(SMALLINT, VARCHAR) { x, t -> Datum.varchar(x.short.toString(), t.length) } register(SMALLINT, CHAR) { x, t -> Datum.character(x.short.toString(), t.length) } register(SMALLINT, CLOB) { x, t -> Datum.clob(x.short.toString().toByteArray(), t.length) } @@ -278,11 +255,9 @@ internal object CastTable { t.scale ) } - register(INTEGER, DECIMAL_ARBITRARY) { x, _ -> Datum.decimal(x.int.toBigDecimal()) } register(INTEGER, REAL) { x, _ -> Datum.real(x.int.toFloat()) } register(INTEGER, DOUBLE) { x, _ -> Datum.doublePrecision(x.int.toDouble()) } register(INTEGER, STRING) { x, _ -> Datum.string(x.int.toString()) } - register(INTEGER, SYMBOL) { x, _ -> Datum.symbol(x.int.toString()) } register(INTEGER, VARCHAR) { x, t -> Datum.varchar(x.int.toString(), t.length) } register(INTEGER, CHAR) { x, t -> Datum.character(x.int.toString(), t.length) } register(INTEGER, CLOB) { x, t -> Datum.clob(x.int.toString().toByteArray(), t.length) } @@ -305,14 +280,9 @@ internal object CastTable { t.scale ) } - register( - BIGINT, - DECIMAL_ARBITRARY - ) { x, _ -> Datum.decimal(x.long.toBigDecimal()) } register(BIGINT, REAL) { x, _ -> Datum.real(x.long.toFloat()) } register(BIGINT, DOUBLE) { x, _ -> Datum.doublePrecision(x.long.toDouble()) } register(BIGINT, STRING) { x, _ -> Datum.string(x.long.toString()) } - register(BIGINT, SYMBOL) { x, _ -> Datum.symbol(x.long.toString()) } register(BIGINT, VARCHAR) { x, t -> Datum.varchar(x.long.toString(), t.length) } register(BIGINT, CHAR) { x, t -> Datum.character(x.long.toString(), t.length) } register(BIGINT, CLOB) { x, t -> Datum.clob(x.long.toString().toByteArray(), t.length) } @@ -335,17 +305,12 @@ internal object CastTable { t.scale ) } - register( - NUMERIC, - DECIMAL_ARBITRARY - ) { x, _ -> Datum.decimal(x.bigInteger.toBigDecimal()) } register(NUMERIC, REAL) { x, _ -> datumReal(x.bigInteger) } register( NUMERIC, DOUBLE ) { x, _ -> datumDoublePrecision(x.bigInteger) } register(NUMERIC, STRING) { x, _ -> Datum.string(x.bigInteger.toString()) } - register(NUMERIC, SYMBOL) { x, _ -> Datum.symbol(x.bigInteger.toString()) } register(NUMERIC, VARCHAR) { x, t -> Datum.varchar(x.bigInteger.toString(), t.length) } register(NUMERIC, CHAR) { x, t -> Datum.character(x.bigInteger.toString(), t.length) } register(NUMERIC, CLOB) { x, t -> Datum.clob(x.bigInteger.toString().toByteArray(), t.length) } @@ -365,55 +330,17 @@ internal object CastTable { NUMERIC ) { x, _ -> datumIntArbitrary(x.bigDecimal) } register(DECIMAL, DECIMAL) { x, _ -> x } - register(DECIMAL, DECIMAL_ARBITRARY) { x, _ -> Datum.decimal(x.bigDecimal) } register(DECIMAL, REAL) { x, _ -> datumReal(x.bigDecimal) } register( DECIMAL, DOUBLE ) { x, _ -> datumDoublePrecision(x.bigDecimal) } register(DECIMAL, STRING) { x, _ -> Datum.string(x.bigDecimal.toString()) } - register(DECIMAL, SYMBOL) { x, _ -> Datum.symbol(x.bigDecimal.toString()) } register(DECIMAL, VARCHAR) { x, t -> Datum.varchar(x.bigDecimal.toString(), t.length) } register(DECIMAL, CHAR) { x, t -> Datum.character(x.bigDecimal.toString(), t.length) } register(DECIMAL, CLOB) { x, t -> Datum.clob(x.bigDecimal.toString().toByteArray(), t.length) } } - /** - * CAST( AS ) - */ - private fun registerDecimalArbitrary() { - register( - DECIMAL_ARBITRARY, - BOOL - ) { x, _ -> Datum.bool(x.bigDecimal != BigDecimal.ZERO) } - register(DECIMAL_ARBITRARY, TINYINT) { x, _ -> datumTinyInt(x.bigDecimal) } - register(DECIMAL_ARBITRARY, SMALLINT) { x, _ -> datumSmallInt(x.bigDecimal) } - register(DECIMAL_ARBITRARY, INTEGER) { x, _ -> datumInt(x.bigDecimal) } - register(DECIMAL_ARBITRARY, BIGINT) { x, _ -> datumBigInt(x.bigDecimal) } - register( - DECIMAL_ARBITRARY, - NUMERIC - ) { x, _ -> datumIntArbitrary(x.bigDecimal) } - register(DECIMAL_ARBITRARY, DECIMAL) { x, t -> - Datum.decimal( - x.bigDecimal, - t.precision, - t.scale - ) - } - register(DECIMAL_ARBITRARY, DECIMAL_ARBITRARY) { x, _ -> x } - register(DECIMAL_ARBITRARY, REAL) { x, _ -> datumReal(x.bigDecimal) } - register( - DECIMAL_ARBITRARY, - DOUBLE - ) { x, _ -> datumDoublePrecision(x.bigDecimal) } - register(DECIMAL_ARBITRARY, STRING) { x, _ -> Datum.string(x.bigDecimal.toString()) } - register(DECIMAL_ARBITRARY, SYMBOL) { x, _ -> Datum.symbol(x.bigDecimal.toString()) } - register(DECIMAL_ARBITRARY, VARCHAR) { x, t -> Datum.varchar(x.bigDecimal.toString(), t.length) } - register(DECIMAL_ARBITRARY, CHAR) { x, t -> Datum.character(x.bigDecimal.toString(), t.length) } - register(DECIMAL_ARBITRARY, CLOB) { x, t -> Datum.clob(x.bigDecimal.toString().toByteArray(), t.length) } - } - /** * CAST( AS ) */ @@ -435,14 +362,9 @@ internal object CastTable { t.scale ) } - register( - REAL, - DECIMAL_ARBITRARY - ) { x, _ -> Datum.decimal(x.float.toBigDecimal()) } register(REAL, REAL) { x, _ -> x } register(REAL, DOUBLE) { x, _ -> Datum.doublePrecision(x.float.toDouble()) } register(REAL, STRING) { x, _ -> Datum.string(x.float.toString()) } - register(REAL, SYMBOL) { x, _ -> Datum.symbol(x.float.toString()) } register(REAL, VARCHAR) { x, t -> Datum.varchar(x.float.toString(), t.length) } register(REAL, CHAR) { x, t -> Datum.character(x.float.toString(), t.length) } register(REAL, CLOB) { x, t -> Datum.clob(x.float.toString().toByteArray(), t.length) } @@ -471,14 +393,9 @@ internal object CastTable { t.scale ) } - register( - DOUBLE, - DECIMAL_ARBITRARY - ) { x, _ -> Datum.decimal(x.double.toBigDecimal()) } register(DOUBLE, REAL) { x, _ -> datumReal(x.double) } register(DOUBLE, DOUBLE) { x, _ -> x } register(DOUBLE, STRING) { x, _ -> Datum.string(x.double.toString()) } - register(DOUBLE, SYMBOL) { x, _ -> Datum.symbol(x.double.toString()) } register(DOUBLE, VARCHAR) { x, t -> Datum.varchar(x.double.toString(), t.length) } register(DOUBLE, CHAR) { x, t -> Datum.character(x.double.toString(), t.length) } register(DOUBLE, CLOB) { x, t -> Datum.clob(x.double.toString().toByteArray(), t.length) } @@ -509,59 +426,22 @@ internal object CastTable { register(STRING, BIGINT) { x, t -> cast(numberFromString(x.string), t) } register(STRING, NUMERIC) { x, t -> cast(numberFromString(x.string), t) } register(STRING, DECIMAL) { x, t -> cast(numberFromString(x.string), t) } - register(STRING, DECIMAL_ARBITRARY) { x, t -> cast(numberFromString(x.string), t) } register(STRING, REAL) { x, t -> cast(numberFromString(x.string), t) } register(STRING, DOUBLE) { x, t -> cast(numberFromString(x.string), t) } register(STRING, STRING) { x, _ -> x } - register(STRING, SYMBOL) { x, _ -> Datum.symbol(x.string) } register(STRING, VARCHAR) { x, t -> Datum.varchar(x.string, t.length) } register(STRING, CHAR) { x, t -> Datum.character(x.string, t.length) } register(STRING, CLOB) { x, t -> Datum.clob(x.string.toByteArray(), t.length) } } - /** - * CAST( AS ) - */ - private fun registerSymbol() { - register(SYMBOL, BOOL) { x, _ -> - val str = x.string.lowercase() - when (str) { - "true " -> Datum.bool(true) - "false" -> Datum.bool(false) - else -> throw TypeCheckException() - } - } - register(SYMBOL, TINYINT) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, SMALLINT) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, INTEGER) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, BIGINT) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, NUMERIC) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, DECIMAL) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, DECIMAL_ARBITRARY) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, REAL) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, DOUBLE) { x, t -> cast(numberFromString(x.string), t) } - register(SYMBOL, STRING) { x, _ -> Datum.string(x.string) } - register(SYMBOL, SYMBOL) { x, _ -> x } - register(SYMBOL, VARCHAR) { x, t -> Datum.varchar(x.string, t.length) } - register(SYMBOL, CHAR) { x, t -> Datum.character(x.string, t.length) } - register(SYMBOL, CLOB) { x, t -> Datum.clob(x.string.toByteArray(), t.length) } - } private fun registerBag() { register(BAG, BAG) { x, _ -> x } register(BAG, ARRAY) { x, _ -> Datum.array(x) } - register(BAG, SEXP) { x, _ -> Datum.sexp(x) } } private fun registerList() { register(ARRAY, BAG) { x, _ -> Datum.bag(x) } register(ARRAY, ARRAY) { x, _ -> x } - register(ARRAY, SEXP) { x, _ -> Datum.sexp(x) } - } - - private fun registerSexp() { - register(SEXP, BAG) { x, _ -> Datum.bag(x) } - register(SEXP, ARRAY) { x, _ -> Datum.array(x) } - register(SEXP, SEXP) { x, _ -> x } } /** @@ -573,7 +453,6 @@ internal object CastTable { register(TIMESTAMP, CHAR) { x, t -> Datum.character(x.timestamp.toString(), t.length) } register(TIMESTAMP, CLOB) { x, t -> Datum.clob(x.timestamp.toString().toByteArray(), t.length) } register(TIMESTAMP, STRING) { x, _ -> Datum.string(x.timestamp.toString()) } - register(TIMESTAMP, SYMBOL) { x, _ -> Datum.symbol(x.timestamp.toString()) } register(TIMESTAMP, TIMESTAMP) { x, _ -> Datum.timestamp(x.timestamp) } register(TIMESTAMP, TIMESTAMPZ) { x, _ -> Datum.timestamp(x.timestamp) } register(TIMESTAMP, TIME) { x, _ -> Datum.time(x.timestamp.toTime()) } @@ -583,7 +462,6 @@ internal object CastTable { register(TIMESTAMPZ, CHAR) { x, t -> Datum.character(x.timestamp.toString(), t.length) } register(TIMESTAMPZ, CLOB) { x, t -> Datum.clob(x.timestamp.toString().toByteArray(), t.length) } register(TIMESTAMPZ, STRING) { x, _ -> Datum.string(x.timestamp.toString()) } - register(TIMESTAMPZ, SYMBOL) { x, _ -> Datum.symbol(x.timestamp.toString()) } register(TIMESTAMPZ, TIMESTAMP) { x, _ -> Datum.timestamp(x.timestamp) } register(TIMESTAMPZ, TIMESTAMPZ) { x, _ -> Datum.timestamp(x.timestamp) } register(TIMESTAMPZ, TIME) { x, _ -> Datum.time(x.timestamp.toTime()) } @@ -594,7 +472,6 @@ internal object CastTable { register(DATE, CHAR) { x, t -> Datum.character(x.date.toString(), t.length) } register(DATE, CLOB) { x, t -> Datum.clob(x.date.toString().toByteArray(), t.length) } register(DATE, STRING) { x, _ -> Datum.string(x.date.toString()) } - register(DATE, SYMBOL) { x, _ -> Datum.symbol(x.date.toString()) } register(DATE, DATE) { x, _ -> Datum.date(x.date) } register(DATE, TIMESTAMP) { x, _ -> Datum.timestamp(DateTimeValue.timestamp(x.date, DateTimeValue.time(0, 0, 0))) } register(DATE, TIMESTAMPZ) { x, _ -> Datum.timestamp(DateTimeValue.timestamp(x.date, DateTimeValue.time(0, 0, 0))) } @@ -606,7 +483,6 @@ internal object CastTable { register(TIME, CHAR) { x, t -> Datum.character(x.time.toString(), t.length) } register(TIME, CLOB) { x, t -> Datum.clob(x.time.toString().toByteArray(), t.length) } register(TIME, STRING) { x, _ -> Datum.string(x.time.toString()) } - register(TIME, SYMBOL) { x, _ -> Datum.symbol(x.time.toString()) } register(TIME, TIME) { x, _ -> Datum.time(x.time) } register(TIME, TIMESTAMP) { x, _ -> Datum.timestamp(DateTimeValue.timestamp(DateTimeValue.date(1970, 1, 1), x.time)) } register(TIME, TIMESTAMPZ) { x, _ -> Datum.timestamp(DateTimeValue.timestamp(DateTimeValue.date(1970, 1, 1), x.time)) } @@ -616,7 +492,6 @@ internal object CastTable { register(TIMEZ, CHAR) { x, t -> Datum.character(x.time.toString(), t.length) } register(TIMEZ, CLOB) { x, t -> Datum.clob(x.time.toString().toByteArray(), t.length) } register(TIMEZ, STRING) { x, _ -> Datum.string(x.time.toString()) } - register(TIMEZ, SYMBOL) { x, _ -> Datum.symbol(x.time.toString()) } register(TIMEZ, TIME) { x, _ -> Datum.time(x.time) } register(TIMEZ, TIMESTAMP) { x, _ -> Datum.timestamp(DateTimeValue.timestamp(DateTimeValue.date(1970, 1, 1), x.time)) } register(TIMEZ, TIMESTAMPZ) { x, _ -> Datum.timestamp(DateTimeValue.timestamp(DateTimeValue.date(1970, 1, 1), x.time)) } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt index 362cff177..038f4edb0 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt @@ -8,6 +8,7 @@ import org.partiql.eval.internal.operator.rex.ExprCallDynamic.Candidate import org.partiql.eval.internal.operator.rex.ExprCallDynamic.CoercionFamily.DYNAMIC import org.partiql.eval.internal.operator.rex.ExprCallDynamic.CoercionFamily.UNKNOWN import org.partiql.spi.function.Function +import org.partiql.spi.function.Parameter import org.partiql.spi.value.Datum import org.partiql.types.PType import org.partiql.value.PartiQLValue @@ -31,7 +32,7 @@ import org.partiql.value.PartiQLValue */ internal class ExprCallDynamic( private val name: String, - private val functions: Array, + private val functions: Array, private val args: Array ) : ExprValue { @@ -48,7 +49,7 @@ internal class ExprCallDynamic( * * TODO actually make this an array instead of lists. */ - private val paramTypes: List> = functions.map { c -> c.parameters.toList() } + private val paramTypes: List> = functions.map { c -> c.getParameters().toList() } /** * @property paramFamilies is a two-dimensional array. @@ -58,7 +59,7 @@ internal class ExprCallDynamic( * * TODO actually make this an array instead of lists. */ - private val paramFamilies: List> = functions.map { c -> c.parameters.map { p -> family(p.kind) } } + private val paramFamilies: List> = functions.map { c -> c.getParameters().map { p -> family(p.getType().kind) } } /** * A memoization cache for the [match] function. @@ -92,7 +93,7 @@ internal class ExprCallDynamic( for (paramIndex in paramIndices) { val argType = args[paramIndex] val paramType = paramTypes[candidateIndex][paramIndex] - if (paramType == argType) { currentExactMatches++ } + if (paramType.getMatch(argType) == argType) { currentExactMatches++ } val argFamily = argFamilies[paramIndex] val paramFamily = paramFamilies[candidateIndex][paramIndex] if (paramFamily != argFamily && argFamily != CoercionFamily.UNKNOWN && paramFamily != CoercionFamily.DYNAMIC) { return@forEach } @@ -102,7 +103,7 @@ internal class ExprCallDynamic( exactMatches = currentExactMatches } } - return if (currentMatch == null) null else Candidate(functions[currentMatch!!]) + return if (currentMatch == null) null else Candidate(functions[currentMatch!!].getInstance(args.toTypedArray())) } /** @@ -145,7 +146,6 @@ internal class ExprCallDynamic( PType.Kind.REAL -> CoercionFamily.NUMBER PType.Kind.DOUBLE -> CoercionFamily.NUMBER PType.Kind.DECIMAL -> CoercionFamily.NUMBER - PType.Kind.DECIMAL_ARBITRARY -> CoercionFamily.NUMBER PType.Kind.STRING -> CoercionFamily.STRING PType.Kind.BOOL -> CoercionFamily.BOOLEAN PType.Kind.TIMEZ -> CoercionFamily.TIME @@ -155,13 +155,11 @@ internal class ExprCallDynamic( PType.Kind.DATE -> CoercionFamily.DATE PType.Kind.STRUCT -> CoercionFamily.STRUCTURE PType.Kind.ARRAY -> CoercionFamily.COLLECTION - PType.Kind.SEXP -> CoercionFamily.COLLECTION PType.Kind.BAG -> CoercionFamily.COLLECTION PType.Kind.ROW -> CoercionFamily.STRUCTURE PType.Kind.CHAR -> CoercionFamily.STRING PType.Kind.VARCHAR -> CoercionFamily.STRING PType.Kind.DYNAMIC -> DYNAMIC // TODO: REMOVE - PType.Kind.SYMBOL -> CoercionFamily.STRING PType.Kind.BLOB -> CoercionFamily.BINARY PType.Kind.CLOB -> CoercionFamily.STRING PType.Kind.UNKNOWN -> UNKNOWN // TODO: REMOVE diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt index 7735791c8..792f0dedb 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt @@ -16,8 +16,7 @@ internal class ExprPathIndex( val input = root.eval(env) val iterator = when (input.type.kind) { PType.Kind.BAG, - PType.Kind.ARRAY, - PType.Kind.SEXP -> input.iterator() + PType.Kind.ARRAY -> input.iterator() else -> throw TypeCheckException("expected collection, found ${input.type.kind}") } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt index a76d71383..3b9c32da9 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt @@ -32,7 +32,7 @@ internal class ExprStructPermissive(private val fields: List) : return null } return when (this.type.kind) { - PType.Kind.STRING, PType.Kind.SYMBOL, PType.Kind.CHAR -> this.string + PType.Kind.STRING, PType.Kind.CHAR -> this.string else -> null } } diff --git a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt index 7c8c19d76..bef79ef0c 100644 --- a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt +++ b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt @@ -33,7 +33,6 @@ import org.partiql.value.missingValue import org.partiql.value.nullValue import org.partiql.value.stringValue import org.partiql.value.structValue -import org.partiql.value.symbolValue import java.io.ByteArrayOutputStream import java.math.BigDecimal import kotlin.test.assertEquals @@ -124,12 +123,6 @@ class PartiQLEvaluatorTest { decimalValue(BigDecimal.valueOf(3000, 1)), ) ), - SuccessTestCase( - input = """ - CAST(20 AS SYMBOL); - """.trimIndent(), - expected = symbolValue("20"), - ), // TODO: Use Datum for assertions. Currently, PartiQLValue doesn't support parameterized CHAR/VARCHAR // SuccessTestCase( // input = """ @@ -1397,7 +1390,7 @@ class PartiQLEvaluatorTest { try { val (strictResult, _) = run(mode = Mode.STRICT()) when (strictResult.type.kind) { - PType.Kind.BAG, PType.Kind.ARRAY, PType.Kind.SEXP -> strictResult.toList() + PType.Kind.BAG, PType.Kind.ARRAY -> strictResult.toList() else -> strictResult } } catch (e: Throwable) { diff --git a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt index 4aa0f4892..387e1e936 100644 --- a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt +++ b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt @@ -8,6 +8,7 @@ import org.junit.jupiter.params.provider.MethodSource import org.partiql.eval.Environment import org.partiql.eval.internal.helpers.ValueUtility.check import org.partiql.spi.function.Function +import org.partiql.spi.function.Parameter import org.partiql.spi.value.Datum import org.partiql.spi.value.Datum.array import org.partiql.spi.value.Datum.bag @@ -62,12 +63,29 @@ class ExprCallDynamicTest { ) @OptIn(PartiQLValueExperimental::class) - internal val functions: Array = params.mapIndexed { index, it -> - object : Function.Instance( - returns = PType.integer(), - parameters = arrayOf(it.first.toPType(), it.second.toPType()) - ) { - override fun invoke(args: Array): Datum = integer(index) + internal val functions: Array = params.mapIndexed { index, it -> + object : Function { + + override fun getName(): String { + return "example" + } + + override fun getParameters(): Array { + return arrayOf(Parameter("lhs", it.first.toPType()), Parameter("rhs", it.second.toPType())) + } + + override fun getReturnType(args: Array): PType { + return PType.integer() + } + + override fun getInstance(args: Array): Function.Instance { + return object : Function.Instance( + returns = PType.integer(), + parameters = arrayOf(it.first.toPType(), it.second.toPType()) + ) { + override fun invoke(args: Array): Datum = integer(index) + } + } } }.toTypedArray() } diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt index c221c813d..da9376fe1 100644 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt +++ b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt @@ -1466,7 +1466,8 @@ internal class PartiQLParserDefault : PartiQLParser { } override fun visitSequenceConstructor(ctx: GeneratedParser.SequenceConstructorContext) = translate(ctx) { - error("Sequence constructor not supported") + val expressions = visitOrEmpty(ctx.expr()) + exprArray(expressions) } private fun PathStep.copy(next: PathStep?) = when (this) { diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt index b542bfd29..788bb2cbf 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt @@ -395,7 +395,7 @@ public interface PlanFactory { * @param args * @return */ - public fun rexCallDynamic(name: String, functions: List, args: List): RexCallDynamic = + public fun rexCallDynamic(name: String, functions: List, args: List): RexCallDynamic = RexCallDynamicImpl(name, functions, args) /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt index af9fece07..b48579012 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt @@ -16,7 +16,7 @@ public interface RexCallDynamic : Rex { /** * Returns the functions to dispatch to. */ - public fun getFunctions(): List + public fun getFunctions(): List /** * Returns the list of function arguments. @@ -33,7 +33,7 @@ public interface RexCallDynamic : Rex { */ internal class RexCallDynamicImpl( private var name: String, - private var functions: List, + private var functions: List, private var args: List, ) : RexCallDynamic { @@ -42,7 +42,7 @@ internal class RexCallDynamicImpl( override fun getName(): String = name - override fun getFunctions(): List = functions + override fun getFunctions(): List = functions override fun getArgs(): List = args diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/FnComparator.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/FnComparator.kt index 373a7fd9b..d33ca80f2 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/FnComparator.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/FnComparator.kt @@ -57,10 +57,8 @@ internal object FnComparator : Comparator { Kind.DECIMAL, Kind.REAL, Kind.DOUBLE, - Kind.DECIMAL_ARBITRARY, // Arbitrary precision decimal has a higher precedence than FLOAT Kind.CHAR, Kind.VARCHAR, - Kind.SYMBOL, Kind.STRING, Kind.CLOB, Kind.BLOB, @@ -70,7 +68,6 @@ internal object FnComparator : Comparator { Kind.TIMESTAMP, Kind.TIMESTAMPZ, Kind.ARRAY, - Kind.SEXP, Kind.BAG, Kind.ROW, Kind.STRUCT, diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/casts/CastTable.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/casts/CastTable.kt index f7ced8bf8..5db70c6de 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/casts/CastTable.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/casts/CastTable.kt @@ -78,13 +78,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.CHAR) cast(Kind.STRING) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.TINYINT.ordinal] = relationships { cast(Kind.BOOL) @@ -94,13 +92,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.VARCHAR) cast(Kind.CHAR) - cast(Kind.SYMBOL) } graph[Kind.SMALLINT.ordinal] = relationships { cast(Kind.BOOL) @@ -110,13 +106,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.CHAR) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.INTEGER.ordinal] = relationships { cast(Kind.BOOL) @@ -126,13 +120,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.CHAR) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.BIGINT.ordinal] = relationships { cast(Kind.BOOL) @@ -142,13 +134,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.CHAR) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.NUMERIC.ordinal] = relationships { cast(Kind.BOOL) @@ -158,13 +148,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.CHAR) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.DECIMAL.ordinal] = relationships { cast(Kind.BOOL) @@ -174,29 +162,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.CHAR) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) - } - graph[Kind.DECIMAL_ARBITRARY.ordinal] = relationships { - cast(Kind.BOOL) - cast(Kind.TINYINT) - cast(Kind.SMALLINT) - cast(Kind.INTEGER) - cast(Kind.BIGINT) - cast(Kind.NUMERIC) - cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) - cast(Kind.REAL) - cast(Kind.DOUBLE) - cast(Kind.STRING) - cast(Kind.CHAR) - cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.REAL.ordinal] = relationships { cast(Kind.BOOL) @@ -206,13 +176,11 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.CHAR) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.DOUBLE.ordinal] = relationships { cast(Kind.BOOL) @@ -222,45 +190,36 @@ internal class CastTable private constructor( cast(Kind.BIGINT) cast(Kind.NUMERIC) cast(Kind.DECIMAL) - cast(Kind.DECIMAL_ARBITRARY) cast(Kind.REAL) cast(Kind.DOUBLE) cast(Kind.STRING) cast(Kind.CHAR) cast(Kind.VARCHAR) - cast(Kind.SYMBOL) } graph[Kind.CHAR.ordinal] = relationships { Kind.values().filterNot { - it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.SEXP, Kind.ROW) + it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.ROW) }.forEach { cast(it) } } graph[Kind.STRING.ordinal] = relationships { Kind.values().filterNot { - it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.SEXP, Kind.ROW) + it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.ROW) }.forEach { cast(it) } } graph[Kind.VARCHAR.ordinal] = relationships { Kind.values().filterNot { - it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.SEXP, Kind.ROW) - }.forEach { - cast(it) - } - } - graph[Kind.SYMBOL.ordinal] = relationships { - Kind.values().filterNot { - it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.SEXP, Kind.ROW) + it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.ROW) }.forEach { cast(it) } } graph[Kind.CLOB.ordinal] = relationships { Kind.values().filterNot { - it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.SEXP, Kind.ROW) + it in setOf(Kind.BLOB, Kind.UNKNOWN, Kind.DYNAMIC, Kind.ARRAY, Kind.BAG, Kind.ROW) }.forEach { cast(it) } @@ -274,7 +233,6 @@ internal class CastTable private constructor( cast(Kind.STRING) cast(Kind.VARCHAR) cast(Kind.CHAR) - cast(Kind.SYMBOL) cast(Kind.CLOB) } graph[Kind.TIMEZ.ordinal] = relationships { @@ -285,7 +243,6 @@ internal class CastTable private constructor( cast(Kind.STRING) cast(Kind.VARCHAR) cast(Kind.CHAR) - cast(Kind.SYMBOL) cast(Kind.CLOB) } graph[Kind.TIME.ordinal] = relationships { @@ -296,7 +253,6 @@ internal class CastTable private constructor( cast(Kind.STRING) cast(Kind.VARCHAR) cast(Kind.CHAR) - cast(Kind.SYMBOL) cast(Kind.CLOB) } graph[Kind.TIMESTAMPZ.ordinal] = relationships { @@ -308,7 +264,6 @@ internal class CastTable private constructor( cast(Kind.STRING) cast(Kind.VARCHAR) cast(Kind.CHAR) - cast(Kind.SYMBOL) cast(Kind.CLOB) } graph[Kind.TIMESTAMP.ordinal] = relationships { @@ -320,22 +275,14 @@ internal class CastTable private constructor( cast(Kind.STRING) cast(Kind.VARCHAR) cast(Kind.CHAR) - cast(Kind.SYMBOL) cast(Kind.CLOB) } graph[Kind.BAG.ordinal] = relationships { cast(Kind.BAG) cast(Kind.ARRAY) - cast(Kind.SEXP) } graph[Kind.ARRAY.ordinal] = relationships { cast(Kind.BAG) - cast(Kind.SEXP) - cast(Kind.ARRAY) - } - graph[Kind.SEXP.ordinal] = relationships { - cast(Kind.BAG) - cast(Kind.SEXP) cast(Kind.ARRAY) } graph[Kind.STRUCT.ordinal] = relationships { diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index 66257edae..088e41eb6 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -18,6 +18,7 @@ import org.partiql.spi.errors.PErrorListener import org.partiql.spi.value.Datum import org.partiql.types.Field import org.partiql.types.PType +import org.partiql.value.DecimalValue import org.partiql.value.PartiQLValueExperimental import org.partiql.planner.internal.ir.PartiQLPlan as IPlan import org.partiql.planner.internal.ir.PlanNode as INode @@ -162,8 +163,7 @@ internal class PlanTransform(private val flags: Set) { } override fun visitRexOpCallDynamic(node: IRex.Op.Call.Dynamic, ctx: PType): Any { - // TODO add argument types and move to plan typer!! - val fns = node.candidates.map { it.fn.signature.getInstance(emptyArray()) } + val fns = node.candidates.map { it.fn.signature } val args = node.args.map { visitRex(it, ctx) } // TODO assert on function name in plan typer .. here is not the place. return factory.rexCallDynamic("unknown", fns, args) @@ -229,6 +229,15 @@ internal class PlanTransform(private val flags: Set) { @OptIn(PartiQLValueExperimental::class) override fun visitRexOpLit(node: IRex.Op.Lit, ctx: PType): Any { + val value = node.value + // TODO: PartiQLValue doesn't have a finite decimal type, so we need to specially handle this until we remove + // PartiQLValue. + if (value is DecimalValue && ctx.kind == PType.Kind.DECIMAL) { + return when (val dec = value.value) { + null -> factory.rexLit(Datum.nullValue(ctx)) + else -> factory.rexLit(Datum.decimal(dec, ctx.precision, ctx.scale)) + } + } return factory.rexLit(Datum.of(node.value)) } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt index d4f751b1a..ed96bf983 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/RexConverter.kt @@ -86,6 +86,7 @@ import org.partiql.planner.internal.typer.CompilerType import org.partiql.planner.internal.typer.PlanTyper.Companion.toCType import org.partiql.spi.catalog.Identifier import org.partiql.types.PType +import org.partiql.value.DecimalValue import org.partiql.value.MissingValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.StringValue @@ -125,13 +126,24 @@ internal object RexConverter { throw IllegalArgumentException("unsupported rex $node") override fun visitExprLit(node: ExprLit, context: Env): Rex { - val type = CompilerType( - _delegate = node.value.type.toPType(), + val type = when (val value = node.value) { + // Specifically handle the lack of an infinite precision/scale + // TODO: PartiQLValue won't be in AST soon + is DecimalValue -> { + when (val decimal = value.value) { + null -> PType.decimal() + else -> PType.decimal(decimal.precision(), decimal.scale()) + } + } + else -> value.type.toPType() + } + val cType = CompilerType( + _delegate = type, isNullValue = node.value.isNull, isMissingValue = node.value is MissingValue ) val op = rexOpLit(node.value) - return rex(type, op) + return rex(cType, op) } /** @@ -933,7 +945,6 @@ internal object RexConverter { } DataType.CLOB -> assertGtZeroAndCreate(PType.Kind.CLOB, "length", type.length ?: Int.MAX_VALUE, PType::clob) DataType.STRING -> PType.string() - DataType.SYMBOL -> PType.symbol() // // TODO BINARY_LARGE_OBJECT DataType.BLOB -> assertGtZeroAndCreate(PType.Kind.BLOB, "length", type.length ?: Int.MAX_VALUE, PType::blob) @@ -1005,7 +1016,6 @@ internal object RexConverter { // DataType.LIST -> PType.array() DataType.BAG -> PType.bag() - DataType.SEXP -> PType.sexp() // DataType.USER_DEFINED -> TODO("Custom type not supported ") else -> error("Unsupported DataType type: $type") @@ -1069,7 +1079,6 @@ internal object RexConverter { private val STRUCT: CompilerType = CompilerType(PType.struct()) private val BAG: CompilerType = CompilerType(PType.bag()) private val LIST: CompilerType = CompilerType(PType.array()) - private val SEXP: CompilerType = CompilerType(PType.sexp()) private val INT: CompilerType = CompilerType(PType.numeric()) private val INT4: CompilerType = CompilerType(PType.integer()) private val TIMESTAMP: CompilerType = CompilerType(PType.timestamp(6)) diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt index 99a226b4d..0bace18bc 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/CompilerType.kt @@ -87,7 +87,6 @@ internal class CompilerType( Kind.REAL, Kind.DOUBLE, Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY ) } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/DynamicTyper.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/DynamicTyper.kt index 1e2bc0d47..c17da6315 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/DynamicTyper.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/DynamicTyper.kt @@ -25,10 +25,8 @@ import org.partiql.value.intValue import org.partiql.value.listValue import org.partiql.value.missingValue import org.partiql.value.nullValue -import org.partiql.value.sexpValue import org.partiql.value.stringValue import org.partiql.value.structValue -import org.partiql.value.symbolValue import org.partiql.value.timeValue import org.partiql.value.timestampValue @@ -116,7 +114,7 @@ internal class DynamicTyper { return anyOf(types)!!.toCType() to null } // If a collection, then return union of all accumulated types as these coercion rules are not defined by SQL. - if (superTypeBase in setOf(Kind.ROW, Kind.STRUCT, Kind.BAG, Kind.ARRAY, Kind.SEXP)) { + if (superTypeBase in setOf(Kind.ROW, Kind.STRUCT, Kind.BAG, Kind.ARRAY)) { return anyOf(types)!!.toCType() to null } // Decimal @@ -254,7 +252,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.BIGINT, Kind.NUMERIC to Kind.NUMERIC, Kind.DECIMAL to Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY to Kind.DECIMAL_ARBITRARY, Kind.REAL to Kind.REAL, Kind.DOUBLE to Kind.DOUBLE, ) @@ -265,7 +262,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.BIGINT, Kind.NUMERIC to Kind.NUMERIC, Kind.DECIMAL to Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY to Kind.DECIMAL_ARBITRARY, Kind.REAL to Kind.REAL, Kind.DOUBLE to Kind.DOUBLE, ) @@ -276,7 +272,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.BIGINT, Kind.NUMERIC to Kind.NUMERIC, Kind.DECIMAL to Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY to Kind.DECIMAL_ARBITRARY, Kind.REAL to Kind.REAL, Kind.DOUBLE to Kind.DOUBLE, ) @@ -287,7 +282,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.BIGINT, Kind.NUMERIC to Kind.NUMERIC, Kind.DECIMAL to Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY to Kind.DECIMAL_ARBITRARY, Kind.REAL to Kind.REAL, Kind.DOUBLE to Kind.DOUBLE, ) @@ -298,7 +292,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.NUMERIC, Kind.NUMERIC to Kind.NUMERIC, Kind.DECIMAL to Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY to Kind.DECIMAL_ARBITRARY, Kind.REAL to Kind.REAL, Kind.DOUBLE to Kind.DOUBLE, ) @@ -309,18 +302,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.DECIMAL, Kind.NUMERIC to Kind.DECIMAL, Kind.DECIMAL to Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY to Kind.DECIMAL_ARBITRARY, - Kind.REAL to Kind.REAL, - Kind.DOUBLE to Kind.DOUBLE, - ) - graph[Kind.DECIMAL_ARBITRARY.ordinal] = edges( - Kind.TINYINT to Kind.DECIMAL_ARBITRARY, - Kind.SMALLINT to Kind.DECIMAL_ARBITRARY, - Kind.INTEGER to Kind.DECIMAL_ARBITRARY, - Kind.BIGINT to Kind.DECIMAL_ARBITRARY, - Kind.NUMERIC to Kind.DECIMAL_ARBITRARY, - Kind.DECIMAL to Kind.DECIMAL_ARBITRARY, - Kind.DECIMAL_ARBITRARY to Kind.DECIMAL_ARBITRARY, Kind.REAL to Kind.REAL, Kind.DOUBLE to Kind.DOUBLE, ) @@ -331,7 +312,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.REAL, Kind.NUMERIC to Kind.REAL, Kind.DECIMAL to Kind.REAL, - Kind.DECIMAL_ARBITRARY to Kind.REAL, Kind.REAL to Kind.REAL, Kind.DOUBLE to Kind.DOUBLE, ) @@ -342,7 +322,6 @@ internal class DynamicTyper { Kind.BIGINT to Kind.DOUBLE, Kind.NUMERIC to Kind.DOUBLE, Kind.DECIMAL to Kind.DOUBLE, - Kind.DECIMAL_ARBITRARY to Kind.DOUBLE, Kind.REAL to Kind.DOUBLE, Kind.DOUBLE to Kind.DOUBLE, ) @@ -350,28 +329,18 @@ internal class DynamicTyper { Kind.CHAR to Kind.CHAR, Kind.STRING to Kind.STRING, Kind.VARCHAR to Kind.STRING, - Kind.SYMBOL to Kind.STRING, Kind.CLOB to Kind.CLOB, ) graph[Kind.STRING.ordinal] = edges( Kind.CHAR to Kind.STRING, Kind.STRING to Kind.STRING, Kind.VARCHAR to Kind.STRING, - Kind.SYMBOL to Kind.STRING, Kind.CLOB to Kind.CLOB, ) graph[Kind.VARCHAR.ordinal] = edges( Kind.CHAR to Kind.VARCHAR, Kind.STRING to Kind.STRING, Kind.VARCHAR to Kind.VARCHAR, - Kind.SYMBOL to Kind.STRING, - Kind.CLOB to Kind.CLOB, - ) - graph[Kind.SYMBOL.ordinal] = edges( - Kind.CHAR to Kind.SYMBOL, - Kind.STRING to Kind.STRING, - Kind.VARCHAR to Kind.STRING, - Kind.SYMBOL to Kind.SYMBOL, Kind.CLOB to Kind.CLOB, ) graph[Kind.BLOB.ordinal] = edges( @@ -384,7 +353,6 @@ internal class DynamicTyper { Kind.CHAR to Kind.CLOB, Kind.STRING to Kind.CLOB, Kind.VARCHAR to Kind.CLOB, - Kind.SYMBOL to Kind.CLOB, Kind.CLOB to Kind.CLOB, ) graph[Kind.TIME.ordinal] = edges( @@ -401,17 +369,10 @@ internal class DynamicTyper { ) graph[Kind.ARRAY.ordinal] = edges( Kind.ARRAY to Kind.ARRAY, - Kind.SEXP to Kind.SEXP, - Kind.BAG to Kind.BAG, - ) - graph[Kind.SEXP.ordinal] = edges( - Kind.ARRAY to Kind.SEXP, - Kind.SEXP to Kind.SEXP, Kind.BAG to Kind.BAG, ) graph[Kind.BAG.ordinal] = edges( Kind.ARRAY to Kind.BAG, - Kind.SEXP to Kind.BAG, Kind.BAG to Kind.BAG, ) graph[Kind.STRUCT.ordinal] = edges( @@ -436,13 +397,11 @@ internal class DynamicTyper { Kind.BIGINT -> PType.bigint() Kind.NUMERIC -> PType.numeric() Kind.DECIMAL -> PType.decimal() // TODO: To be updated. - Kind.DECIMAL_ARBITRARY -> PType.decimal() Kind.REAL -> PType.real() Kind.DOUBLE -> PType.doublePrecision() Kind.CHAR -> PType.character(255) // TODO: To be updated Kind.VARCHAR -> PType.varchar(255) // TODO: To be updated Kind.STRING -> PType.string() - Kind.SYMBOL -> PType.symbol() Kind.BLOB -> PType.blob(Int.MAX_VALUE) // TODO: To be updated Kind.CLOB -> PType.clob(Int.MAX_VALUE) // TODO: To be updated Kind.DATE -> PType.date() @@ -453,7 +412,6 @@ internal class DynamicTyper { Kind.BAG -> PType.bag() // TODO: To be updated Kind.ARRAY -> PType.array() // TODO: To be updated Kind.ROW -> PType.row(emptyList()) // TODO: To be updated - Kind.SEXP -> PType.sexp() // TODO: To be updated Kind.STRUCT -> PType.struct() // TODO: To be updated Kind.UNKNOWN -> PType.unknown() // TODO: To be updated Kind.VARIANT -> TODO("variant in dynamic typer") @@ -470,13 +428,11 @@ internal class DynamicTyper { Kind.BIGINT -> int64Value(null) Kind.NUMERIC -> intValue(null) Kind.DECIMAL -> decimalValue(null) - Kind.DECIMAL_ARBITRARY -> decimalValue(null) Kind.REAL -> float32Value(null) Kind.DOUBLE -> float64Value(null) Kind.CHAR -> charValue(null) Kind.VARCHAR -> TODO("No implementation of VAR CHAR") Kind.STRING -> stringValue(null) - Kind.SYMBOL -> symbolValue(null) Kind.BLOB -> blobValue(null) Kind.CLOB -> clobValue(null) Kind.DATE -> dateValue(null) @@ -487,7 +443,6 @@ internal class DynamicTyper { Kind.BAG -> bagValue(null) Kind.ARRAY -> listValue(null) Kind.ROW -> structValue(null) - Kind.SEXP -> sexpValue(null) Kind.STRUCT -> structValue() Kind.UNKNOWN -> nullValue() Kind.VARIANT -> TODO("variant in dynamic typer") diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt index 5e963effa..37985062c 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt @@ -122,8 +122,7 @@ internal class PlanTyper(private val env: Env, config: Context) { // Collapse Collections if (unique.all { it.kind == Kind.ARRAY } || - unique.all { it.kind == Kind.BAG } || - unique.all { it.kind == Kind.SEXP } + unique.all { it.kind == Kind.BAG } ) { return collapseCollection(unique, unique.first().kind) } @@ -139,7 +138,6 @@ internal class PlanTyper(private val env: Env, config: Context) { return when (type) { Kind.ARRAY -> PType.array(typeParam) Kind.BAG -> PType.array(typeParam) - Kind.SEXP -> PType.array(typeParam) else -> error("This shouldn't have happened.") } } @@ -637,8 +635,8 @@ internal class PlanTyper(private val env: Env, config: Context) { return Rex(CompilerType(PType.dynamic()), Rex.Op.Path.Index(root, key)) } - // Check Root Type (LIST/SEXP) - if (root.type.kind != Kind.ARRAY && root.type.kind != Kind.SEXP) { + // Check Root Type LIST + if (root.type.kind != Kind.ARRAY) { return errorRexAndReport(_listener, PErrors.pathIndexNeverSucceeds(null)) } @@ -966,8 +964,8 @@ internal class PlanTyper(private val env: Env, config: Context) { } override fun visitRexOpCollection(node: Rex.Op.Collection, ctx: CompilerType?): Rex { - if (ctx!!.kind !in setOf(Kind.ARRAY, Kind.SEXP, Kind.BAG)) { - val problem = PErrors.typeUnexpected(null, ctx, listOf(PType.array(), PType.bag(), PType.sexp())) + if (ctx!!.kind !in setOf(Kind.ARRAY, Kind.BAG)) { + val problem = PErrors.typeUnexpected(null, ctx, listOf(PType.array(), PType.bag())) return errorRexAndReport(_listener, problem) } val values = node.values.map { visitRex(it, it.type) } @@ -978,7 +976,6 @@ internal class PlanTyper(private val env: Env, config: Context) { val type = when (ctx.kind) { Kind.BAG -> PType.bag(t) Kind.ARRAY -> PType.array(t) - Kind.SEXP -> PType.sexp(t) else -> error("This is impossible.") } return rex(CompilerType(type), rexOpCollection(values)) @@ -1284,7 +1281,7 @@ internal class PlanTyper(private val env: Env, config: Context) { private fun getElementTypeForFromSource(fromSourceType: CompilerType): CompilerType = when (fromSourceType.kind) { Kind.DYNAMIC -> CompilerType(PType.dynamic()) - Kind.BAG, Kind.ARRAY, Kind.SEXP -> fromSourceType.typeParameter + Kind.BAG, Kind.ARRAY -> fromSourceType.typeParameter // TODO: Should we emit a warning? else -> fromSourceType } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/TypeUtils.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/TypeUtils.kt index 32242eca9..53f789bf7 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/TypeUtils.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/TypeUtils.kt @@ -24,7 +24,7 @@ internal fun CompilerType.exclude(steps: List, lastStepOpti Kind.DYNAMIC -> CompilerType(PType.dynamic()) Kind.ROW -> acc.excludeStruct(step, lastStepOptional) Kind.STRUCT -> acc - Kind.ARRAY, Kind.BAG, Kind.SEXP -> acc.excludeCollection(step, lastStepOptional) + Kind.ARRAY, Kind.BAG -> acc.excludeCollection(step, lastStepOptional) else -> acc } } @@ -108,7 +108,6 @@ internal fun CompilerType.excludeCollection(step: Rel.Op.Exclude.Step, lastStepO return when (this.kind) { Kind.ARRAY -> PType.array(e).toCType() Kind.BAG -> PType.bag(e).toCType() - Kind.SEXP -> PType.sexp(e).toCType() else -> throw IllegalStateException() } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt index 6fb951db6..0e0b4ad85 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt @@ -64,13 +64,12 @@ abstract class PartiQLTyperTestBase { /** * Build a ConnectorMetadata instance from the list of types. */ - private fun buildCatalog(name: String, types: List): Catalog { + private fun buildCatalog(name: String, types: List): Catalog { val catalog = Catalog.builder().name(name) // define all bindings types.forEachIndexed { i, t -> val tableName = Name.of("t${i + 1}") - val tableSchema = fromStaticType(t) - val table = Table.empty(tableName, tableSchema) + val table = Table.empty(tableName, t) catalog.define(table) } return catalog.build() @@ -81,11 +80,29 @@ abstract class PartiQLTyperTestBase { tests: List, argsMap: Map>>, ): Stream { + return testGenPType( + testCategory, + tests, + argsMap.entries.associate { (k, v) -> + k to v.map { + it.map { staticType -> + fromStaticType(staticType) + } + }.toSet() + } + ) + } + + fun testGenPType( + testCategory: String, + tests: List, + argsMap: Map>>, + ): Stream { return tests.map { test -> val group = test.statement val children = argsMap.flatMap { (key, value) -> - value.mapIndexed { index: Int, types: List -> + value.mapIndexed { index: Int, types: List -> val testName = "${testCategory}_${key}_$index" val metadata = buildCatalog(testName, types) val displayName = "$group | $testName | $types" diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt index 274fdf36d..8bf4f4f8a 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt @@ -34,6 +34,7 @@ import org.partiql.spi.errors.PError import org.partiql.spi.errors.PErrorListener import org.partiql.types.BagType import org.partiql.types.DecimalType +import org.partiql.types.Field import org.partiql.types.ListType import org.partiql.types.NumberConstraint import org.partiql.types.PType @@ -56,7 +57,7 @@ import kotlin.test.assertTrue internal class PlanTyperTestsPorted { sealed class TestCase { - class SuccessTestCase( + class SuccessTestCase private constructor( val name: String? = null, val key: PartiQLTest.Key? = null, val query: String? = null, @@ -66,6 +67,24 @@ internal class PlanTyperTestsPorted { val warnings: PErrorListener? = null, ) : TestCase() { + constructor( + name: String? = null, + key: PartiQLTest.Key, + catalog: String = "pql", + catalogPath: List = emptyList(), + expected: PType, + warnings: PErrorListener? = null, + ) : this(name, key, null, catalog, catalogPath, expected.toCType(), warnings) + + constructor( + name: String? = null, + query: String, + catalog: String = "pql", + catalogPath: List = emptyList(), + expected: PType, + warnings: PErrorListener? = null, + ) : this(name, null, query, catalog, catalogPath, expected.toCType(), warnings) + // legacy shim! constructor( name: String? = null, @@ -85,27 +104,80 @@ internal class PlanTyperTestsPorted { } } - class ErrorTestCase( + class ErrorTestCase private constructor( val name: String, - val key: PartiQLTest.Key?, - val query: String?, + val key: PartiQLTest.Key? = null, + val query: String? = null, val catalog: String = "pql", val catalogPath: List = emptyList(), - val note: String?, - val expected: CompilerType?, - val problemHandler: ProblemHandler?, + val note: String? = null, + val expected: PType? = null, + val problemHandler: ProblemHandler? = null, ) : TestCase() { constructor( name: String, - key: PartiQLTest.Key? = null, - query: String? = null, - catalog: String = "pql", - catalogPath: List = emptyList(), - note: String? = null, - expected: StaticType? = null, - problemHandler: ProblemHandler? = null, - ) : this(name, key, query, catalog, catalogPath, note, expected?.let { fromStaticType(it).toCType() }, problemHandler) + query: String, + problemHandler: ProblemHandler + ) : this(name, key = null, query = query, problemHandler = problemHandler) + + constructor( + name: String, + query: String, + expected: PType, + problemHandler: ProblemHandler + ) : this(name, key = null, query = query, expected = expected, problemHandler = problemHandler) + + constructor( + name: String, + key: PartiQLTest.Key, + expected: PType, + problemHandler: ProblemHandler + ) : this(name, key = key, query = null, expected = expected, problemHandler = problemHandler) + + constructor( + name: String, + key: PartiQLTest.Key, + catalog: String + ) : this(name, key = key, query = null, catalog = catalog) + + constructor( + name: String, + query: String, + expected: StaticType, + problemHandler: ProblemHandler + ) : this(name, query = query, expected = fromStaticType(expected).toCType(), problemHandler = problemHandler) + + constructor( + name: String, + query: String, + expected: StaticType, + ) : this(name, query = query, expected = fromStaticType(expected).toCType()) + + constructor( + name: String, + query: String, + expected: PType, + catalog: String, + problemHandler: ProblemHandler + ) : this(name, key = null, query = query, catalog = catalog, expected = expected.toCType(), problemHandler = problemHandler) + + constructor( + name: String, + query: String, + expected: StaticType, + catalog: String, + catalogPath: List + ) : this(name, query = query, expected = fromStaticType(expected).toCType(), catalog = catalog, catalogPath = catalogPath) + + constructor( + name: String, + query: String, + expected: StaticType, + catalog: String, + catalogPath: List, + problemHandler: ProblemHandler + ) : this(name, query = query, expected = fromStaticType(expected).toCType(), catalog = catalog, catalogPath = catalogPath, problemHandler = problemHandler) override fun toString(): String = "$name : ${query ?: key}" } @@ -331,72 +403,72 @@ internal class PlanTyperTestsPorted { SuccessTestCase( name = "cast decimal", query = "CAST(1 AS DECIMAL)", - expected = StaticType.DECIMAL, + expected = PType.decimal(38, 0), ), SuccessTestCase( name = "cast decimal(1)", query = "CAST(1 AS DECIMAL(1))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(1, 0)), + expected = PType.decimal(1, 0), ), SuccessTestCase( name = "cast decimal(1,0)", query = "CAST(1 AS DECIMAL(1,0))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(1, 0)), + expected = PType.decimal(1, 0), ), SuccessTestCase( name = "cast decimal(1,1)", query = "CAST(1 AS DECIMAL(1,1))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(1, 1)), + expected = PType.decimal(1, 1), ), SuccessTestCase( name = "cast decimal(38)", query = "CAST(1 AS DECIMAL(38))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(38, 0)), + expected = PType.decimal(38, 0), ), SuccessTestCase( name = "cast decimal(38,0)", query = "CAST(1 AS DECIMAL(38,0))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(38, 0)), + expected = PType.decimal(38, 0), ), SuccessTestCase( name = "cast decimal(38,38)", query = "CAST(1 AS DECIMAL(38,38))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(38, 38)), + expected = PType.decimal(38, 38), ), SuccessTestCase( name = "cast decimal string", query = "CAST('1' AS DECIMAL)", - expected = StaticType.DECIMAL, + expected = PType.decimal(38, 0), ), SuccessTestCase( name = "cast decimal(1) string", query = "CAST('1' AS DECIMAL(1))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(1, 0)), + expected = PType.decimal(1, 0), ), SuccessTestCase( name = "cast decimal(1,0) string", query = "CAST('1' AS DECIMAL(1,0))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(1, 0)), + expected = PType.decimal(1, 0), ), SuccessTestCase( name = "cast decimal(1,1) string", query = "CAST('1' AS DECIMAL(1,1))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(1, 1)), + expected = PType.decimal(1, 1), ), SuccessTestCase( name = "cast decimal(38) string", query = "CAST('1' AS DECIMAL(38))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(38, 0)), + expected = PType.decimal(38, 0), ), SuccessTestCase( name = "cast decimal(38,0) string", query = "CAST('1' AS DECIMAL(38,0))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(38, 0)), + expected = PType.decimal(38, 0), ), SuccessTestCase( name = "cast decimal(38,38) string", query = "CAST('1' AS DECIMAL(38,38))", - expected = DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(38, 38)), + expected = PType.decimal(38, 38), ), ) @@ -715,7 +787,7 @@ internal class PlanTyperTestsPorted { name = "DECIMAL_ARBITRARY AS DECIMAL", key = key("cast-05"), catalog = "pql", - expected = StaticType.DECIMAL, + expected = PType.decimal(), ), ) @@ -867,92 +939,52 @@ internal class PlanTyperTestsPorted { SuccessTestCase( name = "CROSS JOIN", query = "SELECT * FROM <<{ 'a': 1 }>> AS t1, <<{ 'b': 2.0 }>> AS t2", - expected = BagType( - StructType( - fields = mapOf( - "a" to StaticType.INT4, - "b" to StaticType.DECIMAL, - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.integer()), + Field.of("b", PType.decimal(2, 1)), ) - ) + ), ), SuccessTestCase( name = "LEFT JOIN", query = "SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'b': 2.0 }>> AS t2 ON TRUE", - expected = BagType( - StructType( - fields = mapOf( - "a" to StaticType.INT4, - "b" to StaticType.DECIMAL, - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.integer()), + Field.of("b", PType.decimal(2, 1)) ) - ) + ), ), SuccessTestCase( name = "LEFT JOIN", query = "SELECT b, a FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'b': 2.0 }>> AS t2 ON TRUE", - expected = BagType( - StructType( - fields = listOf( - StructType.Field("b", StaticType.DECIMAL), - StructType.Field("a", StaticType.INT4), - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("b", PType.decimal(2, 1)), + Field.of("a", PType.integer()), ) - ) + ), ), SuccessTestCase( name = "LEFT JOIN", query = "SELECT t1.a, t2.a FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON t1.a = t2.a", - expected = BagType( - StructType( - fields = listOf( - StructType.Field("a", StaticType.INT4), - StructType.Field("a", StaticType.DECIMAL), - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(false), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.integer()), + Field.of("a", PType.decimal(2, 1)), ) - ) + ), ), SuccessTestCase( name = "LEFT JOIN ALL", query = "SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON t1.a = t2.a", - expected = BagType( - StructType( - fields = listOf( - StructType.Field("a", StaticType.INT4), - StructType.Field("a", StaticType.DECIMAL), - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(false), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.integer()), + Field.of("a", PType.decimal(2, 1)), ) - ) + ), ), SuccessTestCase( name = "LEFT JOIN ALL", @@ -967,37 +999,21 @@ internal class PlanTyperTestsPorted { <<{ 'a': 'hello, world' }>> AS t3 ON t3.a = 'hello' """, - expected = BagType( - StructType( - fields = listOf( - StructType.Field("a", StaticType.INT4), - StructType.Field("a", StaticType.DECIMAL), - StructType.Field("a", StaticType.STRING), - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(false), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.integer()), + Field.of("a", PType.decimal(2, 1)), + Field.of("a", PType.string()), ) - ) + ), ), ErrorTestCase( name = "LEFT JOIN Ambiguous Reference in ON", query = "SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON a = 3", - expected = BagType( - StructType( - fields = listOf( - StructType.Field("a", StaticType.INT4), - StructType.Field("a", StaticType.DECIMAL), - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(false), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.integer()), + Field.of("a", PType.decimal(2, 1)), ) ), problemHandler = assertProblemExists( @@ -2092,25 +2108,16 @@ internal class PlanTyperTestsPorted { ErrorTestCase( name = "invalid exclude root", key = key("exclude-34"), - expected = BagType( - elementType = StructType( - fields = mapOf( - "a" to BagType( - elementType = StructType( - fields = mapOf( - "b" to StaticType.INT4 - ), - contentClosed = true, - constraints = setOf(TupleConstraint.Open(false), TupleConstraint.UniqueAttrs(true)) + expected = PType.bag( + PType.row( + Field.of( + "a", + PType.bag( + PType.row( + Field.of("b", PType.integer()) ) ) ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) ) ), problemHandler = assertProblemExists( @@ -2552,23 +2559,11 @@ internal class PlanTyperTestsPorted { """, catalog = "pql", catalogPath = listOf("main"), - expected = BagType( - StructType( - fields = mapOf( - "breed_descriptor" to StaticType.unionOf( - StaticType.STRING, - StaticType.INT4, - StaticType.DECIMAL - ), - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("breed_descriptor", PType.dynamic()), ) - ) + ), ), // SuccessTestCase( @@ -2614,7 +2609,7 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-10"), catalog = "pql", - expected = StaticType.DECIMAL, + expected = PType.decimal(), ), SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-11"), @@ -2689,20 +2684,12 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-27"), catalog = "pql", - expected = unionOf( - StaticType.INT2, - StaticType.INT4, - StaticType.INT8, - StaticType.INT, - StaticType.DECIMAL, - StaticType.STRING, - StaticType.CLOB - ), + expected = PType.dynamic() ), SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-28"), catalog = "pql", - expected = unionOf(StaticType.INT2, StaticType.INT4, StaticType.INT8, StaticType.INT, StaticType.DECIMAL, StaticType.STRING, StaticType.CLOB), + expected = PType.dynamic() ), SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-29"), @@ -2778,12 +2765,12 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-43"), catalog = "pql", - expected = StaticType.DECIMAL + expected = PType.decimal(38, 5) ), SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-44"), catalog = "pql", - expected = StaticType.DECIMAL + expected = PType.decimal() ), SuccessTestCase( key = PartiQLTest.Key("basics", "case-when-45"), @@ -2877,7 +2864,7 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "nullif-16"), catalog = "pql", - expected = unionOf(StaticType.INT2, StaticType.INT4, StaticType.INT8, StaticType.INT, StaticType.DECIMAL) + expected = PType.dynamic() ), SuccessTestCase( key = PartiQLTest.Key("basics", "nullif-17"), @@ -2906,22 +2893,22 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-02"), catalog = "pql", - expected = StaticType.DECIMAL + expected = PType.decimal() ), SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-03"), catalog = "pql", - expected = StaticType.DECIMAL + expected = PType.decimal() ), SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-04"), catalog = "pql", - expected = StaticType.DECIMAL + expected = PType.decimal() ), SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-05"), catalog = "pql", - expected = StaticType.DECIMAL + expected = PType.decimal() ), SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-06"), @@ -2961,30 +2948,17 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-13"), catalog = "pql", - expected = unionOf( - StaticType.INT2, - StaticType.INT4, - StaticType.INT8, - StaticType.INT, - StaticType.DECIMAL - ) + expected = PType.dynamic() ), SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-14"), catalog = "pql", - expected = unionOf( - StaticType.INT2, - StaticType.INT4, - StaticType.INT8, - StaticType.INT, - StaticType.DECIMAL, - StaticType.STRING - ) + expected = PType.dynamic() ), SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-15"), catalog = "pql", - expected = unionOf(StaticType.INT2, StaticType.INT4, StaticType.INT8, StaticType.INT, StaticType.DECIMAL, StaticType.STRING) + expected = PType.dynamic() ), SuccessTestCase( key = PartiQLTest.Key("basics", "coalesce-16"), @@ -3148,7 +3122,7 @@ internal class PlanTyperTestsPorted { query = """ { 'aBc': 1, 'AbC': 2.0 }['AbC']; """, - expected = StaticType.DECIMAL + expected = PType.decimal(2, 1) ), // This should fail because the Spec says tuple indexing MUST use a literal string or explicit cast. ErrorTestCase( @@ -3313,22 +3287,14 @@ internal class PlanTyperTestsPorted { SuccessTestCase( name = "AGGREGATE over DECIMALS", query = "SELECT a, COUNT(*) AS c, SUM(a) AS s, MIN(b) AS m FROM << {'a': 1.0, 'b': 2.0}, {'a': 1.0, 'b': 2.0} >> GROUP BY a", - expected = BagType( - StructType( - fields = mapOf( - "a" to StaticType.DECIMAL, - "c" to StaticType.INT8, - "s" to StaticType.DECIMAL, - "m" to StaticType.DECIMAL, - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.decimal(2, 1)), + Field.of("c", PType.bigint()), + Field.of("s", PType.decimal(38, 0)), // TODO: Check this + Field.of("m", PType.decimal(38, 0)), ) - ) + ), ), SuccessTestCase( name = "AGGREGATE over nullable integers", @@ -3662,35 +3628,28 @@ internal class PlanTyperTestsPorted { { 'a': 5, 'b': NULL } >> GROUP BY a """.trimIndent(), - expected = BagType( - StructType( - fields = mapOf( - "a" to StaticType.DECIMAL, - "count_star" to StaticType.INT8, - "count_a" to StaticType.INT8, - "count_b" to StaticType.INT8, - "sum_a" to StaticType.DECIMAL, - "sum_b" to StaticType.DECIMAL, - "min_a" to StaticType.DECIMAL, - "min_b" to StaticType.DECIMAL, - "max_a" to StaticType.DECIMAL, - "max_b" to StaticType.DECIMAL, - "avg_a" to StaticType.DECIMAL, - "avg_b" to StaticType.DECIMAL, - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.decimal()), + Field.of("count_star", PType.bigint()), + Field.of("count_a", PType.bigint()), + Field.of("count_b", PType.bigint()), + Field.of("sum_a", PType.decimal()), + Field.of("sum_b", PType.decimal()), + Field.of("min_a", PType.decimal()), + Field.of("min_b", PType.decimal()), + Field.of("max_a", PType.decimal()), + Field.of("max_b", PType.decimal()), + Field.of("avg_a", PType.decimal()), + Field.of("avg_b", PType.decimal()), ) - ) + ), ) runTest(tc) } @Test + @Disabled fun developmentTest() { val tc = SuccessTestCase( name = "DEV TEST", @@ -4005,28 +3964,7 @@ internal class PlanTyperTestsPorted { name = "Pets should not be accessible #2", catalog = CATALOG_AWS, query = "SELECT * FROM pets", - expected = BagType( - unionOf( - StructType( - fields = emptyMap(), - contentClosed = false, - constraints = setOf( - TupleConstraint.Open(true), - TupleConstraint.UniqueAttrs(false), - ) - ), - StructType( - fields = listOf( - StructType.Field("_1", ANY) - ), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - ) - ), - ) - ), + expected = PType.bag(PType.dynamic()), problemHandler = assertProblemExists( PErrors.varRefNotFound(null, insensitive("pets"), emptyList()) ) @@ -4455,29 +4393,21 @@ internal class PlanTyperTestsPorted { SuccessTestCase( name = "Non-tuples", query = "SELECT a FROM << [ 1, 1.0 ] >> AS a", - expected = BagType( - StructType( - fields = mapOf("a" to ListType(StaticType.unionOf(StaticType.INT4, StaticType.DECIMAL))), - contentClosed = true, - constraints = setOf( - TupleConstraint.Open(false), - TupleConstraint.UniqueAttrs(true), - TupleConstraint.Ordered - ) + expected = PType.bag( + PType.row( + Field.of("a", PType.array()), ) - ) + ), ), SuccessTestCase( name = "Non-tuples in SELECT VALUE", query = "SELECT VALUE a FROM << [ 1, 1.0 ] >> AS a", - expected = - BagType(ListType(StaticType.unionOf(StaticType.INT4, StaticType.DECIMAL))) + expected = PType.bag(PType.array()) ), SuccessTestCase( name = "SELECT VALUE", query = "SELECT VALUE [1, 1.0] FROM <<>>", - expected = - BagType(ListType(StaticType.unionOf(StaticType.INT4, StaticType.DECIMAL))) + expected = PType.bag(PType.array()) ), SuccessTestCase( name = "Duplicate fields in struct", diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/Utils.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/Utils.kt index 3a04eb456..c9a035670 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/Utils.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/Utils.kt @@ -1,46 +1,28 @@ package org.partiql.planner.internal.typer -import org.partiql.types.NullType -import org.partiql.types.StaticType +import org.partiql.types.PType /** * In contrast to [set], this accumulates the passed-in [value] to the in-place value corresponding to [key]. * Note that this does not replace the value corresponding to [key]. The [MutableMap] is acting as a way to * accumulate values, and this helper function aids in that. */ - -internal fun MutableMap>>.accumulateSuccess( - key: StaticType, - value: List, +internal fun MutableMap>>.accumulateSuccess( + key: PType, + value: List, ) { val result = PartiQLTyperTestBase.TestResult.Success(key) this[result] = setOf(value) + (this[result] ?: emptySet()) } /** - * This internally calls [accumulateSuccess], however, this function also checks whether any of the [value] is of type - * null. If so, it makes sure that the result is also nullable. If the [value] is of type MISSING, the result will - * be MISSING. - */ -internal fun MutableMap>>.accumulateSuccessNullCall( - key: StaticType, - value: List, -) { - val actualKey = when { - value.any { it is NullType } -> key.asNullable() - else -> key - } - accumulateSuccess(actualKey, value) -} - -/** - * This runs [accumulateSuccessNullCall] over all elements of [value]. + * This runs [accumulateSuccess] over all elements of [value]. */ -internal fun MutableMap>>.accumulateSuccesses( - key: StaticType, - value: Set>, +internal fun MutableMap>>.accumulateSuccesses( + key: PType, + value: Set>, ) { value.forEach { - accumulateSuccessNullCall(key, it) + accumulateSuccess(key, it) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/NullIfTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/NullIfTest.kt index dd84ba0db..9dc82da69 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/NullIfTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/NullIfTest.kt @@ -3,9 +3,9 @@ package org.partiql.planner.internal.typer.functions import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.util.allSupportedType +import org.partiql.planner.util.allSupportedPType import org.partiql.planner.util.cartesianProduct -import org.partiql.types.StaticType +import org.partiql.types.PType import java.util.stream.Stream /** @@ -26,10 +26,10 @@ class NullIfTest : PartiQLTyperTestBase() { fun nullIf(): Stream { val tests = listOf("func-00").map { inputs.get("basics", it)!! } - val argsMap = mutableMapOf>>() + val argsMap = mutableMapOf>>() // Generate all success cases - cartesianProduct(allSupportedType, allSupportedType).forEach { args -> + cartesianProduct(allSupportedPType, allSupportedPType).forEach { args -> val expected = args[0] val result = TestResult.Success(expected) argsMap[result] = setOf(args) @@ -37,6 +37,6 @@ class NullIfTest : PartiQLTyperTestBase() { // No failure case argsMap[TestResult.Failure] = emptySet() - return super.testGen("nullIf", tests, argsMap) + return super.testGenPType("nullIf", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpArithmeticTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpArithmeticTest.kt index c9bbbea6e..ea27ba1c4 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpArithmeticTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpArithmeticTest.kt @@ -3,13 +3,13 @@ package org.partiql.planner.internal.typer.operator import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.internal.typer.accumulateSuccessNullCall +import org.partiql.planner.internal.typer.accumulateSuccess import org.partiql.planner.util.CastType -import org.partiql.planner.util.allNumberType -import org.partiql.planner.util.allSupportedType +import org.partiql.planner.util.allNumberPType +import org.partiql.planner.util.allSupportedPType import org.partiql.planner.util.cartesianProduct -import org.partiql.planner.util.castTable -import org.partiql.types.StaticType +import org.partiql.planner.util.castTablePType +import org.partiql.types.PType import java.util.stream.Stream class OpArithmeticTest : PartiQLTyperTestBase() { @@ -23,30 +23,30 @@ class OpArithmeticTest : PartiQLTyperTestBase() { "expr-41", ).map { inputs.get("basics", it)!! } - val argsMap: Map>> = buildMap { - val successArgs = allNumberType.let { cartesianProduct(it, it) } + val argsMap: Map>> = buildMap { + val successArgs = allNumberPType.let { cartesianProduct(it, it) } val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType + allSupportedPType, + allSupportedPType ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> + successArgs.forEach { args: List -> val arg0 = args.first() val arg1 = args[1] val output = when { arg0 == arg1 -> arg1 - castTable(arg1, arg0) == CastType.COERCION -> arg0 - castTable(arg0, arg1) == CastType.COERCION -> arg1 + castTablePType(arg1, arg0) == CastType.COERCION -> arg0 + castTablePType(arg0, arg1) == CastType.COERCION -> arg1 else -> error("Arguments do not conform to parameters. Args: $args") } - accumulateSuccessNullCall(output, args) + accumulateSuccess(output, args) } put(TestResult.Failure, failureArgs) } - return super.testGen("arithmetic", tests, argsMap) + return super.testGenPType("arithmetic", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpBitwiseAndTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpBitwiseAndTest.kt index 6973cf5de..a28dd9e2c 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpBitwiseAndTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpBitwiseAndTest.kt @@ -3,14 +3,14 @@ package org.partiql.planner.internal.typer.operator import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.internal.typer.accumulateSuccessNullCall +import org.partiql.planner.internal.typer.accumulateSuccess import org.partiql.planner.util.CastType -import org.partiql.planner.util.allIntType -import org.partiql.planner.util.allNumberType -import org.partiql.planner.util.allSupportedType +import org.partiql.planner.util.allIntPType +import org.partiql.planner.util.allNumberPType +import org.partiql.planner.util.allSupportedPType import org.partiql.planner.util.cartesianProduct -import org.partiql.planner.util.castTable -import org.partiql.types.StaticType +import org.partiql.planner.util.castTablePType +import org.partiql.types.PType import java.util.stream.Stream class OpBitwiseAndTest : PartiQLTyperTestBase() { @@ -21,31 +21,31 @@ class OpBitwiseAndTest : PartiQLTyperTestBase() { ).map { inputs.get("basics", it)!! } val argsMap = buildMap { - val successArgs = allNumberType.let { cartesianProduct(it, it) } + val successArgs = allNumberPType.let { cartesianProduct(it, it) } val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType + allSupportedPType, + allSupportedPType ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> + successArgs.forEach { args: List -> val arg0 = args.first() val arg1 = args[1] val output = when { - arg0 !in allIntType && arg1 !in allIntType -> StaticType.INT - arg0 in allIntType && arg1 !in allIntType -> arg0 - arg0 !in allIntType && arg1 in allIntType -> arg1 + arg0 !in allIntPType && arg1 !in allIntPType -> PType.numeric() + arg0 in allIntPType && arg1 !in allIntPType -> arg0 + arg0 !in allIntPType && arg1 in allIntPType -> arg1 arg0 == arg1 -> arg1 - castTable(arg1, arg0) == CastType.COERCION -> arg0 - castTable(arg0, arg1) == CastType.COERCION -> arg1 + castTablePType(arg1, arg0) == CastType.COERCION -> arg0 + castTablePType(arg0, arg1) == CastType.COERCION -> arg1 else -> error("Arguments do not conform to parameters. Args: $args") } - accumulateSuccessNullCall(output, args) + accumulateSuccess(output, args) } put(TestResult.Failure, failureArgs) } - return super.testGen("bitwise_and", tests, argsMap) + return super.testGenPType("bitwise_and", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpConcatTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpConcatTest.kt index 49222dac0..3caac53c1 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpConcatTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/operator/OpConcatTest.kt @@ -3,13 +3,13 @@ package org.partiql.planner.internal.typer.operator import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.internal.typer.accumulateSuccessNullCall +import org.partiql.planner.internal.typer.accumulateSuccess import org.partiql.planner.util.CastType -import org.partiql.planner.util.allSupportedType -import org.partiql.planner.util.allTextType +import org.partiql.planner.util.allCharStringPType +import org.partiql.planner.util.allSupportedPType import org.partiql.planner.util.cartesianProduct -import org.partiql.planner.util.castTable -import org.partiql.types.StaticType +import org.partiql.planner.util.castTablePType +import org.partiql.types.PType import java.util.stream.Stream class OpConcatTest : PartiQLTyperTestBase() { @@ -20,28 +20,28 @@ class OpConcatTest : PartiQLTyperTestBase() { ).map { inputs.get("basics", it)!! } val argsMap = buildMap { - val successArgs = allTextType.let { cartesianProduct(it, it) } + val successArgs = allCharStringPType.let { cartesianProduct(it, it) } val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType + allSupportedPType, + allSupportedPType ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> + successArgs.forEach { args: List -> val arg0 = args.first() val arg1 = args[1] val output = when { arg0 == arg1 -> arg1 - castTable(arg1, arg0) == CastType.COERCION -> arg0 - castTable(arg0, arg1) == CastType.COERCION -> arg1 + castTablePType(arg1, arg0) == CastType.COERCION -> arg0 + castTablePType(arg0, arg1) == CastType.COERCION -> arg1 else -> error("Arguments do not conform to parameters. Args: $args") } - accumulateSuccessNullCall(output, args) + accumulateSuccess(output, args) } put(TestResult.Failure, failureArgs) } - return super.testGen("concat", tests, argsMap) + return super.testGenPType("concat", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpBetweenTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpBetweenTest.kt index 578153335..1b9d788db 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpBetweenTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpBetweenTest.kt @@ -3,11 +3,15 @@ package org.partiql.planner.internal.typer.predicate import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.internal.typer.accumulateSuccessNullCall -import org.partiql.planner.util.allNumberType -import org.partiql.planner.util.allSupportedType +import org.partiql.planner.internal.typer.accumulateSuccess +import org.partiql.planner.util.allCharStringPType +import org.partiql.planner.util.allDatePType +import org.partiql.planner.util.allNumberPType +import org.partiql.planner.util.allSupportedPType +import org.partiql.planner.util.allTimePType +import org.partiql.planner.util.allTimeStampPType import org.partiql.planner.util.cartesianProduct -import org.partiql.types.StaticType +import org.partiql.types.PType import java.util.stream.Stream // TODO: Finalize the semantics for Between operator when operands contain MISSING @@ -22,41 +26,41 @@ class OpBetweenTest : PartiQLTyperTestBase() { val argsMap = buildMap { val successArgs = cartesianProduct( - allNumberType, - allNumberType, - allNumberType, + allNumberPType, + allNumberPType, + allNumberPType, ) + cartesianProduct( - StaticType.TEXT.allTypes + listOf(StaticType.CLOB), - StaticType.TEXT.allTypes + listOf(StaticType.CLOB), - StaticType.TEXT.allTypes + listOf(StaticType.CLOB) + allCharStringPType, + allCharStringPType, + allCharStringPType ) + cartesianProduct( - listOf(StaticType.DATE), - listOf(StaticType.DATE), - listOf(StaticType.DATE) + allDatePType, + allDatePType, + allDatePType, ) + cartesianProduct( - listOf(StaticType.TIME), - listOf(StaticType.TIME), - listOf(StaticType.TIME) + allTimePType, + allTimePType, + allTimePType, ) + cartesianProduct( - listOf(StaticType.TIMESTAMP), - listOf(StaticType.TIMESTAMP), - listOf(StaticType.TIMESTAMP) + allTimeStampPType, + allTimeStampPType, + allTimeStampPType, ) val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType, - allSupportedType + allSupportedPType, + allSupportedPType, + allSupportedPType ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> - accumulateSuccessNullCall(StaticType.BOOL, args) + successArgs.forEach { args: List -> + accumulateSuccess(PType.bool(), args) } put(TestResult.Failure, failureArgs) } - return super.testGen("between", tests, argsMap) + return super.testGenPType("between", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpComparisonTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpComparisonTest.kt index 0d19562f6..d8b0a4670 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpComparisonTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpComparisonTest.kt @@ -3,10 +3,16 @@ package org.partiql.planner.internal.typer.predicate import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.internal.typer.accumulateSuccessNullCall -import org.partiql.planner.util.allSupportedType +import org.partiql.planner.internal.typer.accumulateSuccess +import org.partiql.planner.util.allBooleanPType +import org.partiql.planner.util.allCharStringPType +import org.partiql.planner.util.allDatePType +import org.partiql.planner.util.allNumberPType +import org.partiql.planner.util.allSupportedPType +import org.partiql.planner.util.allTimePType +import org.partiql.planner.util.allTimeStampPType import org.partiql.planner.util.cartesianProduct -import org.partiql.types.StaticType +import org.partiql.types.PType import java.util.stream.Stream // TODO : Behavior when Missing is one operand needs to be finalized @@ -19,14 +25,14 @@ class OpComparisonTest : PartiQLTyperTestBase() { "expr-08", // Not Equal != "expr-09", // Not Equal <> ).map { inputs.get("basics", it)!! } - val argsMap: Map>> = buildMap { - val successArgs = cartesianProduct(allSupportedType, allSupportedType) - successArgs.forEach { args: List -> - accumulateSuccessNullCall(StaticType.BOOL, args) + val argsMap: Map>> = buildMap { + val successArgs = cartesianProduct(allSupportedPType, allSupportedPType) + successArgs.forEach { args: List -> + accumulateSuccess(PType.bool(), args) } } - return super.testGen("eq", tests, argsMap) + return super.testGenPType("eq", tests, argsMap) } @TestFactory @@ -45,38 +51,38 @@ class OpComparisonTest : PartiQLTyperTestBase() { val argsMap = buildMap { val successArgs = cartesianProduct( - StaticType.NUMERIC.allTypes, - StaticType.NUMERIC.allTypes + allNumberPType, + allNumberPType, ) + cartesianProduct( - StaticType.TEXT.allTypes + listOf(StaticType.CLOB), - StaticType.TEXT.allTypes + listOf(StaticType.CLOB) + allCharStringPType, + allCharStringPType, ) + cartesianProduct( - listOf(StaticType.BOOL), - listOf(StaticType.BOOL) + allBooleanPType, + allBooleanPType, ) + cartesianProduct( - listOf(StaticType.DATE), - listOf(StaticType.DATE) + allDatePType, + allDatePType, ) + cartesianProduct( - listOf(StaticType.TIME), - listOf(StaticType.TIME) + allTimePType, + allTimePType, ) + cartesianProduct( - listOf(StaticType.TIMESTAMP), - listOf(StaticType.TIMESTAMP) + allTimeStampPType, + allTimeStampPType, ) val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType, + allSupportedPType, + allSupportedPType, ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> - accumulateSuccessNullCall(StaticType.BOOL, args) + successArgs.forEach { args: List -> + accumulateSuccess(PType.bool(), args) } put(TestResult.Failure, failureArgs) } - return super.testGen("comparison", tests, argsMap) + return super.testGenPType("comparison", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpInTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpInTest.kt index 29f69593d..aa477b92e 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpInTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpInTest.kt @@ -3,11 +3,11 @@ package org.partiql.planner.internal.typer.predicate import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.internal.typer.accumulateSuccessNullCall -import org.partiql.planner.util.allCollectionType -import org.partiql.planner.util.allSupportedType +import org.partiql.planner.internal.typer.accumulateSuccess +import org.partiql.planner.util.allCollectionPType +import org.partiql.planner.util.allSupportedPType import org.partiql.planner.util.cartesianProduct -import org.partiql.types.StaticType +import org.partiql.types.PType import java.util.stream.Stream class OpInTest : PartiQLTyperTestBase() { @@ -20,17 +20,17 @@ class OpInTest : PartiQLTyperTestBase() { val argsMap = buildMap { val successArgs = - allSupportedType + allSupportedPType .map { t -> listOf(t) } .toSet() - successArgs.forEach { args: List -> - accumulateSuccessNullCall(StaticType.BOOL, args) + successArgs.forEach { args: List -> + accumulateSuccess(PType.bool(), args) } - put(TestResult.Failure, emptySet>()) + put(TestResult.Failure, emptySet>()) } - return super.testGen("in", tests, argsMap) + return super.testGenPType("in", tests, argsMap) } @TestFactory @@ -41,22 +41,22 @@ class OpInTest : PartiQLTyperTestBase() { val argsMap = buildMap { val successArgs = cartesianProduct( - allSupportedType, - allCollectionType + allSupportedPType, + allCollectionPType ) val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType, + allSupportedPType, + allSupportedPType, ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> - accumulateSuccessNullCall(StaticType.BOOL, args) + successArgs.forEach { args: List -> + accumulateSuccess(PType.bool(), args) } put(TestResult.Failure, failureArgs) } - return super.testGen("in", tests, argsMap) + return super.testGenPType("in", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsMissingTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsMissingTest.kt index e85d6d5c2..9112d7d0e 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsMissingTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsMissingTest.kt @@ -3,8 +3,8 @@ package org.partiql.planner.internal.typer.predicate import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.util.allSupportedType -import org.partiql.types.StaticType +import org.partiql.planner.util.allSupportedPType +import org.partiql.types.PType import java.util.stream.Stream class OpIsMissingTest : PartiQLTyperTestBase() { @@ -15,14 +15,14 @@ class OpIsMissingTest : PartiQLTyperTestBase() { ).map { inputs.get("basics", it)!! } val argsMap = buildMap { - val successArgs = allSupportedType.flatMap { t -> + val successArgs = allSupportedPType.flatMap { t -> setOf(listOf(t)) }.toSet() - put(TestResult.Success(StaticType.BOOL), successArgs) - put(TestResult.Failure, emptySet>()) + put(TestResult.Success(PType.bool()), successArgs) + put(TestResult.Failure, emptySet>()) } - return super.testGen("isMissing", tests, argsMap) + return super.testGenPType("isMissing", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsNullTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsNullTest.kt index cb806fec1..6b3eee625 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsNullTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpIsNullTest.kt @@ -3,8 +3,8 @@ package org.partiql.planner.internal.typer.predicate import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.util.allSupportedType -import org.partiql.types.StaticType +import org.partiql.planner.util.allSupportedPType +import org.partiql.types.PType import java.util.stream.Stream // TODO: Finalize the semantics for IS NULL operator when operand is MISSING. @@ -17,14 +17,14 @@ class OpIsNullTest : PartiQLTyperTestBase() { ).map { inputs.get("basics", it)!! } val argsMap = buildMap { - val successArgs = allSupportedType.flatMap { t -> + val successArgs = allSupportedPType.flatMap { t -> setOf(listOf(t)) }.toSet() - put(TestResult.Success(StaticType.BOOL), successArgs) - put(TestResult.Failure, emptySet>()) + put(TestResult.Success(PType.bool()), successArgs) + put(TestResult.Failure, emptySet>()) } - return super.testGen("isNull", tests, argsMap) + return super.testGenPType("isNull", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpLikeTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpLikeTest.kt index 1d8582d98..b0cbdb338 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpLikeTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpLikeTest.kt @@ -3,11 +3,11 @@ package org.partiql.planner.internal.typer.predicate import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase -import org.partiql.planner.internal.typer.accumulateSuccessNullCall -import org.partiql.planner.util.allSupportedType -import org.partiql.planner.util.allTextType +import org.partiql.planner.internal.typer.accumulateSuccess +import org.partiql.planner.util.allCharStringPType +import org.partiql.planner.util.allSupportedPType import org.partiql.planner.util.cartesianProduct -import org.partiql.types.StaticType +import org.partiql.types.PType import java.util.stream.Stream class OpLikeTest : PartiQLTyperTestBase() { @@ -18,22 +18,22 @@ class OpLikeTest : PartiQLTyperTestBase() { ).map { inputs.get("basics", it)!! } val argsMap = buildMap { - val successArgs = (allTextType) + val successArgs = (allCharStringPType) .let { cartesianProduct(it, it) } val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType + allSupportedPType, + allSupportedPType ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> - accumulateSuccessNullCall(StaticType.BOOL, args) + successArgs.forEach { args: List -> + accumulateSuccess(PType.bool(), args) } put(TestResult.Failure, failureArgs) } - return super.testGen("like", tests, argsMap) + return super.testGenPType("like", tests, argsMap) } @TestFactory @@ -43,22 +43,22 @@ class OpLikeTest : PartiQLTyperTestBase() { ).map { inputs.get("basics", it)!! } val argsMap = buildMap { - val successArgs = (allTextType) + val successArgs = (allCharStringPType) .let { cartesianProduct(it, it, it) } val failureArgs = cartesianProduct( - allSupportedType, - allSupportedType, - allSupportedType, + allSupportedPType, + allSupportedPType, + allSupportedPType, ).filterNot { successArgs.contains(it) }.toSet() - successArgs.forEach { args: List -> - accumulateSuccessNullCall(StaticType.BOOL, args) + successArgs.forEach { args: List -> + accumulateSuccess(PType.bool(), args) } put(TestResult.Failure, failureArgs) } - return super.testGen("like", tests, argsMap) + return super.testGenPType("like", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpTypeUnexpectedAssertionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpTypeUnexpectedAssertionTest.kt index 96eacfbe1..027a1c083 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpTypeUnexpectedAssertionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/predicate/OpTypeUnexpectedAssertionTest.kt @@ -4,28 +4,27 @@ import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.TestFactory import org.partiql.planner.internal.typer.PartiQLTyperTestBase import org.partiql.planner.internal.typer.accumulateSuccesses -import org.partiql.planner.util.allSupportedType -import org.partiql.types.SingleType -import org.partiql.types.StaticType +import org.partiql.planner.util.allSupportedPType +import org.partiql.types.PType import java.util.stream.Stream class OpTypeUnexpectedAssertionTest : PartiQLTyperTestBase() { @TestFactory fun typeAssertion(): Stream { val tests = buildList { - (12..29).forEach { + (12..27).forEach { this.add("expr-$it") } }.map { inputs.get("basics", it)!! } val argsMap = buildMap { - val successArgs = allSupportedType.flatMap { t -> + val successArgs = allSupportedPType.flatMap { t -> setOf(listOf(t)) }.toSet() - accumulateSuccesses(StaticType.BOOL, successArgs) - put(TestResult.Failure, emptySet>()) + accumulateSuccesses(PType.bool(), successArgs) + put(TestResult.Failure, emptySet>()) } - return super.testGen("type-assertion", tests, argsMap) + return super.testGenPType("type-assertion", tests, argsMap) } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/plugins/local/LocalSchema.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/plugins/local/LocalSchema.kt index fb6b02ef0..6793d5cc0 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/plugins/local/LocalSchema.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/plugins/local/LocalSchema.kt @@ -81,7 +81,7 @@ public fun StringElement.toStaticType(): StaticType = when (textValue) { "int32" -> StaticType.INT4 "int64" -> StaticType.INT8 "int" -> StaticType.INT - "decimal" -> StaticType.DECIMAL + "decimal" -> DecimalType(DecimalType.PrecisionScaleConstraint.Constrained(38, 0)) // The default decimal type. "float32" -> StaticType.FLOAT "float64" -> StaticType.FLOAT "string" -> StaticType.STRING diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/util/Utils.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/util/Utils.kt index 3e86ebedd..070d36696 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/util/Utils.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/util/Utils.kt @@ -14,6 +14,7 @@ import org.partiql.types.IntType import org.partiql.types.ListType import org.partiql.types.MissingType import org.partiql.types.NullType +import org.partiql.types.PType import org.partiql.types.SexpType import org.partiql.types.StaticType import org.partiql.types.StringType @@ -22,7 +23,7 @@ import org.partiql.types.SymbolType import org.partiql.types.TimeType import org.partiql.types.TimestampType -fun cartesianProduct(a: List, b: List, vararg lists: List): Set> = +fun cartesianProduct(a: Collection, b: Collection, vararg lists: Collection): Set> = (listOf(a, b).plus(lists)) .fold(listOf(listOf())) { acc, set -> acc.flatMap { list -> set.map { element -> list + element } } @@ -32,6 +33,55 @@ val allSupportedType = StaticType.ALL_TYPES.filterNot { it == StaticType.GRAPH || it is NullType || it is MissingType } +val allDatePType = setOf(PType.date()) + +val allTimePType = setOf( + PType.time(6), // TODO: Precision + PType.timez(6), // TODO: Precision +) + +val allTimeStampPType = setOf( + PType.timestamp(6), // TODO: Precision + PType.timestampz(6), // TODO: Precision +) + +val allDateTimePType = allDatePType + allTimePType + allTimeStampPType + +val allCharStringPType = setOf( + PType.character(256), // TODO: Length + PType.varchar(256), // TODO: Length + PType.string(), + PType.clob(Int.MAX_VALUE), // TODO: Length +) + +val allBinaryPType = setOf( + PType.blob(Int.MAX_VALUE), // TODO: Length +) + +val allStructPType = setOf( + PType.struct(), + PType.row(), // TODO +) + +val allCollectionPType = setOf( + PType.array(), + PType.bag() +) + +val allBooleanPType = setOf( + PType.bool() +) + +val allIntPType = setOf(PType.tinyint(), PType.smallint(), PType.integer(), PType.bigint(), PType.numeric()) + +val allNumberPType = allIntPType + setOf( + PType.decimal(), + PType.real(), + PType.doublePrecision(), +) + +val allSupportedPType = allNumberPType + allBooleanPType + allCharStringPType + allCollectionPType + allStructPType + allBinaryPType + allDateTimePType + val allSupportedTypeNotUnknown = allSupportedType.filterNot { it == StaticType.MISSING || it == StaticType.NULL } val allCollectionType = listOf(StaticType.LIST, StaticType.BAG, StaticType.SEXP) @@ -219,3 +269,120 @@ val castTable: ((StaticType, StaticType) -> CastType) = { from, to -> } } } + +val castTablePType: ((PType, PType) -> CastType) = { from, to -> +// val table = CastTable.partiql +// when (val result = table.get(from, to)) { +// null -> CastType.UNSAFE +// else -> when (result.safety) { +// Ref.Cast.Safety.UNSAFE -> CastType.UNSAFE +// Ref.Cast.Safety.COERCION -> CastType.COERCION +// Ref.Cast.Safety.EXPLICIT -> CastType.EXPLICIT +// } +// } + val fromKind = from.kind + when (fromKind) { + PType.Kind.DYNAMIC -> CastType.UNSAFE + PType.Kind.BLOB -> when (to.kind) { + PType.Kind.BLOB -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.BOOL -> when (to.kind) { + PType.Kind.BOOL, PType.Kind.DECIMAL, PType.Kind.REAL, PType.Kind.DOUBLE, PType.Kind.INTEGER, PType.Kind.TINYINT, PType.Kind.SMALLINT, PType.Kind.BIGINT, PType.Kind.NUMERIC -> CastType.COERCION + PType.Kind.STRING -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.CLOB -> when (to.kind) { + PType.Kind.CLOB -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.BAG -> when (to.kind) { + PType.Kind.BAG -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.ARRAY -> when (to.kind) { + PType.Kind.BAG -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.DATE -> when (to.kind) { + PType.Kind.DATE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.DECIMAL -> { + when (val toKind = to.kind) { + PType.Kind.DECIMAL -> { + val toPrecision = to.precision + val toScale = to.scale + val fromPrecision = from.precision + val fromScale = from.scale + if (fromPrecision >= toPrecision && fromScale >= toScale) { + CastType.COERCION + } else CastType.EXPLICIT + } + PType.Kind.REAL -> CastType.COERCION + PType.Kind.DOUBLE -> CastType.COERCION + PType.Kind.INTEGER -> CastType.EXPLICIT + else -> CastType.UNSAFE + } + } + PType.Kind.REAL -> when (to.kind) { + PType.Kind.REAL -> CastType.COERCION + PType.Kind.DOUBLE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.TINYINT -> when (to.kind) { + PType.Kind.TINYINT, PType.Kind.SMALLINT, PType.Kind.INTEGER, PType.Kind.BIGINT, PType.Kind.NUMERIC, PType.Kind.DECIMAL, PType.Kind.REAL, PType.Kind.DOUBLE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.SMALLINT -> when (to.kind) { + PType.Kind.SMALLINT, PType.Kind.INTEGER, PType.Kind.BIGINT, PType.Kind.NUMERIC, PType.Kind.DECIMAL, PType.Kind.REAL, PType.Kind.DOUBLE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.INTEGER -> when (to.kind) { + PType.Kind.INTEGER, PType.Kind.BIGINT, PType.Kind.NUMERIC, PType.Kind.DECIMAL, PType.Kind.REAL, PType.Kind.DOUBLE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.BIGINT -> when (to.kind) { + PType.Kind.BIGINT, PType.Kind.NUMERIC, PType.Kind.DECIMAL, PType.Kind.REAL, PType.Kind.DOUBLE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.STRING -> when (to.kind) { + PType.Kind.STRING, PType.Kind.CLOB -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.STRUCT -> when (to.kind) { + PType.Kind.STRUCT -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.TIME, PType.Kind.TIMEZ -> when (to.kind) { + PType.Kind.TIME, PType.Kind.TIMEZ -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.TIMESTAMP, PType.Kind.TIMESTAMPZ -> when (to.kind) { + PType.Kind.TIMESTAMP, PType.Kind.TIMESTAMPZ -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.NUMERIC -> when (to.kind) { + PType.Kind.NUMERIC, PType.Kind.DECIMAL, PType.Kind.REAL, PType.Kind.DOUBLE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.DOUBLE -> when (to.kind) { + PType.Kind.DOUBLE -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.CHAR -> when (to.kind) { + PType.Kind.CHAR, PType.Kind.VARCHAR, PType.Kind.STRING, PType.Kind.CLOB -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.VARCHAR -> when (to.kind) { + PType.Kind.VARCHAR, PType.Kind.STRING, PType.Kind.CLOB -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.ROW -> when (to.kind) { + PType.Kind.ROW, PType.Kind.STRUCT -> CastType.COERCION + else -> CastType.UNSAFE + } + PType.Kind.UNKNOWN -> CastType.UNSAFE + PType.Kind.VARIANT -> TODO() + } +} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/pql/t_item.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/pql/t_item.ion index f15089fcc..28d7c37a6 100644 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/pql/t_item.ion +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/pql/t_item.ion @@ -66,13 +66,6 @@ items: "any", } }, - { - name: "t_sexp", - type: { - type: "sexp", - items: "any", - } - }, // structs { name: "t_struct_a", diff --git a/partiql-planner/src/testFixtures/resources/inputs/basics/operator.sql b/partiql-planner/src/testFixtures/resources/inputs/basics/operator.sql index 45ee26ba7..fc43a7387 100644 --- a/partiql-planner/src/testFixtures/resources/inputs/basics/operator.sql +++ b/partiql-planner/src/testFixtures/resources/inputs/basics/operator.sql @@ -56,36 +56,30 @@ t1 IS FLOAT; t1 IS BOOL; --#[expr-19] -t1 IS SYMBOL; - ---#[expr-20] t1 IS DATE; ---#[expr-21] +--#[expr-20] t1 IS TIME; ---#[expr-22] +--#[expr-21] t1 IS TIMESTAMP; ---#[expr-23] +--#[expr-22] t1 IS STRING; ---#[expr-24] +--#[expr-23] t1 IS CLOB; ---#[expr-25] +--#[expr-24] t1 IS BLOB; ---#[expr-26] +--#[expr-25] t1 IS LIST; ---#[expr-27] -t1 IS SEXP; - ---#[expr-28] +--#[expr-26] t1 IS STRUCT; ---#[expr-29] +--#[expr-27] t1 IS BAG; --#[expr-30] diff --git a/partiql-spi/api/partiql-spi.api b/partiql-spi/api/partiql-spi.api index 060a880fb..410203dcb 100644 --- a/partiql-spi/api/partiql-spi.api +++ b/partiql-spi/api/partiql-spi.api @@ -508,12 +508,10 @@ public abstract interface class org/partiql/spi/value/Datum : java/lang/Iterable public static fun of (Lorg/partiql/value/PartiQLValue;)Lorg/partiql/spi/value/Datum; public fun pack (Ljava/nio/charset/Charset;)[B public static fun real (F)Lorg/partiql/spi/value/Datum; - public static fun sexp (Ljava/lang/Iterable;)Lorg/partiql/spi/value/Datum; public static fun smallint (S)Lorg/partiql/spi/value/Datum; public static fun string (Ljava/lang/String;)Lorg/partiql/spi/value/Datum; public static fun struct ()Lorg/partiql/spi/value/Datum; public static fun struct (Ljava/lang/Iterable;)Lorg/partiql/spi/value/Datum; - public static fun symbol (Ljava/lang/String;)Lorg/partiql/spi/value/Datum; public static fun time (Lorg/partiql/value/datetime/Time;)Lorg/partiql/spi/value/Datum; public static fun timestamp (Lorg/partiql/value/datetime/Timestamp;)Lorg/partiql/spi/value/Datum; public static fun tinyint (B)Lorg/partiql/spi/value/Datum; diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java b/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java index e59f16aea..e35dbdbae 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable; import org.partiql.errors.DataException; import org.partiql.types.PType; +import org.partiql.value.DecimalValue; import org.partiql.value.PartiQL; import org.partiql.value.PartiQLValue; import org.partiql.value.PartiQLValueType; @@ -295,9 +296,9 @@ default BigDecimal getBigDecimal() { } /** - * @return the elements of either bags, lists, or sexps; returns the fields' values if the type is a struct. + * @return the elements of either bags/lists; returns the fields' values if the type is a struct. * @throws UnsupportedOperationException if this operation is invoked on a value that is not of the following - * types: {@link PartiQLValueType#BAG}, {@link PartiQLValueType#LIST}, {@link PartiQLValueType#SEXP}, and + * types: {@link PartiQLValueType#BAG}, {@link PartiQLValueType#LIST}, and * {@link PartiQLValueType#STRUCT}. * @throws NullPointerException if this instance also returns true on {@link #isNull()}; callers should check that * {@link #isNull()} returns false before attempting to invoke this method. @@ -400,7 +401,6 @@ default PartiQLValue toPartiQLValue() { case NUMERIC: return this.isNull() ? PartiQL.intValue(null) : PartiQL.intValue(this.getBigInteger()); case DECIMAL: - case DECIMAL_ARBITRARY: return this.isNull() ? PartiQL.decimalValue(null) : PartiQL.decimalValue(this.getBigDecimal()); case REAL: return this.isNull() ? PartiQL.float32Value(null) : PartiQL.float32Value(this.getFloat()); @@ -410,8 +410,6 @@ default PartiQLValue toPartiQLValue() { return this.isNull() ? PartiQL.charValue(null) : PartiQL.charValue(this.getString().charAt(0)); case STRING: return this.isNull() ? PartiQL.stringValue(null) : PartiQL.stringValue(this.getString()); - case SYMBOL: - return this.isNull() ? PartiQL.symbolValue(null) : PartiQL.symbolValue(this.getString()); case BLOB: return this.isNull() ? PartiQL.blobValue(null) : PartiQL.blobValue(this.getBytes()); case CLOB: @@ -428,8 +426,6 @@ default PartiQLValue toPartiQLValue() { return this.isNull() ? PartiQL.bagValue((Iterable) null) : PartiQL.bagValue(new PQLToPartiQLIterable(this)); case ARRAY: return this.isNull() ? PartiQL.listValue((Iterable) null) : PartiQL.listValue(new PQLToPartiQLIterable(this)); - case SEXP: - return this.isNull() ? PartiQL.sexpValue((Iterable) null) : PartiQL.sexpValue(new PQLToPartiQLIterable(this)); case STRUCT: case ROW: return this.isNull() ? PartiQL.structValue((Iterable>) null) : PartiQL.structValue(new PQLToPartiQLStruct(this)); @@ -481,8 +477,7 @@ static Datum of(PartiQLValue value) { org.partiql.value.Int16Value INT16Value = (org.partiql.value.Int16Value) value; return new DatumShort(Objects.requireNonNull(INT16Value.getValue())); case SEXP: - @SuppressWarnings("unchecked") org.partiql.value.SexpValue sexpValue = (org.partiql.value.SexpValue) value; - return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(sexpValue)), PType.sexp()); + throw new IllegalStateException("SEXP is not supported."); case LIST: @SuppressWarnings("unchecked") org.partiql.value.ListValue LISTValue = (org.partiql.value.ListValue) value; return new DatumCollection(new PartiQLToPQLIterable(Objects.requireNonNull(LISTValue)), PType.array()); @@ -516,15 +511,16 @@ static Datum of(PartiQLValue value) { org.partiql.value.Float64Value FLOAT64Value = (org.partiql.value.Float64Value) value; return new DatumDouble(Objects.requireNonNull(FLOAT64Value.getValue())); case DECIMAL: + case DECIMAL_ARBITRARY: org.partiql.value.DecimalValue DECIMALValue = (org.partiql.value.DecimalValue) value; - return new DatumDecimal(Objects.requireNonNull(DECIMALValue.getValue()), PType.decimal()); + BigDecimal d = Objects.requireNonNull(DECIMALValue.getValue()); + return Datum.decimal(d, d.precision(), d.scale()); case CHAR: org.partiql.value.CharValue CHARValue = (org.partiql.value.CharValue) value; String charString = Objects.requireNonNull(CHARValue.getValue()).toString(); return new DatumChars(charString, charString.length()); case SYMBOL: - org.partiql.value.SymbolValue SYMBOLValue = (org.partiql.value.SymbolValue) value; - return new DatumString(Objects.requireNonNull(SYMBOLValue.getValue()), PType.symbol()); + throw new IllegalStateException("SYMBOL not supported."); case CLOB: org.partiql.value.ClobValue CLOBValue = (org.partiql.value.ClobValue) value; return new DatumBytes(Objects.requireNonNull(CLOBValue.getValue()), PType.clob(Integer.MAX_VALUE)); // TODO @@ -533,9 +529,6 @@ static Datum of(PartiQLValue value) { return new DatumBytes(Objects.requireNonNull(BLOBValue.getValue()), PType.blob(Integer.MAX_VALUE)); // TODO case BYTE: throw new UnsupportedOperationException(); - case DECIMAL_ARBITRARY: - org.partiql.value.DecimalValue DECIMAL_ARBITRARYValue = (org.partiql.value.DecimalValue) value; - return new DatumDecimal(Objects.requireNonNull(DECIMAL_ARBITRARYValue.getValue()), PType.decimal()); case ANY: default: throw new NotImplementedError(); @@ -613,7 +606,6 @@ static Datum doublePrecision(double value) { return new DatumDouble(value); } - @Deprecated @NotNull static Datum decimal(@NotNull BigDecimal value) { return new DatumDecimal(value, PType.decimal()); @@ -698,11 +690,6 @@ static Datum character(@NotNull String value, int length) { return new DatumString(newValue, PType.character(length)); } - @NotNull - static Datum symbol(@NotNull String value) { - return new DatumString(value, PType.symbol()); - } - @NotNull static Datum clob(@NotNull byte[] value) { return clob(value, Integer.MAX_VALUE); @@ -754,11 +741,6 @@ static Datum array(@NotNull Iterable values) { return new DatumCollection(values, PType.array()); } - @NotNull - static Datum sexp(@NotNull Iterable values) { - return new DatumCollection(values, PType.sexp()); - } - // STRUCTURAL @NotNull diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumCollection.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumCollection.java index 50d4edc58..fb2612c63 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumCollection.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumCollection.java @@ -10,8 +10,7 @@ *

* This is specifically for: * {@link PType.Kind#ARRAY}, - * {@link PType.Kind#BAG}, - * {@link PType.Kind#SEXP} + * {@link PType.Kind#BAG} */ class DatumCollection implements Datum { diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumComparator.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumComparator.java index ae515dc45..e77953bed 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumComparator.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumComparator.java @@ -148,7 +148,6 @@ private static Map initializeTypePrecedence() { precedence.put(PType.Kind.BIGINT, 1); precedence.put(PType.Kind.NUMERIC, 1); precedence.put(PType.Kind.DECIMAL, 1); - precedence.put(PType.Kind.DECIMAL_ARBITRARY, 1); precedence.put(PType.Kind.REAL, 1); precedence.put(PType.Kind.DOUBLE, 1); // Date Type @@ -163,14 +162,11 @@ private static Map initializeTypePrecedence() { precedence.put(PType.Kind.CHAR, 5); precedence.put(PType.Kind.VARCHAR, 5); precedence.put(PType.Kind.STRING, 5); - precedence.put(PType.Kind.SYMBOL, 5); // LOB Types precedence.put(PType.Kind.CLOB, 6); precedence.put(PType.Kind.BLOB, 6); // Array Type precedence.put(PType.Kind.ARRAY, 7); - // Sexp Type - precedence.put(PType.Kind.SEXP, 8); // Tuple Type precedence.put(PType.Kind.ROW, 9); precedence.put(PType.Kind.STRUCT, 9); @@ -227,7 +223,6 @@ private static DatumComparison[][] initializeComparators() { fillIntArbitraryComparator(row); break; case DECIMAL: - case DECIMAL_ARBITRARY: fillDecimalComparator(row); break; case REAL: @@ -239,7 +234,6 @@ private static DatumComparison[][] initializeComparators() { case CHAR: case VARCHAR: case STRING: - case SYMBOL: fillStringComparator(row); break; case BLOB: @@ -263,9 +257,6 @@ private static DatumComparison[][] initializeComparators() { case ARRAY: fillListComparator(row); break; - case SEXP: - fillSexpComparator(row); - break; case ROW: case STRUCT: fillStructComparator(row); @@ -288,7 +279,6 @@ private static DatumComparison[] fillTinyIntComparator(DatumComparison[] comps) comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getByte(), real.getFloat())); comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getByte(), doublePrecision.getDouble())); comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getByte()).compareTo(decimal.getBigDecimal()); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getByte()).compareTo(decimal.getBigDecimal()); return comps; } @@ -302,7 +292,6 @@ private static DatumComparison[] fillSmallIntComparator(DatumComparison[] comps) comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getShort(), real.getFloat())); comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getShort(), doublePrecision.getDouble())); comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getShort()).compareTo(decimal.getBigDecimal()); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getShort()).compareTo(decimal.getBigDecimal()); return comps; } @@ -316,7 +305,6 @@ private static DatumComparison[] fillIntComparator(DatumComparison[] comps) { comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getInt(), real.getFloat())); comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getInt(), doublePrecision.getDouble())); comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getInt()).compareTo(decimal.getBigDecimal()); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getInt()).compareTo(decimal.getBigDecimal()); return comps; } @@ -330,7 +318,6 @@ private static DatumComparison[] fillBigIntComparator(DatumComparison[] comps) { comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> Float.compare(self.getLong(), real.getFloat())); comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> Double.compare(self.getLong(), doublePrecision.getDouble())); comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getLong()).compareTo(decimal.getBigDecimal()); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> BigDecimal.valueOf(self.getLong()).compareTo(decimal.getBigDecimal()); return comps; } @@ -344,7 +331,6 @@ private static DatumComparison[] fillIntArbitraryComparator(DatumComparison[] co comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> new BigDecimal(self.getBigInteger()).compareTo(BigDecimal.valueOf(real.getFloat()))); comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> new BigDecimal(self.getBigInteger()).compareTo(BigDecimal.valueOf(doublePrecision.getDouble()))); comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> new BigDecimal(self.getBigInteger()).compareTo(decimal.getBigDecimal()); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> new BigDecimal(self.getBigInteger()).compareTo(decimal.getBigDecimal()); return comps; } @@ -362,7 +348,6 @@ private static DatumComparison[] fillRealComparator(DatumComparison[] comps) { return compareDoubles(selfFlt, otherDbl, () -> Double.compare(selfFlt, otherDbl)); }; comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> compareDoubleLhs(self.getFloat(), () -> BigDecimal.valueOf(self.getFloat()).compareTo(decimal.getBigDecimal())); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> compareDoubleLhs(self.getFloat(), () -> BigDecimal.valueOf(self.getFloat()).compareTo(decimal.getBigDecimal())); return comps; } @@ -474,7 +459,6 @@ private static DatumComparison[] fillDoubleComparator(DatumComparison[] comps) { }; comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubles(self.getDouble(), doublePrecision.getDouble(), () -> Double.compare(self.getDouble(), doublePrecision.getDouble())); comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> compareDoubleLhs(self.getDouble(), () -> BigDecimal.valueOf(self.getDouble()).compareTo(decimal.getBigDecimal())); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> compareDoubleLhs(self.getDouble(), () -> BigDecimal.valueOf(self.getDouble()).compareTo(decimal.getBigDecimal())); return comps; } @@ -488,7 +472,6 @@ private static DatumComparison[] fillDecimalComparator(DatumComparison[] comps) comps[PType.Kind.REAL.ordinal()] = (self, real, comp) -> compareDoubleRhs(real.getFloat(), () -> self.getBigDecimal().compareTo(BigDecimal.valueOf(real.getFloat()))); comps[PType.Kind.DOUBLE.ordinal()] = (self, doublePrecision, comp) -> compareDoubleRhs(doublePrecision.getDouble(), () -> self.getBigDecimal().compareTo(BigDecimal.valueOf(doublePrecision.getDouble()))); comps[PType.Kind.DECIMAL.ordinal()] = (self, decimal, comp) -> self.getBigDecimal().compareTo(decimal.getBigDecimal()); - comps[PType.Kind.DECIMAL_ARBITRARY.ordinal()] = (self, decimal, comp) -> self.getBigDecimal().compareTo(decimal.getBigDecimal()); return comps; } @@ -522,7 +505,7 @@ private static DatumComparison[] fillTimestampComparator(DatumComparison[] comps } /** - * Used for {@link PType.Kind#STRING}, {@link PType.Kind#CHAR}, {@link PType.Kind#VARCHAR}, and {@link PType.Kind#SYMBOL}. + * Used for {@link PType.Kind#STRING}, {@link PType.Kind#CHAR}, {@link PType.Kind#VARCHAR}. * @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other * {@link Datum}'s {@link PType.Kind#ordinal()}. * @return the modified array @@ -532,7 +515,6 @@ private static DatumComparison[] fillStringComparator(DatumComparison[] comps) { comps[PType.Kind.STRING.ordinal()] = (self, string, comp) -> self.getString().compareTo(string.getString()); comps[PType.Kind.CHAR.ordinal()] = (self, string, comp) -> self.getString().compareTo(string.getString()); comps[PType.Kind.VARCHAR.ordinal()] = (self, string, comp) -> self.getString().compareTo(string.getString()); - comps[PType.Kind.SYMBOL.ordinal()] = (self, string, comp) -> self.getString().compareTo(string.getString()); return comps; } @@ -546,17 +528,6 @@ private static DatumComparison[] fillListComparator(DatumComparison[] comps) { return comps; } - /** - * @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other - * {@link Datum}'s {@link PType.Kind#ordinal()}. - * @return the modified array - */ - @SuppressWarnings("deprecation") - private static DatumComparison[] fillSexpComparator(DatumComparison[] comps) { - comps[PType.Kind.SEXP.ordinal()] = (self, list, comp) -> compareOrdered(self.iterator(), list.iterator(), comp); - return comps; - } - /** * @param comps the array of {@link DatumComparison} to modify. Each {@link DatumComparison} is indexed by the other * {@link Datum}'s {@link PType.Kind#ordinal()}. diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumDecimal.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumDecimal.java index 1835207f4..01d22b4c6 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumDecimal.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumDecimal.java @@ -10,7 +10,6 @@ *

* This is specifically for: * {@link PType.Kind#DECIMAL}, - * {@link PType.Kind#DECIMAL_ARBITRARY} */ class DatumDecimal implements Datum { diff --git a/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java b/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java index bde8edfae..b6a773e1e 100644 --- a/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java +++ b/partiql-spi/src/main/java/org/partiql/spi/value/DatumNull.java @@ -86,7 +86,7 @@ public BigInteger getBigInteger() { @NotNull @Override public BigDecimal getBigDecimal() { - if (_type.getKind() == PType.Kind.DECIMAL || _type.getKind() == PType.Kind.DECIMAL_ARBITRARY) { + if (_type.getKind() == PType.Kind.DECIMAL) { throw new NullPointerException(); } else { throw new UnsupportedOperationException(); @@ -143,7 +143,7 @@ public float getFloat() { @NotNull @Override public Iterator iterator() { - if (_type.getKind() == PType.Kind.BAG || _type.getKind() == PType.Kind.ARRAY || _type.getKind() == PType.Kind.SEXP) { + if (_type.getKind() == PType.Kind.BAG || _type.getKind() == PType.Kind.ARRAY) { throw new NullPointerException(); } else { throw new UnsupportedOperationException(); @@ -163,7 +163,7 @@ public Iterator getFields() { @NotNull @Override public String getString() { - if (_type.getKind() == PType.Kind.STRING || _type.getKind() == PType.Kind.CHAR || _type.getKind() == PType.Kind.SYMBOL) { + if (_type.getKind() == PType.Kind.STRING || _type.getKind() == PType.Kind.CHAR) { throw new NullPointerException(); } else { throw new UnsupportedOperationException(); diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt index df926ab01..f3555089d 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/Builtins.kt @@ -38,13 +38,13 @@ internal object Builtins { Fn_BETWEEN__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL, Fn_BETWEEN__STRING_STRING_STRING__BOOL, Fn_BETWEEN__CLOB_CLOB_CLOB__BOOL, - Fn_BETWEEN__SYMBOL_SYMBOL_SYMBOL__BOOL, + Fn_BETWEEN__DATE_DATE_DATE__BOOL, Fn_BETWEEN__TIME_TIME_TIME__BOOL, Fn_BETWEEN__TIMESTAMP_TIMESTAMP_TIMESTAMP__BOOL, Fn_BIT_LENGTH__STRING__INT32, Fn_BIT_LENGTH__CLOB__INT32, - Fn_BIT_LENGTH__SYMBOL__INT32, + Fn_BITWISE_AND__INT8_INT8__INT8, Fn_BITWISE_AND__INT16_INT16__INT16, Fn_BITWISE_AND__INT32_INT32__INT32, @@ -52,11 +52,11 @@ internal object Builtins { Fn_BITWISE_AND__INT_INT__INT, Fn_CARDINALITY__BAG__INT32, Fn_CARDINALITY__LIST__INT32, - Fn_CARDINALITY__SEXP__INT32, + Fn_CARDINALITY__STRUCT__INT32, Fn_CHAR_LENGTH__STRING__INT, Fn_CHAR_LENGTH__CLOB__INT, - Fn_CHAR_LENGTH__SYMBOL__INT, + Fn_COLL_AGG__BAG__ANY.ANY_ALL, Fn_COLL_AGG__BAG__ANY.AVG_ALL, Fn_COLL_AGG__BAG__ANY.COUNT_ALL, @@ -73,9 +73,11 @@ internal object Builtins { Fn_COLL_AGG__BAG__ANY.MIN_DISTINCT, Fn_COLL_AGG__BAG__ANY.SOME_DISTINCT, Fn_COLL_AGG__BAG__ANY.SUM_DISTINCT, + Fn_CONCAT__CHAR_CHAR__CHAR, + Fn_CONCAT__VARCHAR_VARCHAR__VARCHAR, Fn_CONCAT__STRING_STRING__STRING, Fn_CONCAT__CLOB_CLOB__CLOB, - Fn_CONCAT__SYMBOL_SYMBOL__SYMBOL, + Fn_CURRENT_DATE____DATE, Fn_CURRENT_USER____STRING, Fn_DATE_ADD_DAY__INT32_DATE__DATE, @@ -161,7 +163,7 @@ internal object Builtins { Fn_GT__FLOAT64_FLOAT64__BOOL, Fn_GT__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL, Fn_GT__STRING_STRING__BOOL, - Fn_GT__SYMBOL_SYMBOL__BOOL, + Fn_GT__DATE_DATE__BOOL, Fn_GT__TIME_TIME__BOOL, Fn_GT__TIMESTAMP_TIMESTAMP__BOOL, @@ -175,79 +177,14 @@ internal object Builtins { Fn_GTE__FLOAT64_FLOAT64__BOOL, Fn_GTE__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL, Fn_GTE__STRING_STRING__BOOL, - Fn_GTE__SYMBOL_SYMBOL__BOOL, + Fn_GTE__DATE_DATE__BOOL, Fn_GTE__TIME_TIME__BOOL, Fn_GTE__TIMESTAMP_TIMESTAMP__BOOL, - Fn_IN_COLLECTION__BOOL_BAG__BOOL, - Fn_IN_COLLECTION__BOOL_LIST__BOOL, - Fn_IN_COLLECTION__BOOL_SEXP__BOOL, - Fn_IN_COLLECTION__INT8_BAG__BOOL, - Fn_IN_COLLECTION__INT8_LIST__BOOL, - Fn_IN_COLLECTION__INT8_SEXP__BOOL, - Fn_IN_COLLECTION__INT16_BAG__BOOL, - Fn_IN_COLLECTION__INT16_LIST__BOOL, - Fn_IN_COLLECTION__INT16_SEXP__BOOL, - Fn_IN_COLLECTION__INT32_BAG__BOOL, - Fn_IN_COLLECTION__INT32_LIST__BOOL, - Fn_IN_COLLECTION__INT32_SEXP__BOOL, - Fn_IN_COLLECTION__INT64_BAG__BOOL, - Fn_IN_COLLECTION__INT64_LIST__BOOL, - Fn_IN_COLLECTION__INT64_SEXP__BOOL, - Fn_IN_COLLECTION__INT_BAG__BOOL, - Fn_IN_COLLECTION__INT_LIST__BOOL, - Fn_IN_COLLECTION__INT_SEXP__BOOL, - Fn_IN_COLLECTION__DECIMAL_BAG__BOOL, - Fn_IN_COLLECTION__DECIMAL_LIST__BOOL, - Fn_IN_COLLECTION__DECIMAL_SEXP__BOOL, - Fn_IN_COLLECTION__FLOAT32_BAG__BOOL, - Fn_IN_COLLECTION__FLOAT32_LIST__BOOL, - Fn_IN_COLLECTION__FLOAT32_SEXP__BOOL, - Fn_IN_COLLECTION__FLOAT64_BAG__BOOL, - Fn_IN_COLLECTION__FLOAT64_LIST__BOOL, - Fn_IN_COLLECTION__FLOAT64_SEXP__BOOL, - Fn_IN_COLLECTION__DECIMAL_ARBITRARY_BAG__BOOL, - Fn_IN_COLLECTION__DECIMAL_ARBITRARY_LIST__BOOL, - Fn_IN_COLLECTION__DECIMAL_ARBITRARY_SEXP__BOOL, - Fn_IN_COLLECTION__CHAR_BAG__BOOL, - Fn_IN_COLLECTION__CHAR_LIST__BOOL, - Fn_IN_COLLECTION__CHAR_SEXP__BOOL, - Fn_IN_COLLECTION__STRING_BAG__BOOL, - Fn_IN_COLLECTION__STRING_LIST__BOOL, - Fn_IN_COLLECTION__STRING_SEXP__BOOL, - Fn_IN_COLLECTION__CLOB_BAG__BOOL, - Fn_IN_COLLECTION__CLOB_LIST__BOOL, - Fn_IN_COLLECTION__CLOB_SEXP__BOOL, - Fn_IN_COLLECTION__SYMBOL_BAG__BOOL, - Fn_IN_COLLECTION__SYMBOL_LIST__BOOL, - Fn_IN_COLLECTION__SYMBOL_SEXP__BOOL, - Fn_IN_COLLECTION__BLOB_BAG__BOOL, - Fn_IN_COLLECTION__BLOB_LIST__BOOL, - Fn_IN_COLLECTION__BLOB_SEXP__BOOL, - Fn_IN_COLLECTION__DATE_BAG__BOOL, - Fn_IN_COLLECTION__DATE_LIST__BOOL, - Fn_IN_COLLECTION__DATE_SEXP__BOOL, - Fn_IN_COLLECTION__TIME_BAG__BOOL, - Fn_IN_COLLECTION__TIME_LIST__BOOL, - Fn_IN_COLLECTION__TIME_SEXP__BOOL, - Fn_IN_COLLECTION__TIMESTAMP_BAG__BOOL, - Fn_IN_COLLECTION__TIMESTAMP_LIST__BOOL, - Fn_IN_COLLECTION__TIMESTAMP_SEXP__BOOL, - Fn_IN_COLLECTION__LIST_BAG__BOOL, - Fn_IN_COLLECTION__LIST_LIST__BOOL, - Fn_IN_COLLECTION__LIST_SEXP__BOOL, - Fn_IN_COLLECTION__SEXP_BAG__BOOL, - Fn_IN_COLLECTION__SEXP_LIST__BOOL, - Fn_IN_COLLECTION__SEXP_SEXP__BOOL, - Fn_IN_COLLECTION__BAG_BAG__BOOL, - Fn_IN_COLLECTION__BAG_LIST__BOOL, - Fn_IN_COLLECTION__BAG_SEXP__BOOL, - Fn_IN_COLLECTION__STRUCT_BAG__BOOL, - Fn_IN_COLLECTION__STRUCT_LIST__BOOL, - Fn_IN_COLLECTION__STRUCT_SEXP__BOOL, + Fn_IN_COLLECTION__ANY_BAG__BOOL, Fn_IN_COLLECTION__ANY_LIST__BOOL, - Fn_IN_COLLECTION__ANY_SEXP__BOOL, + Fn_IS_ANY__ANY__BOOL, Fn_IS_BAG__ANY__BOOL, Fn_IS_BINARY__ANY__BOOL, @@ -260,7 +197,6 @@ internal object Builtins { Fn_IS_DATE__ANY__BOOL, Fn_IS_DECIMAL__INT32_INT32_ANY__BOOL, Fn_IS_DECIMAL__ANY__BOOL, - Fn_IS_DECIMAL_ARBITRARY__ANY__BOOL, Fn_IS_FLOAT32__ANY__BOOL, Fn_IS_FLOAT64__ANY__BOOL, Fn_IS_INT__ANY__BOOL, @@ -272,24 +208,24 @@ internal object Builtins { Fn_IS_LIST__ANY__BOOL, Fn_IS_MISSING__ANY__BOOL, Fn_IS_NULL__ANY__BOOL, - Fn_IS_SEXP__ANY__BOOL, + Fn_IS_STRING__INT32_ANY__BOOL, Fn_IS_STRING__ANY__BOOL, Fn_IS_STRUCT__ANY__BOOL, - Fn_IS_SYMBOL__ANY__BOOL, + Fn_IS_TIME__BOOL_INT32_ANY__BOOL, Fn_IS_TIME__ANY__BOOL, Fn_IS_TIMESTAMP__BOOL_INT32_ANY__BOOL, Fn_IS_TIMESTAMP__ANY__BOOL, Fn_LIKE__STRING_STRING__BOOL, Fn_LIKE__CLOB_CLOB__BOOL, - Fn_LIKE__SYMBOL_SYMBOL__BOOL, + Fn_LIKE_ESCAPE__STRING_STRING_STRING__BOOL, Fn_LIKE_ESCAPE__CLOB_CLOB_CLOB__BOOL, - Fn_LIKE_ESCAPE__SYMBOL_SYMBOL_SYMBOL__BOOL, + Fn_LOWER__STRING__STRING, Fn_LOWER__CLOB__CLOB, - Fn_LOWER__SYMBOL__SYMBOL, + Fn_LT__BOOL_BOOL__BOOL, Fn_LT__INT8_INT8__BOOL, Fn_LT__INT16_INT16__BOOL, @@ -300,7 +236,7 @@ internal object Builtins { Fn_LT__FLOAT64_FLOAT64__BOOL, Fn_LT__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL, Fn_LT__STRING_STRING__BOOL, - Fn_LT__SYMBOL_SYMBOL__BOOL, + Fn_LT__DATE_DATE__BOOL, Fn_LT__TIME_TIME__BOOL, Fn_LT__TIMESTAMP_TIMESTAMP__BOOL, @@ -314,7 +250,7 @@ internal object Builtins { Fn_LTE__FLOAT64_FLOAT64__BOOL, Fn_LTE__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL, Fn_LTE__STRING_STRING__BOOL, - Fn_LTE__SYMBOL_SYMBOL__BOOL, + Fn_LTE__DATE_DATE__BOOL, Fn_LTE__TIME_TIME__BOOL, Fn_LTE__TIMESTAMP_TIMESTAMP__BOOL, @@ -346,7 +282,7 @@ internal object Builtins { Fn_OR__BOOL_BOOL__BOOL, Fn_OCTET_LENGTH__STRING__INT32, Fn_OCTET_LENGTH__CLOB__INT32, - Fn_OCTET_LENGTH__SYMBOL__INT32, + Fn_PLUS__INT8_INT8__INT8, Fn_PLUS__INT16_INT16__INT16, Fn_PLUS__INT32_INT32__INT32, @@ -365,13 +301,12 @@ internal object Builtins { Fn_POS__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY, Fn_POSITION__STRING_STRING__INT64, Fn_POSITION__CLOB_CLOB__INT64, - Fn_POSITION__SYMBOL_SYMBOL__INT64, + Fn_SUBSTRING__STRING_INT32__STRING, Fn_SUBSTRING__STRING_INT32_INT32__STRING, Fn_SUBSTRING__CLOB_INT64__CLOB, Fn_SUBSTRING__CLOB_INT64_INT64__CLOB, - Fn_SUBSTRING__SYMBOL_INT64__SYMBOL, - Fn_SUBSTRING__SYMBOL_INT32_INT32__SYMBOL, + Fn_TIMES__INT8_INT8__INT8, Fn_TIMES__INT16_INT16__INT16, Fn_TIMES__INT32_INT32__INT32, @@ -382,36 +317,36 @@ internal object Builtins { Fn_TIMES__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRARY, Fn_TRIM__STRING__STRING, Fn_TRIM__CLOB__CLOB, - Fn_TRIM__SYMBOL__SYMBOL, + Fn_TRIM_CHARS__STRING_STRING__STRING, Fn_TRIM_CHARS__CLOB_CLOB__CLOB, - Fn_TRIM_CHARS__SYMBOL_SYMBOL__SYMBOL, + Fn_TRIM_LEADING__STRING__STRING, Fn_TRIM_LEADING__CLOB__CLOB, - Fn_TRIM_LEADING__SYMBOL__SYMBOL, + Fn_TRIM_LEADING_CHARS__STRING_STRING__STRING, Fn_TRIM_LEADING_CHARS__CLOB_CLOB__CLOB, - Fn_TRIM_LEADING_CHARS__SYMBOL_SYMBOL__SYMBOL, + Fn_TRIM_TRAILING__STRING__STRING, Fn_TRIM_TRAILING__CLOB__CLOB, - Fn_TRIM_TRAILING__SYMBOL__SYMBOL, + Fn_TRIM_TRAILING_CHARS__STRING_STRING__STRING, Fn_TRIM_TRAILING_CHARS__CLOB_CLOB__CLOB, - Fn_TRIM_TRAILING_CHARS__SYMBOL_SYMBOL__SYMBOL, + Fn_UPPER__STRING__STRING, Fn_UPPER__CLOB__CLOB, - Fn_UPPER__SYMBOL__SYMBOL, + Fn_UTCNOW____TIMESTAMP, // // NON SQL FUNCTIONS // Fn_EXISTS__BAG__BOOL, Fn_EXISTS__LIST__BOOL, - Fn_EXISTS__SEXP__BOOL, + Fn_EXISTS__STRUCT__BOOL, Fn_SIZE__BAG__INT32, Fn_SIZE__LIST__INT32, - Fn_SIZE__SEXP__INT32, + Fn_SIZE__STRUCT__INT32 ).groupBy { it.getName() } diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt index 76fb52e3e..7b5ffe259 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBetween.kt @@ -98,9 +98,9 @@ internal val Fn_BETWEEN__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__ name = "between", returns = PType.bool(), parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("value", PType.decimal()), - @Suppress("DEPRECATION") Parameter("lower", PType.decimal()), - @Suppress("DEPRECATION") Parameter("upper", PType.decimal()), + Parameter("value", PType.decimal()), + Parameter("lower", PType.decimal()), + Parameter("upper", PType.decimal()), ), ) { args -> @@ -161,23 +161,6 @@ internal val Fn_BETWEEN__STRING_STRING_STRING__BOOL = Function.static( Datum.bool(value in lower..upper) } -internal val Fn_BETWEEN__SYMBOL_SYMBOL_SYMBOL__BOOL = Function.static( - - name = "between", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("lower", PType.symbol()), - Parameter("upper", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val lower = args[1].string - val upper = args[2].string - Datum.bool(value in lower..upper) -} - internal val Fn_BETWEEN__CLOB_CLOB_CLOB__BOOL = Function.static( name = "between", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitLength.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitLength.kt index 4574d79f8..ba477cdbf 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitLength.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitLength.kt @@ -20,20 +20,6 @@ internal val Fn_BIT_LENGTH__STRING__INT32 = Function.static( Datum.integer(length * 8) } -internal val Fn_BIT_LENGTH__SYMBOL__INT32 = Function.static( - - name = "bit_length", - returns = PType.integer(), - parameters = arrayOf( - Parameter("lhs", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val length = value.toByteArray(Charsets.UTF_8).size - Datum.integer(length * 8) -} - internal val Fn_BIT_LENGTH__CLOB__INT32 = Function.static( name = "bit_length", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCardinality.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCardinality.kt index 282471c7f..8a37a7ea1 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCardinality.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCardinality.kt @@ -31,19 +31,6 @@ internal val Fn_CARDINALITY__LIST__INT32 = Function.static( Datum.integer(container.count()) } -internal val Fn_CARDINALITY__SEXP__INT32 = Function.static( - - name = "cardinality", - returns = PType.integer(), - parameters = arrayOf( - Parameter("container", PType.sexp()), - ), - -) { args -> - val container = args[0] - Datum.integer(container.count()) -} - internal val Fn_CARDINALITY__STRUCT__INT32 = Function.static( name = "cardinality", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCharLength.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCharLength.kt index 4f0e3c238..ebb7b550c 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCharLength.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnCharLength.kt @@ -21,19 +21,6 @@ internal val Fn_CHAR_LENGTH__STRING__INT = Function.static( Datum.integer(value.codePointCount(0, value.length)) } -internal val Fn_CHAR_LENGTH__SYMBOL__INT = Function.static( - - name = "char_length", - returns = PType.integer(), - parameters = arrayOf( - Parameter("lhs", PType.symbol()), - ), - -) { args -> - val value = args[0].string - Datum.integer(value.codePointCount(0, value.length)) -} - internal val Fn_CHAR_LENGTH__CLOB__INT = Function.static( name = "char_length", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt index 60b1575d8..d8e90d651 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt @@ -8,34 +8,45 @@ import org.partiql.spi.function.Parameter import org.partiql.spi.value.Datum import org.partiql.types.PType -internal val Fn_CONCAT__STRING_STRING__STRING = Function.static( - +internal val Fn_CONCAT__CHAR_CHAR__CHAR = Function.static( name = "concat", - returns = PType.string(), + returns = PType.character(256), // TODO: Handle length parameters = arrayOf( - Parameter("lhs", PType.string()), - Parameter("rhs", PType.string()), + Parameter("lhs", PType.character(256)), // TODO: Handle length + Parameter("rhs", PType.character(256)), // TODO: Handle length ), +) { args -> + val arg0 = args[0].string + val arg1 = args[1].string + Datum.character(arg0 + arg1, 256) +} +internal val Fn_CONCAT__VARCHAR_VARCHAR__VARCHAR = Function.static( + name = "concat", + returns = PType.varchar(256), // TODO: Handle length + parameters = arrayOf( + Parameter("lhs", PType.varchar(256)), // TODO: Handle length + Parameter("rhs", PType.varchar(256)), // TODO: Handle length + ), ) { args -> val arg0 = args[0].string val arg1 = args[1].string - Datum.string(arg0 + arg1) + Datum.varchar(arg0 + arg1, 256) } -internal val Fn_CONCAT__SYMBOL_SYMBOL__SYMBOL = Function.static( +internal val Fn_CONCAT__STRING_STRING__STRING = Function.static( name = "concat", - returns = PType.symbol(), + returns = PType.string(), parameters = arrayOf( - Parameter("lhs", PType.symbol()), - Parameter("rhs", PType.symbol()), + Parameter("lhs", PType.string()), + Parameter("rhs", PType.string()), ), ) { args -> val arg0 = args[0].string val arg1 = args[1].string - Datum.symbol(arg0 + arg1) + Datum.string(arg0 + arg1) } internal val Fn_CONCAT__CLOB_CLOB__CLOB = Function.static( diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExists.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExists.kt index 6c6b03d89..09c2b06f8 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExists.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnExists.kt @@ -33,20 +33,6 @@ internal val Fn_EXISTS__LIST__BOOL = Function.static( Datum.bool(exists) } -internal val Fn_EXISTS__SEXP__BOOL = Function.static( - - name = "exists", - returns = PType.bool(), - parameters = arrayOf( - Parameter("container", PType.sexp()), - ), - -) { args -> - val container = args[0] - val exists = container.iterator().hasNext() - Datum.bool(exists) -} - internal val Fn_EXISTS__STRUCT__BOOL = Function.static( name = "exists", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt index 8db757068..2347106ce 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGt.kt @@ -88,8 +88,8 @@ internal val Fn_GT__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL = Function.static( name = "gt", returns = PType.bool(), parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("lhs", PType.decimal()), - @Suppress("DEPRECATION") Parameter("rhs", PType.decimal()), + Parameter("lhs", PType.decimal()), + Parameter("rhs", PType.decimal()), ), ) { args -> @@ -143,21 +143,6 @@ internal val Fn_GT__STRING_STRING__BOOL = Function.static( Datum.bool(lhs.string > rhs.string) } -internal val Fn_GT__SYMBOL_SYMBOL__BOOL = Function.static( - - name = "gt", - returns = PType.bool(), - parameters = arrayOf( - Parameter("lhs", PType.symbol()), - Parameter("rhs", PType.symbol()), - ), - -) { args -> - val lhs = args[0] - val rhs = args[1] - Datum.bool(lhs.string > rhs.string) -} - internal val Fn_GT__DATE_DATE__BOOL = Function.static( name = "gt", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt index 8adf314a5..b93ef52df 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnGte.kt @@ -88,8 +88,8 @@ internal val Fn_GTE__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL = Function.static name = "gte", returns = PType.bool(), parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("lhs", PType.decimal()), - @Suppress("DEPRECATION") Parameter("rhs", PType.decimal()), + Parameter("lhs", PType.decimal()), + Parameter("rhs", PType.decimal()), ), ) { args -> @@ -143,21 +143,6 @@ internal val Fn_GTE__STRING_STRING__BOOL = Function.static( Datum.bool(lhs >= rhs) } -internal val Fn_GTE__SYMBOL_SYMBOL__BOOL = Function.static( - - name = "gte", - returns = PType.bool(), - parameters = arrayOf( - Parameter("lhs", PType.symbol()), - Parameter("rhs", PType.symbol()), - ), - -) { args -> - val lhs = args[0].string - val rhs = args[1].string - Datum.bool(lhs >= rhs) -} - internal val Fn_GTE__DATE_DATE__BOOL = Function.static( name = "gte", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt index 46a9e86ff..d888dbf42 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnInCollection.kt @@ -51,1477 +51,3 @@ internal val Fn_IN_COLLECTION__ANY_LIST__BOOL = Function.static( } Datum.bool(false) } - -internal val Fn_IN_COLLECTION__ANY_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.dynamic()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BOOL_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bool()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BOOL_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bool()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BOOL_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bool()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT8_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.tinyint()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT8_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.tinyint()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT8_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.tinyint()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT16_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.smallint()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT16_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.smallint()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT16_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.smallint()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT32_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.integer()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT32_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.integer()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT32_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.integer()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT64_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bigint()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT64_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bigint()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT64_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bigint()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("value", PType.numeric()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("value", PType.numeric()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__INT_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("value", PType.numeric()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DECIMAL_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.decimal()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DECIMAL_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.decimal()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DECIMAL_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.decimal()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DECIMAL_ARBITRARY_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("value", PType.decimal()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DECIMAL_ARBITRARY_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("value", PType.decimal()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DECIMAL_ARBITRARY_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("value", PType.decimal()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__FLOAT32_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.real()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__FLOAT32_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.real()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__FLOAT32_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.real()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__FLOAT64_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.doublePrecision()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__FLOAT64_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.doublePrecision()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__FLOAT64_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.doublePrecision()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__CHAR_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.character(255)), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__CHAR_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.character(255)), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__CHAR_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.character(255)), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__STRING_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.string()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__STRING_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.string()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__STRING_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.string()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__SYMBOL_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__SYMBOL_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__SYMBOL_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BLOB_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.blob(Int.MAX_VALUE)), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BLOB_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.blob(Int.MAX_VALUE)), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BLOB_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.blob(Int.MAX_VALUE)), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__CLOB_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.clob(Int.MAX_VALUE)), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__CLOB_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.clob(Int.MAX_VALUE)), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__CLOB_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.clob(Int.MAX_VALUE)), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DATE_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.date()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DATE_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.date()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__DATE_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.date()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__TIME_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.time(6)), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__TIME_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.time(6)), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__TIME_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.time(6)), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__TIMESTAMP_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.timestamp(6)), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__TIMESTAMP_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.timestamp(6)), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__TIMESTAMP_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.timestamp(6)), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BAG_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bag()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BAG_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bag()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__BAG_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.bag()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__LIST_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.array()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__LIST_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.array()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__LIST_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.array()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__SEXP_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.sexp()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__SEXP_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.sexp()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__SEXP_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.sexp()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__STRUCT_BAG__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.struct()), - Parameter("collection", PType.bag()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__STRUCT_LIST__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.struct()), - Parameter("collection", PType.array()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} - -internal val Fn_IN_COLLECTION__STRUCT_SEXP__BOOL = Function.static( - - name = "in_collection", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.struct()), - Parameter("collection", PType.sexp()), - ), - -) { args -> - val value = args[0] - val collection = args[1] - val iter = collection.iterator() - while (iter.hasNext()) { - val v = iter.next() - if (Datum.comparator().compare(value, v) == 0) { - return@static Datum.bool(true) - } - } - Datum.bool(false) -} diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt index 3a7e3e6d7..8dcab3f5f 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimal.kt @@ -45,7 +45,7 @@ internal val Fn_IS_DECIMAL__INT32_INT32_ANY__BOOL = Function.static( */ { args -> val v = args[2] - if (v.type.kind != PType.Kind.DECIMAL && v.type.kind != PType.Kind.DECIMAL_ARBITRARY) { + if (v.type.kind != PType.Kind.DECIMAL) { return@static Datum.bool(false) } val p = args[0].int diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimalArbitrary.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimalArbitrary.kt deleted file mode 100644 index 519ff52ae..000000000 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsDecimalArbitrary.kt +++ /dev/null @@ -1,19 +0,0 @@ -// ktlint-disable filename -@file:Suppress("ClassName") - -package org.partiql.spi.function.builtins - -import org.partiql.spi.function.Function -import org.partiql.spi.function.Parameter -import org.partiql.spi.value.Datum -import org.partiql.types.PType - -internal val Fn_IS_DECIMAL_ARBITRARY__ANY__BOOL = Function.static( - - name = "is_decimal_arbitrary", - returns = PType.bool(), - parameters = arrayOf(Parameter("value", PType.dynamic())), - -) { args -> - Datum.bool(args[0].type.kind == PType.Kind.DECIMAL_ARBITRARY) -} diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSexp.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSexp.kt deleted file mode 100644 index 558e26be6..000000000 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSexp.kt +++ /dev/null @@ -1,19 +0,0 @@ -// ktlint-disable filename -@file:Suppress("ClassName") - -package org.partiql.spi.function.builtins - -import org.partiql.spi.function.Function -import org.partiql.spi.function.Parameter -import org.partiql.spi.value.Datum -import org.partiql.types.PType - -internal val Fn_IS_SEXP__ANY__BOOL = Function.static( - - name = "is_sexp", - returns = PType.bool(), - parameters = arrayOf(Parameter("value", PType.dynamic())), - -) { args -> - Datum.bool(args[0].type.kind == PType.Kind.SEXP) -} diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSymbol.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSymbol.kt deleted file mode 100644 index 07acfa578..000000000 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnIsSymbol.kt +++ /dev/null @@ -1,19 +0,0 @@ -// ktlint-disable filename -@file:Suppress("ClassName") - -package org.partiql.spi.function.builtins - -import org.partiql.spi.function.Function -import org.partiql.spi.function.Parameter -import org.partiql.spi.value.Datum -import org.partiql.types.PType - -internal val Fn_IS_SYMBOL__ANY__BOOL = Function.static( - - name = "is_symbol", - returns = PType.bool(), - parameters = arrayOf(Parameter("value", PType.dynamic())), - -) { args -> - Datum.bool(args[0].type.kind == PType.Kind.SYMBOL) -} diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLike.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLike.kt index 6d0113407..7d2801dd0 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLike.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLike.kt @@ -33,28 +33,6 @@ internal val Fn_LIKE__STRING_STRING__BOOL = Function.static( } } -internal val Fn_LIKE__SYMBOL_SYMBOL__BOOL = Function.static( - - name = "like", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("pattern", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val pattern = args[1].string - val likeRegexPattern = when { - pattern.isEmpty() -> Pattern.compile("") - else -> parsePattern(pattern, null) - } - when (matchRegexPattern(value, likeRegexPattern)) { - true -> Datum.bool(true) - else -> Datum.bool(false) - } -} - internal val Fn_LIKE__CLOB_CLOB__BOOL = Function.static( name = "like", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLikeEscape.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLikeEscape.kt index 5f5df3bf1..88093f28a 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLikeEscape.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLikeEscape.kt @@ -43,36 +43,6 @@ internal val Fn_LIKE_ESCAPE__STRING_STRING_STRING__BOOL = Function.static( } } -internal val Fn_LIKE_ESCAPE__SYMBOL_SYMBOL_SYMBOL__BOOL = Function.static( - - name = "like_escape", - returns = PType.bool(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("pattern", PType.symbol()), - Parameter("escape", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val pattern = args[1].string - val escape = args[2].string - val (patternString, escapeChar) = - try { - checkPattern(pattern, escape) - } catch (e: IllegalStateException) { - throw TypeCheckException() - } - val likeRegexPattern = when { - patternString.isEmpty() -> Pattern.compile("") - else -> parsePattern(patternString, escapeChar) - } - when (PatternUtils.matchRegexPattern(value, likeRegexPattern)) { - true -> Datum.bool(true) - else -> Datum.bool(false) - } -} - internal val Fn_LIKE_ESCAPE__CLOB_CLOB_CLOB__BOOL = Function.static( name = "like_escape", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt index 50be027d0..ebca15aee 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt @@ -20,18 +20,6 @@ internal val Fn_LOWER__STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_LOWER__SYMBOL__SYMBOL = Function.static( - - name = "lower", - returns = PType.symbol(), - parameters = arrayOf(Parameter("value", PType.symbol())), - -) { args -> - val string = args[0].string - val result = string.lowercase() - Datum.string(result) -} - internal val Fn_LOWER__CLOB__CLOB = Function.static( name = "lower", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt index d80e738a3..461c9d4ba 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLt.kt @@ -88,8 +88,8 @@ internal val Fn_LT__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL = Function.static( name = "lt", returns = PType.bool(), parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("lhs", PType.decimal()), - @Suppress("DEPRECATION") Parameter("rhs", PType.decimal()), + Parameter("lhs", PType.decimal()), + Parameter("rhs", PType.decimal()), ), ) { args -> @@ -143,21 +143,6 @@ internal val Fn_LT__STRING_STRING__BOOL = Function.static( Datum.bool(lhs < rhs) } -internal val Fn_LT__SYMBOL_SYMBOL__BOOL = Function.static( - - name = "lt", - returns = PType.bool(), - parameters = arrayOf( - Parameter("lhs", PType.symbol()), - Parameter("rhs", PType.symbol()), - ), - -) { args -> - val lhs = args[0].string - val rhs = args[1].string - Datum.bool(lhs < rhs) -} - internal val Fn_LT__DATE_DATE__BOOL = Function.static( name = "lt", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt index c5243e0f4..a2c2b4e28 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLte.kt @@ -88,8 +88,8 @@ internal val Fn_LTE__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__BOOL = Function.static name = "lte", returns = PType.bool(), parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("lhs", PType.decimal()), - @Suppress("DEPRECATION") Parameter("rhs", PType.decimal()), + Parameter("lhs", PType.decimal()), + Parameter("rhs", PType.decimal()), ), ) { args -> @@ -143,21 +143,6 @@ internal val Fn_LTE__STRING_STRING__BOOL = Function.static( Datum.bool(lhs <= rhs) } -internal val Fn_LTE__SYMBOL_SYMBOL__BOOL = Function.static( - - name = "lte", - returns = PType.bool(), - parameters = arrayOf( - Parameter("lhs", PType.symbol()), - Parameter("rhs", PType.symbol()), - ), - -) { args -> - val lhs = args[0].string - val rhs = args[1].string - Datum.bool(lhs <= rhs) -} - internal val Fn_LTE__DATE_DATE__BOOL = Function.static( name = "lte", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnOctetLength.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnOctetLength.kt index 460efb4ed..b4ea074e9 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnOctetLength.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnOctetLength.kt @@ -19,20 +19,6 @@ internal val Fn_OCTET_LENGTH__STRING__INT32 = Function.static( Datum.integer(length) } -internal val Fn_OCTET_LENGTH__SYMBOL__INT32 = Function.static( - - name = "octet_length", - returns = PType.integer(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val length = value.toByteArray(Charsets.UTF_8).size - Datum.integer(length) -} - internal val Fn_OCTET_LENGTH__CLOB__INT32 = Function.static( name = "octet_length", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt index 0af98f16a..4b44fa83e 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPlus.kt @@ -89,8 +89,8 @@ internal val Fn_PLUS__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = F name = "plus", returns = PType.decimal(), parameters = arrayOf( - @Suppress("DEPRECATION") Parameter("lhs", PType.decimal()), - @Suppress("DEPRECATION") Parameter("rhs", PType.decimal()), + Parameter("lhs", PType.decimal()), + Parameter("rhs", PType.decimal()), ), ) { args -> diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPosition.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPosition.kt index a1e8e63f2..27992ebc8 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPosition.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnPosition.kt @@ -25,22 +25,6 @@ internal val Fn_POSITION__STRING_STRING__INT64 = Function.static( Datum.bigint(result.toLong()) } -internal val Fn_POSITION__SYMBOL_SYMBOL__INT64 = Function.static( - - name = "position", - returns = PType.bigint(), - parameters = arrayOf( - Parameter("probe", PType.symbol()), - Parameter("value", PType.symbol()), - ), - -) { args -> - val s1 = args[0].string - val s2 = args[1].string - val result = s2.codepointPosition(s1) - Datum.bigint(result.toLong()) -} - internal val Fn_POSITION__CLOB_CLOB__INT64 = Function.static( name = "position", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSize.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSize.kt index 35395cad3..554dbd253 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSize.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSize.kt @@ -31,19 +31,6 @@ internal val Fn_SIZE__LIST__INT32 = Function.static( Datum.integer(container.count()) } -internal val Fn_SIZE__SEXP__INT32 = Function.static( - - name = "size", - returns = PType.integer(), - parameters = arrayOf( - Parameter("container", PType.sexp()), - ), - -) { args -> - val container = args[0] - Datum.integer(container.count()) -} - internal val Fn_SIZE__STRUCT__INT32 = Function.static( name = "size", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSubstring.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSubstring.kt index b7f7c49f6..1872b9ef5 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSubstring.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnSubstring.kt @@ -114,41 +114,6 @@ internal val Fn_SUBSTRING__STRING_INT32_INT32__STRING = Function.static( Datum.string(result) } -internal val Fn_SUBSTRING__SYMBOL_INT64__SYMBOL = Function.static( - - name = "substring", - returns = PType.symbol(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("start", PType.integer()), - ), - -) { args -> - val value = args[0].string - val start = args[1].int - val result = value.codepointSubstring(start) - Datum.symbol(result) -} - -internal val Fn_SUBSTRING__SYMBOL_INT32_INT32__SYMBOL = Function.static( - - name = "substring", - returns = PType.symbol(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("start", PType.integer()), - Parameter("end", PType.integer()), - ), - -) { args -> - val value = args[0].string - val start = args[1].int - val end = args[1].int - if (end < 0) throw TypeCheckException() - val result = value.codepointSubstring(start, end) - Datum.symbol(result) -} - internal val Fn_SUBSTRING__CLOB_INT64__CLOB = Function.static( name = "substring", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrim.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrim.kt index 4ba805a42..6da1ea25f 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrim.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrim.kt @@ -50,18 +50,6 @@ internal val Fn_TRIM__STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_TRIM__SYMBOL__SYMBOL = Function.static( - - name = "trim", - returns = PType.symbol(), - parameters = arrayOf(Parameter("value", PType.symbol())), - -) { args -> - val value = args[0].string - val result = value.codepointTrim() - Datum.symbol(result) -} - internal val Fn_TRIM__CLOB__CLOB = Function.static( name = "trim", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimChars.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimChars.kt index 723ca2228..1a57fc043 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimChars.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimChars.kt @@ -25,22 +25,6 @@ internal val Fn_TRIM_CHARS__STRING_STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_TRIM_CHARS__SYMBOL_SYMBOL__SYMBOL = Function.static( - - name = "trim_chars", - returns = PType.symbol(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("chars", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val chars = args[1].string - val result = value.codepointTrim(chars) - Datum.symbol(result) -} - internal val Fn_TRIM_CHARS__CLOB_CLOB__CLOB = Function.static( name = "trim_chars", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeading.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeading.kt index e55f4297e..c1452755a 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeading.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeading.kt @@ -21,18 +21,6 @@ internal val Fn_TRIM_LEADING__STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_TRIM_LEADING__SYMBOL__SYMBOL = Function.static( - - name = "trim_leading", - returns = PType.symbol(), - parameters = arrayOf(Parameter("value", PType.symbol())), - -) { args -> - val value = args[0].string - val result = value.codepointTrimLeading() - Datum.symbol(result) -} - internal val Fn_TRIM_LEADING__CLOB__CLOB = Function.static( name = "trim_leading", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeadingChars.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeadingChars.kt index 05d9fea2f..600e6003d 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeadingChars.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimLeadingChars.kt @@ -25,22 +25,6 @@ internal val Fn_TRIM_LEADING_CHARS__STRING_STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_TRIM_LEADING_CHARS__SYMBOL_SYMBOL__SYMBOL = Function.static( - - name = "trim_leading_chars", - returns = PType.symbol(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("chars", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val chars = args[1].string - val result = value.codepointTrimLeading(chars) - Datum.symbol(result) -} - internal val Fn_TRIM_LEADING_CHARS__CLOB_CLOB__CLOB = Function.static( name = "trim_leading_chars", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailing.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailing.kt index a0ca76f06..2431ea54e 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailing.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailing.kt @@ -21,18 +21,6 @@ internal val Fn_TRIM_TRAILING__STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_TRIM_TRAILING__SYMBOL__SYMBOL = Function.static( - - name = "trim_trailing", - returns = PType.symbol(), - parameters = arrayOf(Parameter("value", PType.symbol())), - -) { args -> - val value = args[0].string - val result = value.codepointTrimTrailing() - Datum.symbol(result) -} - internal val Fn_TRIM_TRAILING__CLOB__CLOB = Function.static( name = "trim_trailing", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailingChars.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailingChars.kt index e770726f0..d6895e14e 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailingChars.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrimTrailingChars.kt @@ -25,22 +25,6 @@ internal val Fn_TRIM_TRAILING_CHARS__STRING_STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_TRIM_TRAILING_CHARS__SYMBOL_SYMBOL__SYMBOL = Function.static( - - name = "trim_trailing_chars", - returns = PType.symbol(), - parameters = arrayOf( - Parameter("value", PType.symbol()), - Parameter("chars", PType.symbol()), - ), - -) { args -> - val value = args[0].string - val chars = args[1].string - val result = value.codepointTrimTrailing(chars) - Datum.symbol(result) -} - internal val Fn_TRIM_TRAILING_CHARS__CLOB_CLOB__CLOB = Function.static( name = "trim_trailing_chars", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnUpper.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnUpper.kt index f9d3f60d4..f5a118a13 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnUpper.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnUpper.kt @@ -20,18 +20,6 @@ internal val Fn_UPPER__STRING__STRING = Function.static( Datum.string(result) } -internal val Fn_UPPER__SYMBOL__SYMBOL = Function.static( - - name = "upper", - returns = PType.symbol(), - parameters = arrayOf(Parameter("value", PType.symbol())), - -) { args -> - val string = args[0].string - val result = string.uppercase() - Datum.symbol(result) -} - internal val Fn_UPPER__CLOB__CLOB = Function.static( name = "upper", diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt index 289e05c12..d56366610 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/internal/Accumulator.kt @@ -110,7 +110,6 @@ internal fun Datum.numberValue(): Number = when (this.type.kind) { PType.Kind.REAL -> this.float PType.Kind.DOUBLE -> this.double PType.Kind.DECIMAL -> this.bigDecimal - PType.Kind.DECIMAL_ARBITRARY -> this.bigDecimal else -> error("Cannot convert PartiQLValue ($this) to number.") } @@ -128,7 +127,6 @@ internal fun PType.isNumber(): Boolean = when (this.kind) { PType.Kind.REAL, PType.Kind.DOUBLE, PType.Kind.DECIMAL, - PType.Kind.DECIMAL_ARBITRARY, -> true else -> false } @@ -145,7 +143,7 @@ internal fun Number.toTargetType(type: PType): Datum = when (type.kind) { PType.Kind.DYNAMIC -> this.toDatum() PType.Kind.REAL -> Datum.real(this.toFloat()) PType.Kind.DOUBLE -> Datum.doublePrecision(this.toDouble()) - PType.Kind.DECIMAL, PType.Kind.DECIMAL_ARBITRARY -> { + PType.Kind.DECIMAL -> { when (this) { is BigDecimal -> Datum.decimal(this) is BigInteger -> Datum.decimal(this.toBigDecimal()) diff --git a/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt b/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt index a421f02cb..bf07ea213 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/spi/internal/SqlTypeFamily.kt @@ -45,7 +45,6 @@ internal class SqlTypeFamily private constructor( Kind.CHAR, Kind.VARCHAR, Kind.STRING, - Kind.SYMBOL, Kind.CLOB, ) ) @@ -55,7 +54,6 @@ internal class SqlTypeFamily private constructor( preferred = PType.bag(), members = setOf( Kind.ARRAY, - Kind.SEXP, Kind.BAG ) ) @@ -72,7 +70,6 @@ internal class SqlTypeFamily private constructor( Kind.REAL, Kind.DOUBLE, Kind.DECIMAL, - Kind.DECIMAL_ARBITRARY ) ) } diff --git a/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt b/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt index cbbe01bd3..a579a1bad 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt @@ -70,16 +70,17 @@ public enum class PartiQLValueType { ) public fun toPType(): PType { return when (this) { - DECIMAL, DECIMAL_ARBITRARY -> PType.decimal() + DECIMAL -> PType.decimal() + DECIMAL_ARBITRARY -> PType.decimal() // TODO: Figure out precision/scale implications. INT8 -> PType.tinyint() CHAR -> PType.character(255) TIMESTAMP -> PType.timestampz(6) DATE -> PType.date() BOOL -> PType.bool() - SYMBOL -> PType.symbol() + SYMBOL -> TODO("SYMBOL has been removed") STRING -> PType.string() STRUCT -> PType.struct() - SEXP -> PType.sexp() + SEXP -> TODO("SEXP has been removed.") LIST -> PType.array() BAG -> PType.bag() FLOAT32 -> PType.real() diff --git a/partiql-spi/src/main/kotlin/org/partiql/value/io/PartiQLValueIonReader.kt b/partiql-spi/src/main/kotlin/org/partiql/value/io/PartiQLValueIonReader.kt index 6f42b1e2b..baca33715 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/value/io/PartiQLValueIonReader.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/value/io/PartiQLValueIonReader.kt @@ -23,10 +23,8 @@ import org.partiql.value.intValue import org.partiql.value.listValue import org.partiql.value.missingValue import org.partiql.value.nullValue -import org.partiql.value.sexpValue import org.partiql.value.stringValue import org.partiql.value.structValue -import org.partiql.value.symbolValue import org.partiql.value.timeValue import org.partiql.value.timestampValue import java.io.ByteArrayInputStream @@ -124,15 +122,7 @@ internal class PartiQLValueIonReader( } } - IonType.SYMBOL -> { - if (reader.isNullValue) { - symbolValue(null, reader.typeAnnotations.toList()) - } else { - symbolValue(reader.stringValue(), reader.typeAnnotations.toList()) - } - } - - IonType.STRING -> { + IonType.STRING, IonType.SYMBOL -> { if (reader.isNullValue) { stringValue(null, reader.typeAnnotations.toList()) } else { @@ -156,7 +146,7 @@ internal class PartiQLValueIonReader( } } - IonType.LIST -> { + IonType.LIST, IonType.SEXP -> { val annotations = reader.typeAnnotations.toList() reader.stepIn() val elements = mutableListOf().also { elements -> @@ -168,18 +158,6 @@ internal class PartiQLValueIonReader( listValue(elements, annotations) } - IonType.SEXP -> { - val annotation = reader.typeAnnotations.toList() - reader.stepIn() - val elements = mutableListOf().also { elements -> - reader.loadEachValue { - elements.add(fromIon(reader)) - } - } - reader.stepOut() - sexpValue(elements, annotation) - } - IonType.STRUCT -> { val annotations = reader.typeAnnotations.toList() reader.stepIn() @@ -306,25 +284,7 @@ internal class PartiQLValueIonReader( } } - IonType.SYMBOL -> { - when (lastAnnotation) { - PARTIQL_ANNOTATION.MISSING_ANNOTATION -> throw IllegalArgumentException("MISSING_ANNOTATION with Symbol Value") - PARTIQL_ANNOTATION.BAG_ANNOTATION -> throw IllegalArgumentException("BAG_ANNOTATION with Symbol Value") - PARTIQL_ANNOTATION.DATE_ANNOTATION -> throw IllegalArgumentException("DATE_ANNOTATION with Symbol Value") - PARTIQL_ANNOTATION.TIME_ANNOTATION -> throw IllegalArgumentException("TIME_ANNOTATION with Symbol Value") - PARTIQL_ANNOTATION.TIMESTAMP_ANNOTATION -> throw IllegalArgumentException("TIMESTAMP_ANNOTATION with Symbol Value") - PARTIQL_ANNOTATION.GRAPH_ANNOTATION -> throw IllegalArgumentException("GRAPH_ANNOTATION with Symbol Value") - null -> { - if (reader.isNullValue) { - symbolValue(null, annotations) - } else { - symbolValue(reader.stringValue(), annotations) - } - } - } - } - - IonType.STRING -> { + IonType.STRING, IonType.SYMBOL -> { when (lastAnnotation) { PARTIQL_ANNOTATION.MISSING_ANNOTATION -> throw IllegalArgumentException("MISSING_ANNOTATION with String Value") PARTIQL_ANNOTATION.BAG_ANNOTATION -> throw IllegalArgumentException("BAG_ANNOTATION with String Value") @@ -426,7 +386,7 @@ internal class PartiQLValueIonReader( PARTIQL_ANNOTATION.GRAPH_ANNOTATION -> TODO("Not yet implemented") null -> { if (reader.isNullValue) { - sexpValue(null, annotations) + listValue(null, annotations) } else { reader.stepIn() val elements = mutableListOf().also { elements -> @@ -435,7 +395,7 @@ internal class PartiQLValueIonReader( } } reader.stepOut() - sexpValue(elements, annotations) + listValue(elements, annotations) } } } diff --git a/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt b/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt index 34aa5dee1..aac37eec0 100644 --- a/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt +++ b/partiql-spi/src/test/kotlin/org/partiql/eval/value/DatumComparatorTest.kt @@ -202,35 +202,26 @@ class DatumComparatorTest { EquivValues( Datum.string(""), // TODO: Datum.string("", annotations = listOf("foobar")), - Datum.symbol(""), - // TODO: Datum.symbol("", annotations = listOf("foobar")) ), EquivValues( Datum.string("A"), // TODO: Datum.string("A", annotations = listOf("foobar")), - Datum.symbol("A"), - // TODO: Datum.symbol("A", annotations = listOf("foobar")) ), EquivValues( Datum.string("AA"), - Datum.symbol("AA"), ), EquivValues( Datum.string("a"), - Datum.symbol("a"), ), EquivValues( Datum.string("azzzzzzz"), - Datum.symbol("azzzzzzz"), ), EquivValues( Datum.string("z"), - Datum.symbol("z"), ), // TODO add a UTF-16 order breaker here to verify we're doing the right thing EquivValues( Datum.string("\uD83D\uDCA9"), - Datum.symbol("\uD83D\uDCA9"), ), EquivValues( Datum.blob(base64Decode("")), // `{{}}` @@ -315,28 +306,6 @@ class DatumComparatorTest { ) ) // [[[1]]] ), - // TODO: Annotations. -// EquivValues( -// Datum.sexp(emptyList(), annotations = listOf("a", "b", "c")) // `a::b::c::()` -// ), - EquivValues( - Datum.sexp(listOf(Datum.real(1f))), // `a::b::c::(1e0)` - Datum.sexp(listOf(Datum.doublePrecision(1.0))), // TODO: annotations = listOf("a", "b", "c")), // `a::b::c::(1e0)` - Datum.sexp(listOf(Datum.integer(1))), // `(1)` - Datum.sexp(listOf(Datum.decimal(BigDecimal("1.0000000000000")))) // `(1.0000000000000)` - ), - EquivValues( - Datum.sexp(listOf(Datum.timestamp(timestamp(year = 2012)), Datum.real(Float.NaN))) // `(2012T nan)` - ), - EquivValues( - Datum.sexp(listOf(Datum.timestamp(timestamp(year = 2012)), Datum.integer(1), Datum.integer(2), Datum.integer(3))) // `(2012T 1 2 3)` - ), - EquivValues( - Datum.sexp(listOf(Datum.array(emptyList()))) // `([])` - ), - EquivValues( - Datum.sexp(listOf(emptyList, emptyList)) // `([] [])` - ), EquivValues( emptyStruct(), // {} // TODO: emptyStruct(annotations = listOf("m", "n", "o")) // `m::n::o::{}` diff --git a/partiql-spi/src/test/kotlin/org/partiql/value/io/PartiQLValueIonSerdeTest.kt b/partiql-spi/src/test/kotlin/org/partiql/value/io/PartiQLValueIonSerdeTest.kt index a2a7f0dcc..3b4437fe0 100644 --- a/partiql-spi/src/test/kotlin/org/partiql/value/io/PartiQLValueIonSerdeTest.kt +++ b/partiql-spi/src/test/kotlin/org/partiql/value/io/PartiQLValueIonSerdeTest.kt @@ -33,10 +33,8 @@ import org.partiql.value.intValue import org.partiql.value.listValue import org.partiql.value.missingValue import org.partiql.value.nullValue -import org.partiql.value.sexpValue import org.partiql.value.stringValue import org.partiql.value.structValue -import org.partiql.value.symbolValue import org.partiql.value.timeValue import org.partiql.value.timestampValue import java.io.ByteArrayInputStream @@ -115,11 +113,12 @@ class PartiQLValueIonSerdeTest { timestampValue(null), ION.newNullTimestamp() ), + // TODO: Potentially handle this with the impl of VARIANT // symbol.null - roundTrip( - symbolValue(null), - ION.newNullSymbol() - ), +// roundTrip( +// symbolValue(null), +// ION.newNullSymbol() +// ), // string.null roundTrip( stringValue(null), @@ -140,11 +139,12 @@ class PartiQLValueIonSerdeTest { listValue(null), ION.newNullList() ), + // TODO: Potentially handle this with the impl of VARIANT // Sexp.null - roundTrip( - sexpValue(null), - ION.newNullSexp() - ), +// roundTrip( +// sexpValue(null), +// ION.newNullSexp() +// ), // struct.null roundTrip( structValue(null), @@ -246,14 +246,15 @@ class PartiQLValueIonSerdeTest { stringValue("word\nword"), ION.newString("word\nword") ), - roundTrip( - symbolValue("x"), - ION.newSymbol("x"), - ), - roundTrip( - symbolValue("f.x"), - ION.newSymbol("f.x"), - ), + // TODO: Potentially handle this with the impl of variant +// roundTrip( +// symbolValue("x"), +// ION.newSymbol("x"), +// ), +// roundTrip( +// symbolValue("f.x"), +// ION.newSymbol("f.x"), +// ), roundTrip( dateValue(DateTimeValue.date(2023, 6, 1)), ION.newEmptyStruct().apply { @@ -367,10 +368,11 @@ class PartiQLValueIonSerdeTest { listValue(), ION.newEmptyList() ), - roundTrip( - sexpValue(), - ION.newEmptySexp() - ), + // TODO: Do we want to cover this in the impl of variant? +// roundTrip( +// sexpValue(), +// ION.newEmptySexp() +// ), oneWayTrip( bagValue( int32Value(1), @@ -400,23 +402,24 @@ class PartiQLValueIonSerdeTest { ION.newString("c") ) ), - oneWayTrip( - sexpValue( - int32Value(1), - int32Value(2), - int32Value(3), - ), - ION.newSexp( - ION.newInt(1), - ION.newInt(2), - ION.newInt(3) - ), - sexpValue( - intValue(BigInteger.ONE), - intValue(BigInteger.valueOf(2L)), - intValue(BigInteger.valueOf(3L)), - ) - ), + // TODO: Potentially handle this with VARIANT +// oneWayTrip( +// sexpValue( +// int32Value(1), +// int32Value(2), +// int32Value(3), +// ), +// ION.newSexp( +// ION.newInt(1), +// ION.newInt(2), +// ION.newInt(3) +// ), +// sexpValue( +// intValue(BigInteger.ONE), +// intValue(BigInteger.valueOf(2L)), +// intValue(BigInteger.valueOf(3L)), +// ) +// ), oneWayTrip( structValue( "a" to int32Value(1), diff --git a/partiql-types/api/partiql-types.api b/partiql-types/api/partiql-types.api index 7455a3624..6145bbbf8 100644 --- a/partiql-types/api/partiql-types.api +++ b/partiql-types/api/partiql-types.api @@ -31,12 +31,9 @@ public abstract interface class org/partiql/types/PType { public static fun real ()Lorg/partiql/types/PType; public static fun row (Ljava/util/Collection;)Lorg/partiql/types/PType; public static fun row ([Lorg/partiql/types/Field;)Lorg/partiql/types/PType; - public static fun sexp ()Lorg/partiql/types/PType; - public static fun sexp (Lorg/partiql/types/PType;)Lorg/partiql/types/PType; public static fun smallint ()Lorg/partiql/types/PType; public static fun string ()Lorg/partiql/types/PType; public static fun struct ()Lorg/partiql/types/PType; - public static fun symbol ()Lorg/partiql/types/PType; public static fun time (I)Lorg/partiql/types/PType; public static fun timestamp (I)Lorg/partiql/types/PType; public static fun timestampz (I)Lorg/partiql/types/PType; @@ -57,18 +54,15 @@ public final class org/partiql/types/PType$Kind : java/lang/Enum { public static final field CLOB Lorg/partiql/types/PType$Kind; public static final field DATE Lorg/partiql/types/PType$Kind; public static final field DECIMAL Lorg/partiql/types/PType$Kind; - public static final field DECIMAL_ARBITRARY Lorg/partiql/types/PType$Kind; public static final field DOUBLE Lorg/partiql/types/PType$Kind; public static final field DYNAMIC Lorg/partiql/types/PType$Kind; public static final field INTEGER Lorg/partiql/types/PType$Kind; public static final field NUMERIC Lorg/partiql/types/PType$Kind; public static final field REAL Lorg/partiql/types/PType$Kind; public static final field ROW Lorg/partiql/types/PType$Kind; - public static final field SEXP Lorg/partiql/types/PType$Kind; public static final field SMALLINT Lorg/partiql/types/PType$Kind; public static final field STRING Lorg/partiql/types/PType$Kind; public static final field STRUCT Lorg/partiql/types/PType$Kind; - public static final field SYMBOL Lorg/partiql/types/PType$Kind; public static final field TIME Lorg/partiql/types/PType$Kind; public static final field TIMESTAMP Lorg/partiql/types/PType$Kind; public static final field TIMESTAMPZ Lorg/partiql/types/PType$Kind; diff --git a/partiql-types/src/main/java/org/partiql/types/PType.java b/partiql-types/src/main/java/org/partiql/types/PType.java index 5cff5c4c4..c6bfb59b6 100644 --- a/partiql-types/src/main/java/org/partiql/types/PType.java +++ b/partiql-types/src/main/java/org/partiql/types/PType.java @@ -93,7 +93,7 @@ default int getScale() throws UnsupportedOperationException { * * @return type parameter of the type * @throws UnsupportedOperationException if this is called on a type whose {@link Kind} is not: - * {@link Kind#ARRAY}, {@link Kind#BAG}, {@link Kind#SEXP} + * {@link Kind#ARRAY}, {@link Kind#BAG} */ @NotNull default PType getTypeParameter() throws UnsupportedOperationException { @@ -195,19 +195,6 @@ enum Kind { */ DECIMAL, - /** - * Ion's arbitrary precision and scale decimal type. - *
- *
- * Type Syntax: TO_BE_DETERMINED - *
- * Applicable methods: NONE - * - * @deprecated this is an experimental API and is subject to modification/deletion without prior notice. - */ - @Deprecated - DECIMAL_ARBITRARY, - /** * SQL's real type. *
@@ -260,19 +247,6 @@ enum Kind { */ STRING, - /** - * Ion's symbol type. - *
- *
- * Type Syntax: TO_BE_DETERMINED - *
- * Applicable methods: NONE - * - * @deprecated this is an experimental API and is subject to modification/deletion without prior notice. - */ - @Deprecated - SYMBOL, - /** * SQL's blob type. *
@@ -416,20 +390,6 @@ enum Kind { @Deprecated ROW, - /** - * Ion's s-expression type. There is no size limit. - *
- *
- * Type Syntax: SEXP, SEXP(<type>) - *
- * Applicable methods: - * {@link PType#getTypeParameter()} - * - * @deprecated this is an experimental API and is subject to modification/deletion without prior notice. - */ - @Deprecated - SEXP, - /** * Ion's struct type. Characterized as an open, unordered collection of fields (duplicates allowed). *
@@ -522,16 +482,15 @@ static PType numeric() { } /** - * @return a PartiQL decimal (arbitrary precision/scale) type - * @deprecated this API is experimental and is subject to modification/deletion without prior notice. + * @return a decimal with the default precision (38) and default scale (0) */ @NotNull static PType decimal() { - return new PTypePrimitive(Kind.DECIMAL_ARBITRARY); + return decimal(38, 0); } /** - * @return a PartiQL decimal type + * @return a decimal with user-specified precision and default scale (0) */ @NotNull static PType decimal(int precision) { @@ -588,16 +547,6 @@ static PType string() { return new PTypePrimitive(Kind.STRING); } - /** - * @return a PartiQL string type - * @deprecated this API is experimental and is subject to modification/deletion without prior notice. - */ - @NotNull - @Deprecated - static PType symbol() { - return new PTypePrimitive(Kind.SYMBOL); - } - /** * @return a PartiQL clob type * @deprecated this API is experimental and is subject to modification/deletion without prior notice. @@ -688,33 +637,13 @@ static PType bag(@NotNull PType typeParam) { return new PTypeCollection(Kind.BAG, typeParam); } - /** - * @return a PartiQL sexp type containing a component type of dynamic. - * @deprecated this is an experimental API and is subject to modification/deletion without prior notice. - */ - @Deprecated - @NotNull - static PType sexp() { - return new PTypeCollection(Kind.SEXP, PType.dynamic()); - } - - /** - * @param typeParam the component type to be used - * @return a PartiQL sexp type containing a component type of {@code typeParam}. - * @deprecated this is an experimental API and is subject to modification/deletion without prior notice. - */ - @NotNull - static PType sexp(@NotNull PType typeParam) { - return new PTypeCollection(Kind.SEXP, typeParam); - } - /** * @return a PartiQL row type * @deprecated this API is experimental and is subject to modification/deletion without prior notice. */ @NotNull - static PType row(@NotNull Field... fields) { - return new PTypeRow(Arrays.asList(fields)); + static PType row(@NotNull Collection fields) { + return new PTypeRow(fields); } /** @@ -722,8 +651,8 @@ static PType row(@NotNull Field... fields) { * @deprecated this API is experimental and is subject to modification/deletion without prior notice. */ @NotNull - static PType row(@NotNull Collection fields) { - return new PTypeRow(fields); + static PType row(@NotNull Field... fields) { + return new PTypeRow(Arrays.asList(fields)); } /** diff --git a/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt b/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt index 5476476b7..e006a2878 100644 --- a/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt +++ b/partiql-types/src/testFixtures/kotlin/org/partiql/types/FromStaticType.kt @@ -62,8 +62,7 @@ fun fromStaticType(type: StaticType): PType { val elementType = fromStaticType(type.elementType) return PType.array(elementType) } else if (type is SexpType) { - val elementType = fromStaticType(type.elementType) - return PType.sexp(elementType) + throw java.lang.IllegalStateException("SEXP is not supported.") } else if (type is StringType) { return PType.string() } else if (type is StructType) { @@ -83,7 +82,7 @@ fun fromStaticType(type: StaticType): PType { PType.struct() } } else if (type is SymbolType) { - return PType.symbol() + throw java.lang.IllegalStateException("SYMBOL not supported.") } else if (type is TimeType) { var precision = type.precision if (precision == null) { From d9715e47b987317b6751f071aa8f9e99c8dd017c Mon Sep 17 00:00:00 2001 From: John Ed Quinn Date: Mon, 18 Nov 2024 11:26:24 -0800 Subject: [PATCH 2/2] Cleans up references to SEXP Adds error for DECIMAL_ARBITRARY usage --- .../org/partiql/eval/internal/operator/rel/RelOpExclude.kt | 6 +++--- .../src/main/kotlin/org/partiql/value/PartiQLValueType.kt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt index 195ea637a..5a1cf8b71 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt @@ -134,7 +134,7 @@ internal class RelOpExclude( /** * Returns a [PartiQLValue] created from an iterable of [coll]. Requires [type] to be a collection type - * (i.e. [PartiQLValueType.LIST], [PartiQLValueType.BAG], or [PartiQLValueType.SEXP]). + * (i.e. [PartiQLValueType.LIST] or [PartiQLValueType.BAG].). */ private fun newCollValue(type: PType, coll: Iterable): Datum { return when (type.kind) { @@ -171,13 +171,13 @@ internal class RelOpExclude( } // apply exclusions to subtree var value = element - // apply collection index exclusions at deeper levels for lists and sexps + // apply collection index exclusions at deeper levels for lists if (type.kind == PType.Kind.ARRAY) { branches.getCollIndex(i)?.let { value = value.exclude(it.getItems()) } } - // apply collection wildcard exclusions at deeper levels for lists, bags, and sexps + // apply collection wildcard exclusions at deeper levels for lists and bags branches.getCollWildcard()?.let { value = value.exclude(it.getItems()) } diff --git a/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt b/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt index a579a1bad..47873ec25 100644 --- a/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt +++ b/partiql-spi/src/main/kotlin/org/partiql/value/PartiQLValueType.kt @@ -71,16 +71,16 @@ public enum class PartiQLValueType { public fun toPType(): PType { return when (this) { DECIMAL -> PType.decimal() - DECIMAL_ARBITRARY -> PType.decimal() // TODO: Figure out precision/scale implications. + DECIMAL_ARBITRARY -> error("DECIMAL_ARB has been removed.") INT8 -> PType.tinyint() CHAR -> PType.character(255) TIMESTAMP -> PType.timestampz(6) DATE -> PType.date() BOOL -> PType.bool() - SYMBOL -> TODO("SYMBOL has been removed") + SYMBOL -> error("SYMBOL has been removed") STRING -> PType.string() STRUCT -> PType.struct() - SEXP -> TODO("SEXP has been removed.") + SEXP -> error("SEXP has been removed.") LIST -> PType.array() BAG -> PType.bag() FLOAT32 -> PType.real()