Search in sources :

Example 1 with MULTIPLY

use of com.facebook.presto.spi.function.OperatorType.MULTIPLY in project presto by prestodb.

the class DecimalOperators method decimalMultiplyOperator.

private static SqlScalarFunction decimalMultiplyOperator() {
    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 = Signature.builder().kind(SCALAR).operatorType(MULTIPLY).longVariableConstraints(longVariableExpression("r_precision", "min(38, a_precision + b_precision)"), longVariableExpression("r_scale", "a_scale + b_scale")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature).build();
    return SqlScalarFunction.builder(DecimalOperators.class).signature(signature).implementation(b -> b.methods("multiplyShortShortShort", "multiplyShortShortLong", "multiplyLongLongLong", "multiplyShortLongLong", "multiplyLongShortLong")).build();
}
Also used : SpecializeContext(com.facebook.presto.metadata.SqlScalarFunctionBuilder.SpecializeContext) TypeSignature(com.facebook.presto.spi.type.TypeSignature) UnscaledDecimal128Arithmetic.rescale(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.rescale) MULTIPLY(com.facebook.presto.spi.function.OperatorType.MULTIPLY) Slice(io.airlift.slice.Slice) UnscaledDecimal128Arithmetic.divideRoundUp(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.divideRoundUp) UnscaledDecimal128Arithmetic.throwIfOverflows(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.throwIfOverflows) DIVISION_BY_ZERO(com.facebook.presto.spi.StandardErrorCode.DIVISION_BY_ZERO) HASH_CODE(com.facebook.presto.spi.function.OperatorType.HASH_CODE) Decimals.encodeUnscaledValue(com.facebook.presto.spi.type.Decimals.encodeUnscaledValue) UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong) Math.abs(java.lang.Math.abs) PrestoException(com.facebook.presto.spi.PrestoException) SCALAR(com.facebook.presto.metadata.FunctionKind.SCALAR) Signature.longVariableExpression(com.facebook.presto.metadata.Signature.longVariableExpression) MODULUS(com.facebook.presto.spi.function.OperatorType.MODULUS) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) DecimalType(com.facebook.presto.spi.type.DecimalType) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) BigInteger(java.math.BigInteger) Math.toIntExact(java.lang.Math.toIntExact) LiteralParameters(com.facebook.presto.spi.function.LiteralParameters) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode) UnscaledDecimal128Arithmetic(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic) Long.signum(java.lang.Long.signum) Decimals(com.facebook.presto.spi.type.Decimals) ImmutableSet(com.google.common.collect.ImmutableSet) DIVIDE(com.facebook.presto.spi.function.OperatorType.DIVIDE) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) Signature(com.facebook.presto.metadata.Signature) UnscaledDecimal128Arithmetic.isZero(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.isZero) UnscaledDecimal128Arithmetic.unscaledDecimal(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimal) NEGATION(com.facebook.presto.spi.function.OperatorType.NEGATION) Integer.max(java.lang.Integer.max) List(java.util.List) NUMERIC_VALUE_OUT_OF_RANGE(com.facebook.presto.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE) UnscaledDecimal128Arithmetic.remainder(com.facebook.presto.spi.type.UnscaledDecimal128Arithmetic.remainder) SqlScalarFunctionBuilder(com.facebook.presto.metadata.SqlScalarFunctionBuilder) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) SignatureBuilder(com.facebook.presto.metadata.SignatureBuilder) SUBTRACT(com.facebook.presto.spi.function.OperatorType.SUBTRACT) SqlType(com.facebook.presto.spi.function.SqlType) Decimals.longTenToNth(com.facebook.presto.spi.type.Decimals.longTenToNth) ADD(com.facebook.presto.spi.function.OperatorType.ADD) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)

Aggregations

UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)1 SCALAR (com.facebook.presto.metadata.FunctionKind.SCALAR)1 Signature (com.facebook.presto.metadata.Signature)1 Signature.longVariableExpression (com.facebook.presto.metadata.Signature.longVariableExpression)1 SignatureBuilder (com.facebook.presto.metadata.SignatureBuilder)1 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)1 SqlScalarFunctionBuilder (com.facebook.presto.metadata.SqlScalarFunctionBuilder)1 SpecializeContext (com.facebook.presto.metadata.SqlScalarFunctionBuilder.SpecializeContext)1 PrestoException (com.facebook.presto.spi.PrestoException)1 DIVISION_BY_ZERO (com.facebook.presto.spi.StandardErrorCode.DIVISION_BY_ZERO)1 NUMERIC_VALUE_OUT_OF_RANGE (com.facebook.presto.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE)1 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)1 ADD (com.facebook.presto.spi.function.OperatorType.ADD)1 DIVIDE (com.facebook.presto.spi.function.OperatorType.DIVIDE)1 HASH_CODE (com.facebook.presto.spi.function.OperatorType.HASH_CODE)1 MODULUS (com.facebook.presto.spi.function.OperatorType.MODULUS)1 MULTIPLY (com.facebook.presto.spi.function.OperatorType.MULTIPLY)1 NEGATION (com.facebook.presto.spi.function.OperatorType.NEGATION)1 SUBTRACT (com.facebook.presto.spi.function.OperatorType.SUBTRACT)1 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)1