diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnAnd.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnAnd.kt index 98a766abf6..3064c48589 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnAnd.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnAnd.kt @@ -7,10 +7,13 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.BoolValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.BOOL import org.partiql.value.PartiQLValueType.MISSING +import org.partiql.value.boolValue +import org.partiql.value.check @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_AND__BOOL_BOOL__BOOL : PartiQLFunction.Scalar { @@ -27,7 +30,14 @@ internal object Fn_AND__BOOL_BOOL__BOOL : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function and not implemented") + val lhs = args[0].check().value + val rhs = args[1].check().value + val toReturn = when { + lhs == false || rhs == false -> false + lhs == null || rhs == null -> null + else -> true + } + return boolValue(toReturn) } } @@ -46,7 +56,11 @@ internal object Fn_AND__MISSING_BOOL__BOOL : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function and not implemented") + val rhs = args[1].check().value + return when (rhs) { + false -> boolValue(false) + else -> boolValue(null) + } } } @@ -65,7 +79,11 @@ internal object Fn_AND__BOOL_MISSING__BOOL : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function and not implemented") + val lhs = args[0].check().value + return when (lhs) { + false -> boolValue(false) + else -> boolValue(null) + } } } @@ -84,6 +102,6 @@ internal object Fn_AND__MISSING_MISSING__BOOL : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function and not implemented") + return boolValue(null) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnBitwiseAnd.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnBitwiseAnd.kt index e3e49f58ac..c066a6ca92 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnBitwiseAnd.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnBitwiseAnd.kt @@ -7,6 +7,11 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.Int16Value +import org.partiql.value.Int32Value +import org.partiql.value.Int64Value +import org.partiql.value.Int8Value +import org.partiql.value.IntValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.INT @@ -14,6 +19,13 @@ import org.partiql.value.PartiQLValueType.INT16 import org.partiql.value.PartiQLValueType.INT32 import org.partiql.value.PartiQLValueType.INT64 import org.partiql.value.PartiQLValueType.INT8 +import org.partiql.value.check +import org.partiql.value.int16Value +import org.partiql.value.int32Value +import org.partiql.value.int64Value +import org.partiql.value.int8Value +import org.partiql.value.intValue +import kotlin.experimental.and @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_BITWISE_AND__INT8_INT8__INT8 : PartiQLFunction.Scalar { @@ -29,8 +41,10 @@ internal object Fn_BITWISE_AND__INT8_INT8__INT8 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function bitwise_and not implemented") + override fun invoke(args: Array): Int8Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int8Value(arg0 and arg1) } } @@ -48,8 +62,10 @@ internal object Fn_BITWISE_AND__INT16_INT16__INT16 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function bitwise_and not implemented") + override fun invoke(args: Array): Int16Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int16Value(arg0 and arg1) } } @@ -67,8 +83,10 @@ internal object Fn_BITWISE_AND__INT32_INT32__INT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function bitwise_and not implemented") + override fun invoke(args: Array): Int32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int32Value(arg0 and arg1) } } @@ -86,8 +104,10 @@ internal object Fn_BITWISE_AND__INT64_INT64__INT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function bitwise_and not implemented") + override fun invoke(args: Array): Int64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int64Value(arg0 and arg1) } } @@ -105,7 +125,9 @@ internal object Fn_BITWISE_AND__INT_INT__INT : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function bitwise_and not implemented") + override fun invoke(args: Array): IntValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return intValue(arg0 and arg1) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnConcat.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnConcat.kt index 87bfddb5a7..36b2543aac 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnConcat.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnConcat.kt @@ -7,11 +7,18 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.ClobValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.CLOB import org.partiql.value.PartiQLValueType.STRING import org.partiql.value.PartiQLValueType.SYMBOL +import org.partiql.value.StringValue +import org.partiql.value.SymbolValue +import org.partiql.value.check +import org.partiql.value.clobValue +import org.partiql.value.stringValue +import org.partiql.value.symbolValue @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_CONCAT__STRING_STRING__STRING : PartiQLFunction.Scalar { @@ -27,8 +34,11 @@ internal object Fn_CONCAT__STRING_STRING__STRING : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function concat not implemented") + override fun invoke(args: Array): StringValue { + + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return stringValue(arg0 + arg1) } } @@ -46,8 +56,12 @@ internal object Fn_CONCAT__SYMBOL_SYMBOL__SYMBOL : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function concat not implemented") + // TODO: We are still debating on whether symbol is a value. It looks like it may not be, and therefore, this + // will be removed. + override fun invoke(args: Array): SymbolValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return symbolValue(arg0 + arg1) } } @@ -65,7 +79,9 @@ internal object Fn_CONCAT__CLOB_CLOB__CLOB : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function concat not implemented") + override fun invoke(args: Array): ClobValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return clobValue(arg0 + arg1) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnDivide.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnDivide.kt index 325201b309..7431060ccd 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnDivide.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnDivide.kt @@ -7,6 +7,14 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.DecimalValue +import org.partiql.value.Float32Value +import org.partiql.value.Float64Value +import org.partiql.value.Int16Value +import org.partiql.value.Int32Value +import org.partiql.value.Int64Value +import org.partiql.value.Int8Value +import org.partiql.value.IntValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY @@ -17,6 +25,15 @@ import org.partiql.value.PartiQLValueType.INT16 import org.partiql.value.PartiQLValueType.INT32 import org.partiql.value.PartiQLValueType.INT64 import org.partiql.value.PartiQLValueType.INT8 +import org.partiql.value.check +import org.partiql.value.decimalValue +import org.partiql.value.float32Value +import org.partiql.value.float64Value +import org.partiql.value.int16Value +import org.partiql.value.int32Value +import org.partiql.value.int64Value +import org.partiql.value.int8Value +import org.partiql.value.intValue @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_DIVIDE__INT8_INT8__INT8 : PartiQLFunction.Scalar { @@ -32,8 +49,10 @@ internal object Fn_DIVIDE__INT8_INT8__INT8 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): Int8Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int8Value((arg0 / arg1).toByte()) } } @@ -51,8 +70,10 @@ internal object Fn_DIVIDE__INT16_INT16__INT16 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): Int16Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int16Value((arg0 / arg1).toShort()) } } @@ -70,8 +91,10 @@ internal object Fn_DIVIDE__INT32_INT32__INT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): Int32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int32Value(arg0 / arg1) } } @@ -89,8 +112,10 @@ internal object Fn_DIVIDE__INT64_INT64__INT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): Int64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int64Value(arg0 / arg1) } } @@ -108,8 +133,10 @@ internal object Fn_DIVIDE__INT_INT__INT : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): IntValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return intValue(arg0 / arg1) } } @@ -127,8 +154,10 @@ internal object Fn_DIVIDE__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRAR isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): DecimalValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return decimalValue(arg0 / arg1) } } @@ -146,8 +175,10 @@ internal object Fn_DIVIDE__FLOAT32_FLOAT32__FLOAT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): Float32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float32Value(arg0 / arg1) } } @@ -165,7 +196,9 @@ internal object Fn_DIVIDE__FLOAT64_FLOAT64__FLOAT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function divide not implemented") + override fun invoke(args: Array): Float64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float64Value(arg0 / arg1) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnMinus.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnMinus.kt index 497f207ad2..de1df5129c 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnMinus.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnMinus.kt @@ -7,6 +7,14 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.DecimalValue +import org.partiql.value.Float32Value +import org.partiql.value.Float64Value +import org.partiql.value.Int16Value +import org.partiql.value.Int32Value +import org.partiql.value.Int64Value +import org.partiql.value.Int8Value +import org.partiql.value.IntValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY @@ -17,6 +25,15 @@ import org.partiql.value.PartiQLValueType.INT16 import org.partiql.value.PartiQLValueType.INT32 import org.partiql.value.PartiQLValueType.INT64 import org.partiql.value.PartiQLValueType.INT8 +import org.partiql.value.check +import org.partiql.value.decimalValue +import org.partiql.value.float32Value +import org.partiql.value.float64Value +import org.partiql.value.int16Value +import org.partiql.value.int32Value +import org.partiql.value.int64Value +import org.partiql.value.int8Value +import org.partiql.value.intValue @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_MINUS__INT8_INT8__INT8 : PartiQLFunction.Scalar { @@ -32,8 +49,10 @@ internal object Fn_MINUS__INT8_INT8__INT8 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): Int8Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int8Value((arg0 - arg1).toByte()) } } @@ -51,8 +70,10 @@ internal object Fn_MINUS__INT16_INT16__INT16 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): Int16Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int16Value((arg0 - arg1).toShort()) } } @@ -70,8 +91,10 @@ internal object Fn_MINUS__INT32_INT32__INT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): Int32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int32Value(arg0 - arg1) } } @@ -89,8 +112,10 @@ internal object Fn_MINUS__INT64_INT64__INT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): Int64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int64Value(arg0 - arg1) } } @@ -108,8 +133,10 @@ internal object Fn_MINUS__INT_INT__INT : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): IntValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return intValue(arg0 - arg1) } } @@ -127,8 +154,10 @@ internal object Fn_MINUS__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRARY isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): DecimalValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return decimalValue(arg0 - arg1) } } @@ -146,8 +175,10 @@ internal object Fn_MINUS__FLOAT32_FLOAT32__FLOAT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): Float32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float32Value(arg0 - arg1) } } @@ -165,7 +196,9 @@ internal object Fn_MINUS__FLOAT64_FLOAT64__FLOAT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function minus not implemented") + override fun invoke(args: Array): Float64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float64Value(arg0 - arg1) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnModulo.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnModulo.kt index b4ff8aa139..dfe59962e8 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnModulo.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnModulo.kt @@ -7,6 +7,14 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.DecimalValue +import org.partiql.value.Float32Value +import org.partiql.value.Float64Value +import org.partiql.value.Int16Value +import org.partiql.value.Int32Value +import org.partiql.value.Int64Value +import org.partiql.value.Int8Value +import org.partiql.value.IntValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY @@ -17,6 +25,15 @@ import org.partiql.value.PartiQLValueType.INT16 import org.partiql.value.PartiQLValueType.INT32 import org.partiql.value.PartiQLValueType.INT64 import org.partiql.value.PartiQLValueType.INT8 +import org.partiql.value.check +import org.partiql.value.decimalValue +import org.partiql.value.float32Value +import org.partiql.value.float64Value +import org.partiql.value.int16Value +import org.partiql.value.int32Value +import org.partiql.value.int64Value +import org.partiql.value.int8Value +import org.partiql.value.intValue @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_MODULO__INT8_INT8__INT8 : PartiQLFunction.Scalar { @@ -32,8 +49,11 @@ internal object Fn_MODULO__INT8_INT8__INT8 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): Int8Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int8Value((arg0 % arg1).toByte()) } } @@ -51,8 +71,11 @@ internal object Fn_MODULO__INT16_INT16__INT16 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): Int16Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int16Value((arg0 % arg1).toShort()) } } @@ -70,8 +93,11 @@ internal object Fn_MODULO__INT32_INT32__INT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): Int32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int32Value(arg0 % arg1) } } @@ -89,8 +115,11 @@ internal object Fn_MODULO__INT64_INT64__INT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): Int64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int64Value(arg0 % arg1) } } @@ -108,8 +137,11 @@ internal object Fn_MODULO__INT_INT__INT : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): IntValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return intValue(arg0 % arg1) } } @@ -127,8 +159,11 @@ internal object Fn_MODULO__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRAR isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): DecimalValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return decimalValue(arg0 % arg1) } } @@ -146,8 +181,11 @@ internal object Fn_MODULO__FLOAT32_FLOAT32__FLOAT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): Float32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float32Value(arg0 % arg1) } } @@ -165,7 +203,10 @@ internal object Fn_MODULO__FLOAT64_FLOAT64__FLOAT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function modulo not implemented") + // TODO: This is untested and may be wrong. Java's mod operation does not match SQL's. + override fun invoke(args: Array): Float64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float64Value(arg0 % arg1) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNeg.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNeg.kt index ae072fabde..d6a691d703 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNeg.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNeg.kt @@ -7,6 +7,14 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.DecimalValue +import org.partiql.value.Float32Value +import org.partiql.value.Float64Value +import org.partiql.value.Int16Value +import org.partiql.value.Int32Value +import org.partiql.value.Int64Value +import org.partiql.value.Int8Value +import org.partiql.value.IntValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY @@ -17,6 +25,15 @@ import org.partiql.value.PartiQLValueType.INT16 import org.partiql.value.PartiQLValueType.INT32 import org.partiql.value.PartiQLValueType.INT64 import org.partiql.value.PartiQLValueType.INT8 +import org.partiql.value.check +import org.partiql.value.decimalValue +import org.partiql.value.float32Value +import org.partiql.value.float64Value +import org.partiql.value.int16Value +import org.partiql.value.int32Value +import org.partiql.value.int64Value +import org.partiql.value.int8Value +import org.partiql.value.intValue @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_NEG__INT8__INT8 : PartiQLFunction.Scalar { @@ -29,8 +46,9 @@ internal object Fn_NEG__INT8__INT8 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): Int8Value { + val value = args[0].check().value!! + return int8Value(value.times(-1).toByte()) } } @@ -45,8 +63,9 @@ internal object Fn_NEG__INT16__INT16 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): Int16Value { + val value = args[0].check().value!! + return int16Value(value.times(-1).toShort()) } } @@ -61,8 +80,9 @@ internal object Fn_NEG__INT32__INT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): Int32Value { + val value = args[0].check().value!! + return int32Value(value.times(-1)) } } @@ -77,8 +97,9 @@ internal object Fn_NEG__INT64__INT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): Int64Value { + val value = args[0].check().value!! + return int64Value(value.times(-1L)) } } @@ -93,8 +114,9 @@ internal object Fn_NEG__INT__INT : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): IntValue { + val value = args[0].check().value!! + return intValue(value.negate()) } } @@ -109,8 +131,9 @@ internal object Fn_NEG__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY : PartiQLFunction.S isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): DecimalValue { + val value = args[0].check().value!! + return decimalValue(value.negate()) } } @@ -125,8 +148,9 @@ internal object Fn_NEG__FLOAT32__FLOAT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): Float32Value { + val value = args[0].check().value!! + return float32Value(value.times(-1)) } } @@ -141,7 +165,8 @@ internal object Fn_NEG__FLOAT64__FLOAT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function neg not implemented") + override fun invoke(args: Array): Float64Value { + val value = args[0].check().value!! + return float64Value(value.times(-1)) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNot.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNot.kt index 9615880a50..3344ce6c9a 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNot.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnNot.kt @@ -29,11 +29,7 @@ internal object Fn_NOT__BOOL__BOOL : PartiQLFunction.Scalar { override fun invoke(args: Array): PartiQLValue { val value = args[0].check().value - return if (value == null) { - boolValue(null) - } else { - boolValue(!value) - } + return boolValue(value!!.not()) } } @@ -45,7 +41,7 @@ internal object Fn_NOT__MISSING__BOOL : PartiQLFunction.Scalar { returns = BOOL, parameters = listOf(FunctionParameter("value", MISSING)), isNullCall = true, - isNullable = false, + isNullable = true, ) // TODO determine what this behavior should be diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnOr.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnOr.kt index 08aaa72c39..4418d4a400 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnOr.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnOr.kt @@ -7,10 +7,13 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.BoolValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.BOOL import org.partiql.value.PartiQLValueType.MISSING +import org.partiql.value.boolValue +import org.partiql.value.check @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_OR__BOOL_BOOL__BOOL : PartiQLFunction.Scalar { @@ -26,8 +29,15 @@ internal object Fn_OR__BOOL_BOOL__BOOL : PartiQLFunction.Scalar { isNullable = true, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function or not implemented") + override fun invoke(args: Array): BoolValue { + val lhs = args[0].check().value + val rhs = args[1].check().value + val toReturn = when { + lhs == true || rhs == true -> true + lhs == null || rhs == null -> null + else -> false + } + return boolValue(toReturn) } } @@ -46,7 +56,11 @@ internal object Fn_OR__MISSING_BOOL__BOOL : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function or not implemented") + val rhs = args[1].check().value + return when (rhs) { + true -> boolValue(true) + else -> boolValue(null) + } } } @@ -65,7 +79,11 @@ internal object Fn_OR__BOOL_MISSING__BOOL : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function or not implemented") + val lhs = args[0].check().value + return when (lhs) { + true -> boolValue(true) + else -> boolValue(null) + } } } @@ -84,6 +102,6 @@ internal object Fn_OR__MISSING_MISSING__BOOL : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function or not implemented") + return boolValue(null) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPlus.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPlus.kt index bd2dc156da..5d282b36da 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPlus.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPlus.kt @@ -7,6 +7,14 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.DecimalValue +import org.partiql.value.Float32Value +import org.partiql.value.Float64Value +import org.partiql.value.Int16Value +import org.partiql.value.Int32Value +import org.partiql.value.Int64Value +import org.partiql.value.Int8Value +import org.partiql.value.IntValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY @@ -17,6 +25,15 @@ import org.partiql.value.PartiQLValueType.INT16 import org.partiql.value.PartiQLValueType.INT32 import org.partiql.value.PartiQLValueType.INT64 import org.partiql.value.PartiQLValueType.INT8 +import org.partiql.value.check +import org.partiql.value.decimalValue +import org.partiql.value.float32Value +import org.partiql.value.float64Value +import org.partiql.value.int16Value +import org.partiql.value.int32Value +import org.partiql.value.int64Value +import org.partiql.value.int8Value +import org.partiql.value.intValue @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_PLUS__INT8_INT8__INT8 : PartiQLFunction.Scalar { @@ -32,8 +49,10 @@ internal object Fn_PLUS__INT8_INT8__INT8 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): Int8Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int8Value((arg0 + arg1).toByte()) } } @@ -51,8 +70,10 @@ internal object Fn_PLUS__INT16_INT16__INT16 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): Int16Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int16Value((arg0 + arg1).toShort()) } } @@ -70,8 +91,10 @@ internal object Fn_PLUS__INT32_INT32__INT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): Int32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int32Value(arg0 + arg1) } } @@ -89,8 +112,10 @@ internal object Fn_PLUS__INT64_INT64__INT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): Int64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int64Value(arg0 + arg1) } } @@ -108,8 +133,10 @@ internal object Fn_PLUS__INT_INT__INT : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): IntValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return intValue(arg0 + arg1) } } @@ -127,8 +154,10 @@ internal object Fn_PLUS__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRARY isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): DecimalValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return decimalValue(arg0 + arg1) } } @@ -146,8 +175,10 @@ internal object Fn_PLUS__FLOAT32_FLOAT32__FLOAT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): Float32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float32Value(arg0 + arg1) } } @@ -165,7 +196,9 @@ internal object Fn_PLUS__FLOAT64_FLOAT64__FLOAT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function plus not implemented") + override fun invoke(args: Array): Float64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float64Value(arg0 + arg1) } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPos.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPos.kt index df0df54663..8a5344d8cd 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPos.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnPos.kt @@ -30,7 +30,7 @@ internal object Fn_POS__INT8__INT8 : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } @@ -46,7 +46,7 @@ internal object Fn_POS__INT16__INT16 : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } @@ -62,7 +62,7 @@ internal object Fn_POS__INT32__INT32 : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } @@ -78,7 +78,7 @@ internal object Fn_POS__INT64__INT64 : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } @@ -94,7 +94,7 @@ internal object Fn_POS__INT__INT : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } @@ -110,7 +110,7 @@ internal object Fn_POS__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY : PartiQLFunction.S ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } @@ -126,7 +126,7 @@ internal object Fn_POS__FLOAT32__FLOAT32 : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } @@ -142,6 +142,6 @@ internal object Fn_POS__FLOAT64__FLOAT64 : PartiQLFunction.Scalar { ) override fun invoke(args: Array): PartiQLValue { - TODO("Function pos not implemented") + return args[0] } } diff --git a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnTimes.kt b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnTimes.kt index 589e98fb11..5d11700fb0 100644 --- a/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnTimes.kt +++ b/plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnTimes.kt @@ -7,6 +7,14 @@ import org.partiql.spi.function.PartiQLFunction import org.partiql.spi.function.PartiQLFunctionExperimental import org.partiql.types.function.FunctionParameter import org.partiql.types.function.FunctionSignature +import org.partiql.value.DecimalValue +import org.partiql.value.Float32Value +import org.partiql.value.Float64Value +import org.partiql.value.Int16Value +import org.partiql.value.Int32Value +import org.partiql.value.Int64Value +import org.partiql.value.Int8Value +import org.partiql.value.IntValue import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY @@ -17,6 +25,15 @@ import org.partiql.value.PartiQLValueType.INT16 import org.partiql.value.PartiQLValueType.INT32 import org.partiql.value.PartiQLValueType.INT64 import org.partiql.value.PartiQLValueType.INT8 +import org.partiql.value.check +import org.partiql.value.decimalValue +import org.partiql.value.float32Value +import org.partiql.value.float64Value +import org.partiql.value.int16Value +import org.partiql.value.int32Value +import org.partiql.value.int64Value +import org.partiql.value.int8Value +import org.partiql.value.intValue @OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class) internal object Fn_TIMES__INT8_INT8__INT8 : PartiQLFunction.Scalar { @@ -32,8 +49,10 @@ internal object Fn_TIMES__INT8_INT8__INT8 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): Int8Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int8Value((arg0 * arg1).toByte()) } } @@ -51,8 +70,10 @@ internal object Fn_TIMES__INT16_INT16__INT16 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): Int16Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int16Value((arg0 * arg1).toShort()) } } @@ -70,8 +91,10 @@ internal object Fn_TIMES__INT32_INT32__INT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): Int32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int32Value(arg0.times(arg1)) } } @@ -89,8 +112,10 @@ internal object Fn_TIMES__INT64_INT64__INT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): Int64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return int64Value(arg0.times(arg1)) } } @@ -108,8 +133,10 @@ internal object Fn_TIMES__INT_INT__INT : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): IntValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return intValue(arg0.times(arg1)) } } @@ -127,8 +154,10 @@ internal object Fn_TIMES__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRARY isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): DecimalValue { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return decimalValue(arg0.times(arg1)) } } @@ -146,8 +175,10 @@ internal object Fn_TIMES__FLOAT32_FLOAT32__FLOAT32 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): Float32Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float32Value(arg0 * arg1) } } @@ -165,7 +196,9 @@ internal object Fn_TIMES__FLOAT64_FLOAT64__FLOAT64 : PartiQLFunction.Scalar { isNullable = false, ) - override fun invoke(args: Array): PartiQLValue { - TODO("Function times not implemented") + override fun invoke(args: Array): Float64Value { + val arg0 = args[0].check().value!! + val arg1 = args[1].check().value!! + return float64Value(arg0 * arg1) } } diff --git a/plugins/partiql-plugin/src/test/kotlin/org/partiql/plugin/PartiQLHeader.kt b/plugins/partiql-plugin/src/test/kotlin/org/partiql/plugin/PartiQLHeader.kt index 5f2670ba15..b0229ee92a 100644 --- a/plugins/partiql-plugin/src/test/kotlin/org/partiql/plugin/PartiQLHeader.kt +++ b/plugins/partiql-plugin/src/test/kotlin/org/partiql/plugin/PartiQLHeader.kt @@ -224,7 +224,7 @@ internal object PartiQLHeader : Header() { name = "not", returns = BOOL, isNullCall = true, - isNullable = false, + isNullable = true, parameters = listOf(FunctionParameter("value", MISSING)), ), )