Search in sources :

Example 1 with MULTIPLY

use of io.prestosql.spi.function.OperatorType.MULTIPLY in project hetu-core by openlookeng.

the class TestPushProjectionThroughUnion method test.

@Test
public void test() {
    FunctionResolution functionResolution = new FunctionResolution(tester().getMetadata().getFunctionAndTypeManager());
    tester().assertThat(new PushProjectionThroughUnion()).on(p -> {
        Symbol a = p.symbol("a");
        Symbol b = p.symbol("b");
        Symbol c = p.symbol("c");
        Symbol cTimes3 = p.symbol("c_times_3");
        return p.project(Assignments.of(cTimes3, call("c * 3", functionResolution.arithmeticFunction(MULTIPLY, BIGINT, BIGINT), BIGINT, p.variable("c"), constant(3L, BIGINT))), p.union(ImmutableListMultimap.<Symbol, Symbol>builder().put(c, a).put(c, b).build(), ImmutableList.of(p.values(a), p.values(b))));
    }).matches(union(project(ImmutableMap.of("a_times_3", expression("a * 3")), values(ImmutableList.of("a"))), project(ImmutableMap.of("b_times_3", expression("b * 3")), values(ImmutableList.of("b")))).withNumberOfOutputColumns(1).withAlias("a_times_3").withAlias("b_times_3"));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) MULTIPLY(io.prestosql.spi.function.OperatorType.MULTIPLY) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) PlanMatchPattern.union(io.prestosql.sql.planner.assertions.PlanMatchPattern.union) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) ImmutableList(com.google.common.collect.ImmutableList) LongLiteral(io.prestosql.sql.tree.LongLiteral) Expressions.call(io.prestosql.sql.relational.Expressions.call) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) Symbol(io.prestosql.spi.plan.Symbol) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 2 with MULTIPLY

use of io.prestosql.spi.function.OperatorType.MULTIPLY in project hetu-core by openlookeng.

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, MULTIPLY).signature(signature).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("multiplyShortShortShort", "multiplyShortShortLong", "multiplyLongLongLong", "multiplyShortLongLong", "multiplyLongShortLong"))).build();
}
Also used : ADD(io.prestosql.spi.function.OperatorType.ADD) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) LiteralParameters(io.prestosql.spi.function.LiteralParameters) DecimalType(io.prestosql.spi.type.DecimalType) Math.abs(java.lang.Math.abs) UnscaledDecimal128Arithmetic.unscaledDecimal(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimal) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode) DIVISION_BY_ZERO(io.prestosql.spi.StandardErrorCode.DIVISION_BY_ZERO) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) IsNull(io.prestosql.spi.function.IsNull) ScalarOperator(io.prestosql.spi.function.ScalarOperator) INDETERMINATE(io.prestosql.spi.function.OperatorType.INDETERMINATE) OperatorType(io.prestosql.spi.function.OperatorType) BigInteger(java.math.BigInteger) PolymorphicScalarFunctionBuilder(io.prestosql.metadata.PolymorphicScalarFunctionBuilder) Long.signum(java.lang.Long.signum) MULTIPLY(io.prestosql.spi.function.OperatorType.MULTIPLY) UnscaledDecimal128Arithmetic(io.prestosql.spi.type.UnscaledDecimal128Arithmetic) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) Decimals.longTenToNth(io.prestosql.spi.type.Decimals.longTenToNth) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) List(java.util.List) UnscaledDecimal128Arithmetic.divideRoundUp(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.divideRoundUp) SqlType(io.prestosql.spi.function.SqlType) TypeSignature(io.prestosql.spi.type.TypeSignature) MODULUS(io.prestosql.spi.function.OperatorType.MODULUS) HASH_CODE(io.prestosql.spi.function.OperatorType.HASH_CODE) DIVIDE(io.prestosql.spi.function.OperatorType.DIVIDE) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) UnscaledDecimal128Arithmetic.throwIfOverflows(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.throwIfOverflows) SpecializeContext(io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext) NUMERIC_VALUE_OUT_OF_RANGE(io.prestosql.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE) Decimals(io.prestosql.spi.type.Decimals) UnscaledDecimal128Arithmetic.isZero(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.isZero) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) SignatureBuilder(io.prestosql.spi.function.SignatureBuilder) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Signature.longVariableExpression(io.prestosql.spi.function.Signature.longVariableExpression) UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong) XX_HASH_64(io.prestosql.spi.function.OperatorType.XX_HASH_64) XxHash64(io.airlift.slice.XxHash64) Decimals.encodeUnscaledValue(io.prestosql.spi.type.Decimals.encodeUnscaledValue) SUBTRACT(io.prestosql.spi.function.OperatorType.SUBTRACT) Integer.max(java.lang.Integer.max) UnscaledDecimal128Arithmetic.remainder(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.remainder) NEGATION(io.prestosql.spi.function.OperatorType.NEGATION) UnscaledDecimal128Arithmetic.rescale(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.rescale) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 MULTIPLY (io.prestosql.spi.function.OperatorType.MULTIPLY)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Slice (io.airlift.slice.Slice)1 XxHash64 (io.airlift.slice.XxHash64)1 PolymorphicScalarFunctionBuilder (io.prestosql.metadata.PolymorphicScalarFunctionBuilder)1 SpecializeContext (io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)1 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)1 PrestoException (io.prestosql.spi.PrestoException)1 DIVISION_BY_ZERO (io.prestosql.spi.StandardErrorCode.DIVISION_BY_ZERO)1 NUMERIC_VALUE_OUT_OF_RANGE (io.prestosql.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE)1 UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)1 SCALAR (io.prestosql.spi.function.FunctionKind.SCALAR)1 IsNull (io.prestosql.spi.function.IsNull)1 LiteralParameters (io.prestosql.spi.function.LiteralParameters)1 OperatorType (io.prestosql.spi.function.OperatorType)1 ADD (io.prestosql.spi.function.OperatorType.ADD)1 DIVIDE (io.prestosql.spi.function.OperatorType.DIVIDE)1