Search in sources :

Example 1 with SUBTRACT

use of com.facebook.presto.common.function.OperatorType.SUBTRACT in project presto by prestodb.

the class DecimalOperators method decimalSubtractOperator.

private static SqlScalarFunction decimalSubtractOperator() {
    TypeSignature decimalLeftSignature = parseTypeSignature("decimal(a_precision, a_scale)", ImmutableSet.of("a_precision", "a_scale"));
    TypeSignature decimalRightSignature = parseTypeSignature("decimal(b_precision, b_scale)", ImmutableSet.of("b_precision", "b_scale"));
    TypeSignature decimalResultSignature = parseTypeSignature("decimal(r_precision, r_scale)", ImmutableSet.of("r_precision", "r_scale"));
    Signature signature = SignatureBuilder.builder().kind(SCALAR).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 SqlScalarFunction.builder(DecimalOperators.class, SUBTRACT).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 : SUBTRACT(com.facebook.presto.common.function.OperatorType.SUBTRACT) INDETERMINATE(com.facebook.presto.common.function.OperatorType.INDETERMINATE) UnscaledDecimal128Arithmetic.throwIfOverflows(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.throwIfOverflows) UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong) Math.abs(java.lang.Math.abs) TypeSignature(com.facebook.presto.common.type.TypeSignature) ADD(com.facebook.presto.common.function.OperatorType.ADD) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) DIVIDE(com.facebook.presto.common.function.OperatorType.DIVIDE) BigInteger(java.math.BigInteger) LiteralParameters(com.facebook.presto.spi.function.LiteralParameters) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode) Long.signum(java.lang.Long.signum) HASH_CODE(com.facebook.presto.common.function.OperatorType.HASH_CODE) ImmutableSet(com.google.common.collect.ImmutableSet) UnscaledDecimal128Arithmetic.remainder(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.remainder) NEGATION(com.facebook.presto.common.function.OperatorType.NEGATION) UnscaledDecimal128Arithmetic.rescale(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.rescale) SCALAR(com.facebook.presto.spi.function.FunctionKind.SCALAR) List(java.util.List) UnscaledDecimal128Arithmetic(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic) PolymorphicScalarFunctionBuilder(com.facebook.presto.metadata.PolymorphicScalarFunctionBuilder) SqlType(com.facebook.presto.spi.function.SqlType) StandardTypes(com.facebook.presto.common.type.StandardTypes) DecimalType(com.facebook.presto.common.type.DecimalType) Slice(io.airlift.slice.Slice) DIVISION_BY_ZERO(com.facebook.presto.spi.StandardErrorCode.DIVISION_BY_ZERO) Decimals.encodeUnscaledValue(com.facebook.presto.common.type.Decimals.encodeUnscaledValue) MULTIPLY(com.facebook.presto.common.function.OperatorType.MULTIPLY) PrestoException(com.facebook.presto.spi.PrestoException) UnscaledDecimal128Arithmetic.isZero(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.isZero) ImmutableList(com.google.common.collect.ImmutableList) UnscaledDecimal128Arithmetic.divideRoundUp(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.divideRoundUp) UnscaledDecimal128Arithmetic.unscaledDecimal(com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.unscaledDecimal) Objects.requireNonNull(java.util.Objects.requireNonNull) Math.toIntExact(java.lang.Math.toIntExact) Decimals.longTenToNth(com.facebook.presto.common.type.Decimals.longTenToNth) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) Signature.longVariableExpression(com.facebook.presto.spi.function.Signature.longVariableExpression) XxHash64(io.airlift.slice.XxHash64) Decimals(com.facebook.presto.common.type.Decimals) SpecializeContext(com.facebook.presto.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext) Integer.max(java.lang.Integer.max) NUMERIC_VALUE_OUT_OF_RANGE(com.facebook.presto.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) IsNull(com.facebook.presto.spi.function.IsNull) Signature(com.facebook.presto.spi.function.Signature) MODULUS(com.facebook.presto.common.function.OperatorType.MODULUS) SignatureBuilder(com.facebook.presto.metadata.SignatureBuilder) XX_HASH_64(com.facebook.presto.common.function.OperatorType.XX_HASH_64) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature)

Aggregations

UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)1 ADD (com.facebook.presto.common.function.OperatorType.ADD)1 DIVIDE (com.facebook.presto.common.function.OperatorType.DIVIDE)1 HASH_CODE (com.facebook.presto.common.function.OperatorType.HASH_CODE)1 INDETERMINATE (com.facebook.presto.common.function.OperatorType.INDETERMINATE)1 MODULUS (com.facebook.presto.common.function.OperatorType.MODULUS)1 MULTIPLY (com.facebook.presto.common.function.OperatorType.MULTIPLY)1 NEGATION (com.facebook.presto.common.function.OperatorType.NEGATION)1 SUBTRACT (com.facebook.presto.common.function.OperatorType.SUBTRACT)1 XX_HASH_64 (com.facebook.presto.common.function.OperatorType.XX_HASH_64)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 Decimals (com.facebook.presto.common.type.Decimals)1 Decimals.encodeUnscaledValue (com.facebook.presto.common.type.Decimals.encodeUnscaledValue)1 Decimals.longTenToNth (com.facebook.presto.common.type.Decimals.longTenToNth)1 StandardTypes (com.facebook.presto.common.type.StandardTypes)1 TypeSignature (com.facebook.presto.common.type.TypeSignature)1 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)1 UnscaledDecimal128Arithmetic (com.facebook.presto.common.type.UnscaledDecimal128Arithmetic)1 UnscaledDecimal128Arithmetic.divideRoundUp (com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.divideRoundUp)1 UnscaledDecimal128Arithmetic.isZero (com.facebook.presto.common.type.UnscaledDecimal128Arithmetic.isZero)1