Skip to content

Commit

Permalink
Merge pull request #1325 from partiql/operator-impls
Browse files Browse the repository at this point in the history
Adds unary, logical, binary arithmetic, and concat operators
  • Loading branch information
johnedquinn authored Jan 5, 2024
2 parents b9b8b86 + 7cf19fa commit c5dae43
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,7 +30,14 @@ internal object Fn_AND__BOOL_BOOL__BOOL : PartiQLFunction.Scalar {
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function and not implemented")
val lhs = args[0].check<BoolValue>().value
val rhs = args[1].check<BoolValue>().value
val toReturn = when {
lhs == false || rhs == false -> false
lhs == null || rhs == null -> null
else -> true
}
return boolValue(toReturn)
}
}

Expand All @@ -46,7 +56,11 @@ internal object Fn_AND__MISSING_BOOL__BOOL : PartiQLFunction.Scalar {
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function and not implemented")
val rhs = args[1].check<BoolValue>().value
return when (rhs) {
false -> boolValue(false)
else -> boolValue(null)
}
}
}

Expand All @@ -65,7 +79,11 @@ internal object Fn_AND__BOOL_MISSING__BOOL : PartiQLFunction.Scalar {
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function and not implemented")
val lhs = args[0].check<BoolValue>().value
return when (lhs) {
false -> boolValue(false)
else -> boolValue(null)
}
}
}

Expand All @@ -84,6 +102,6 @@ internal object Fn_AND__MISSING_MISSING__BOOL : PartiQLFunction.Scalar {
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function and not implemented")
return boolValue(null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ 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
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 {
Expand All @@ -29,8 +41,10 @@ internal object Fn_BITWISE_AND__INT8_INT8__INT8 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function bitwise_and not implemented")
override fun invoke(args: Array<PartiQLValue>): Int8Value {
val arg0 = args[0].check<Int8Value>().value!!
val arg1 = args[1].check<Int8Value>().value!!
return int8Value(arg0 and arg1)
}
}

Expand All @@ -48,8 +62,10 @@ internal object Fn_BITWISE_AND__INT16_INT16__INT16 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function bitwise_and not implemented")
override fun invoke(args: Array<PartiQLValue>): Int16Value {
val arg0 = args[0].check<Int16Value>().value!!
val arg1 = args[1].check<Int16Value>().value!!
return int16Value(arg0 and arg1)
}
}

Expand All @@ -67,8 +83,10 @@ internal object Fn_BITWISE_AND__INT32_INT32__INT32 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function bitwise_and not implemented")
override fun invoke(args: Array<PartiQLValue>): Int32Value {
val arg0 = args[0].check<Int32Value>().value!!
val arg1 = args[1].check<Int32Value>().value!!
return int32Value(arg0 and arg1)
}
}

Expand All @@ -86,8 +104,10 @@ internal object Fn_BITWISE_AND__INT64_INT64__INT64 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function bitwise_and not implemented")
override fun invoke(args: Array<PartiQLValue>): Int64Value {
val arg0 = args[0].check<Int64Value>().value!!
val arg1 = args[1].check<Int64Value>().value!!
return int64Value(arg0 and arg1)
}
}

Expand All @@ -105,7 +125,9 @@ internal object Fn_BITWISE_AND__INT_INT__INT : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function bitwise_and not implemented")
override fun invoke(args: Array<PartiQLValue>): IntValue {
val arg0 = args[0].check<IntValue>().value!!
val arg1 = args[1].check<IntValue>().value!!
return intValue(arg0 and arg1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,8 +34,11 @@ internal object Fn_CONCAT__STRING_STRING__STRING : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function concat not implemented")
override fun invoke(args: Array<PartiQLValue>): StringValue {

val arg0 = args[0].check<StringValue>().value!!
val arg1 = args[1].check<StringValue>().value!!
return stringValue(arg0 + arg1)
}
}

Expand All @@ -46,8 +56,12 @@ internal object Fn_CONCAT__SYMBOL_SYMBOL__SYMBOL : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): 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<PartiQLValue>): SymbolValue {
val arg0 = args[0].check<SymbolValue>().value!!
val arg1 = args[1].check<SymbolValue>().value!!
return symbolValue(arg0 + arg1)
}
}

Expand All @@ -65,7 +79,9 @@ internal object Fn_CONCAT__CLOB_CLOB__CLOB : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function concat not implemented")
override fun invoke(args: Array<PartiQLValue>): ClobValue {
val arg0 = args[0].check<ClobValue>().value!!
val arg1 = args[1].check<ClobValue>().value!!
return clobValue(arg0 + arg1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -32,8 +49,10 @@ internal object Fn_DIVIDE__INT8_INT8__INT8 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): Int8Value {
val arg0 = args[0].check<Int8Value>().value!!
val arg1 = args[1].check<Int8Value>().value!!
return int8Value((arg0 / arg1).toByte())
}
}

Expand All @@ -51,8 +70,10 @@ internal object Fn_DIVIDE__INT16_INT16__INT16 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): Int16Value {
val arg0 = args[0].check<Int16Value>().value!!
val arg1 = args[1].check<Int16Value>().value!!
return int16Value((arg0 / arg1).toShort())
}
}

Expand All @@ -70,8 +91,10 @@ internal object Fn_DIVIDE__INT32_INT32__INT32 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): Int32Value {
val arg0 = args[0].check<Int32Value>().value!!
val arg1 = args[1].check<Int32Value>().value!!
return int32Value(arg0 / arg1)
}
}

Expand All @@ -89,8 +112,10 @@ internal object Fn_DIVIDE__INT64_INT64__INT64 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): Int64Value {
val arg0 = args[0].check<Int64Value>().value!!
val arg1 = args[1].check<Int64Value>().value!!
return int64Value(arg0 / arg1)
}
}

Expand All @@ -108,8 +133,10 @@ internal object Fn_DIVIDE__INT_INT__INT : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): IntValue {
val arg0 = args[0].check<IntValue>().value!!
val arg1 = args[1].check<IntValue>().value!!
return intValue(arg0 / arg1)
}
}

Expand All @@ -127,8 +154,10 @@ internal object Fn_DIVIDE__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRAR
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): DecimalValue {
val arg0 = args[0].check<DecimalValue>().value!!
val arg1 = args[1].check<DecimalValue>().value!!
return decimalValue(arg0 / arg1)
}
}

Expand All @@ -146,8 +175,10 @@ internal object Fn_DIVIDE__FLOAT32_FLOAT32__FLOAT32 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): Float32Value {
val arg0 = args[0].check<Float32Value>().value!!
val arg1 = args[1].check<Float32Value>().value!!
return float32Value(arg0 / arg1)
}
}

Expand All @@ -165,7 +196,9 @@ internal object Fn_DIVIDE__FLOAT64_FLOAT64__FLOAT64 : PartiQLFunction.Scalar {
isNullable = false,
)

override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
TODO("Function divide not implemented")
override fun invoke(args: Array<PartiQLValue>): Float64Value {
val arg0 = args[0].check<Float64Value>().value!!
val arg1 = args[1].check<Float64Value>().value!!
return float64Value(arg0 / arg1)
}
}
Loading

0 comments on commit c5dae43

Please sign in to comment.