Search in sources :

Example 16 with FunctionResolution

use of com.facebook.presto.sql.relational.FunctionResolution in project presto by prestodb.

the class TestPushProjectionThroughUnion method test.

@Test
public void test() {
    FunctionResolution functionResolution = new FunctionResolution(tester().getMetadata().getFunctionAndTypeManager());
    tester().assertThat(new PushProjectionThroughUnion()).on(p -> {
        VariableReferenceExpression a = p.variable("a");
        VariableReferenceExpression b = p.variable("b");
        VariableReferenceExpression c = p.variable("c");
        return p.project(assignment(p.variable("c_times_3"), call("c * 3", functionResolution.arithmeticFunction(MULTIPLY, BIGINT, BIGINT), BIGINT, c, constant(3L, BIGINT))), p.union(ImmutableListMultimap.<VariableReferenceExpression, VariableReferenceExpression>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 : BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) MULTIPLY(com.facebook.presto.common.function.OperatorType.MULTIPLY) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) PlanMatchPattern.union(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.union) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableList(com.google.common.collect.ImmutableList) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) PlanBuilder.assignment(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.assignment) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PlanMatchPattern.expression(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Aggregations

FunctionResolution (com.facebook.presto.sql.relational.FunctionResolution)16 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)8 RowExpressionDeterminismEvaluator (com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator)7 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)5 ImmutableList (com.google.common.collect.ImmutableList)5 Optional (java.util.Optional)5 BeforeClass (org.testng.annotations.BeforeClass)5 Test (org.testng.annotations.Test)5 Session (com.facebook.presto.Session)4 TableHandle (com.facebook.presto.spi.TableHandle)4 RowExpression (com.facebook.presto.spi.relation.RowExpression)4 Expressions.call (com.facebook.presto.sql.relational.Expressions.call)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)3 Metadata (com.facebook.presto.metadata.Metadata)3 Expressions.constant (com.facebook.presto.sql.relational.Expressions.constant)3 RowExpressionDomainTranslator (com.facebook.presto.sql.relational.RowExpressionDomainTranslator)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)2