Search in sources :

Example 1 with ADD

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

the class TestPolymorphicScalarFunction method testSetsHiddenToTrueForOperators.

@Test
public void testSetsHiddenToTrueForOperators() {
    Signature signature = Signature.builder().operatorType(ADD).kind(SCALAR).returnType(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).build();
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(signature).implementation(b -> b.methods("varcharToVarchar")).build();
    ScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, TYPE_REGISTRY, REGISTRY);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) ImmutableSet(com.google.common.collect.ImmutableSet) Slice(io.airlift.slice.Slice) ImmutableMap(com.google.common.collect.ImmutableMap) TypeRegistry(com.facebook.presto.type.TypeRegistry) Assert.assertEquals(org.testng.Assert.assertEquals) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) Test(org.testng.annotations.Test) Signature.comparableWithVariadicBound(com.facebook.presto.metadata.Signature.comparableWithVariadicBound) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) SCALAR(com.facebook.presto.metadata.FunctionKind.SCALAR) VARCHAR(com.facebook.presto.spi.type.StandardTypes.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) VARCHAR_TO_BIGINT_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) Slices(io.airlift.slice.Slices) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) StandardTypes(com.facebook.presto.spi.type.StandardTypes) Math.toIntExact(java.lang.Math.toIntExact) VARCHAR_TO_VARCHAR_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) ADD(com.facebook.presto.spi.function.OperatorType.ADD) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 2 with ADD

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

the class DecimalOperators method decimalAddOperator.

private static SqlScalarFunction decimalAddOperator() {
    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(ADD).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).signature(signature).implementation(b -> b.methods("addShortShortShort").withExtraParameters(DecimalOperators::calculateShortRescaleParameters)).implementation(b -> b.methods("addShortShortLong", "addLongLongLong", "addShortLongLong", "addLongShortLong").withExtraParameters(DecimalOperators::calculateLongRescaleParameters)).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

SCALAR (com.facebook.presto.metadata.FunctionKind.SCALAR)2 ADD (com.facebook.presto.spi.function.OperatorType.ADD)2 TypeSignature (com.facebook.presto.spi.type.TypeSignature)2 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Slice (io.airlift.slice.Slice)2 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)1 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)1 Signature (com.facebook.presto.metadata.Signature)1 Signature.comparableWithVariadicBound (com.facebook.presto.metadata.Signature.comparableWithVariadicBound)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 VARCHAR_TO_BIGINT_RETURN_VALUE (com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE)1 VARCHAR_TO_VARCHAR_RETURN_VALUE (com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE)1 ScalarFunctionImplementation (com.facebook.presto.operator.scalar.ScalarFunctionImplementation)1 PrestoException (com.facebook.presto.spi.PrestoException)1