Search in sources :

Example 1 with SUBTRACT

use of io.trino.spi.function.OperatorType.SUBTRACT in project trino by trinodb.

the class DecimalOperators method decimalSubtractOperator.

private static SqlScalarFunction decimalSubtractOperator() {
    TypeSignature decimalLeftSignature = new TypeSignature("decimal", typeVariable("a_precision"), typeVariable("a_scale"));
    TypeSignature decimalRightSignature = new TypeSignature("decimal", typeVariable("b_precision"), typeVariable("b_scale"));
    TypeSignature decimalResultSignature = new TypeSignature("decimal", typeVariable("r_precision"), typeVariable("r_scale"));
    Signature signature = Signature.builder().operatorType(SUBTRACT).longVariableConstraints(longVariableExpression("r_precision", "min(38, max(a_precision - a_scale, b_precision - b_scale) + max(a_scale, b_scale) + 1)"), longVariableExpression("r_scale", "max(a_scale, b_scale)")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature).build();
    return new PolymorphicScalarFunctionBuilder(DecimalOperators.class).signature(signature).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("subtractShortShortShort").withExtraParameters(DecimalOperators::calculateShortRescaleParameters)).implementation(methodsGroup -> methodsGroup.methods("subtractShortShortLong", "subtractLongLongLong", "subtractShortLongLong", "subtractLongShortLong").withExtraParameters(DecimalOperators::calculateLongRescaleParameters))).build();
}
Also used : MODULUS(io.trino.spi.function.OperatorType.MODULUS) PolymorphicScalarFunctionBuilder(io.trino.metadata.PolymorphicScalarFunctionBuilder) Int128Math.add(io.trino.spi.type.Int128Math.add) Int128Math.subtract(io.trino.spi.type.Int128Math.subtract) TypeSignatureParameter.typeVariable(io.trino.spi.type.TypeSignatureParameter.typeVariable) Int128Math.remainder(io.trino.spi.type.Int128Math.remainder) LiteralParameters(io.trino.spi.function.LiteralParameters) Int128Math.multiply(io.trino.spi.type.Int128Math.multiply) Math.abs(java.lang.Math.abs) SUBTRACT(io.trino.spi.function.OperatorType.SUBTRACT) Int128Math.divideRoundUp(io.trino.spi.type.Int128Math.divideRoundUp) ImmutableList(com.google.common.collect.ImmutableList) SignatureBuilder(io.trino.metadata.SignatureBuilder) SqlType(io.trino.spi.function.SqlType) Objects.requireNonNull(java.util.Objects.requireNonNull) Signature.longVariableExpression(io.trino.metadata.Signature.longVariableExpression) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.trino.metadata.Signature) NUMERIC_VALUE_OUT_OF_RANGE(io.trino.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE) TypeSignature(io.trino.spi.type.TypeSignature) Long.signum(java.lang.Long.signum) Int128(io.trino.spi.type.Int128) NEGATION(io.trino.spi.function.OperatorType.NEGATION) Decimals.longTenToNth(io.trino.spi.type.Decimals.longTenToNth) ScalarOperator(io.trino.spi.function.ScalarOperator) DIVIDE(io.trino.spi.function.OperatorType.DIVIDE) TrinoException(io.trino.spi.TrinoException) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) DIVISION_BY_ZERO(io.trino.spi.StandardErrorCode.DIVISION_BY_ZERO) SpecializeContext(io.trino.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext) Int128Math.rescale(io.trino.spi.type.Int128Math.rescale) Integer.max(java.lang.Integer.max) List(java.util.List) Int128Math.negateExact(io.trino.spi.type.Int128Math.negateExact) ADD(io.trino.spi.function.OperatorType.ADD) MULTIPLY(io.trino.spi.function.OperatorType.MULTIPLY) Decimals(io.trino.spi.type.Decimals) DecimalType(io.trino.spi.type.DecimalType) TypeSignature(io.trino.spi.type.TypeSignature) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) PolymorphicScalarFunctionBuilder(io.trino.metadata.PolymorphicScalarFunctionBuilder)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)1 PolymorphicScalarFunctionBuilder (io.trino.metadata.PolymorphicScalarFunctionBuilder)1 SpecializeContext (io.trino.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)1 Signature (io.trino.metadata.Signature)1 Signature.longVariableExpression (io.trino.metadata.Signature.longVariableExpression)1 SignatureBuilder (io.trino.metadata.SignatureBuilder)1 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)1 DIVISION_BY_ZERO (io.trino.spi.StandardErrorCode.DIVISION_BY_ZERO)1 NUMERIC_VALUE_OUT_OF_RANGE (io.trino.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE)1 TrinoException (io.trino.spi.TrinoException)1 LiteralParameters (io.trino.spi.function.LiteralParameters)1 ADD (io.trino.spi.function.OperatorType.ADD)1 DIVIDE (io.trino.spi.function.OperatorType.DIVIDE)1 MODULUS (io.trino.spi.function.OperatorType.MODULUS)1 MULTIPLY (io.trino.spi.function.OperatorType.MULTIPLY)1 NEGATION (io.trino.spi.function.OperatorType.NEGATION)1 SUBTRACT (io.trino.spi.function.OperatorType.SUBTRACT)1 ScalarOperator (io.trino.spi.function.ScalarOperator)1 SqlType (io.trino.spi.function.SqlType)1