Search in sources :

Example 31 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestDruidQueryGenerator method testDistinctCountGroupByPushdown.

@Test
public void testDistinctCountGroupByPushdown() {
    PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, druidTable, regionId, secondsSinceEpoch, city, fare));
    PlanNode distinctAggregation = buildPlan(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justScan).singleGroupingSet(variable("city"), variable("region.id"))));
    testDQL(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(distinctAggregation).singleGroupingSet(variable("city")).addAggregation(variable("region.id"), getRowExpression("count(\"region.id\")", defaultSessionHolder))), "SELECT \"city\", count ( distinct \"region.Id\") FROM \"realtimeOnly\" GROUP BY \"city\"");
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) BiConsumer(java.util.function.BiConsumer) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PlanNode(com.facebook.presto.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Example 32 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class OptimizerAssert method on.

public OptimizerAssert on(Function<PlanBuilder, PlanNode> planProvider) {
    checkState(plan == null, "plan has already been set");
    PlanBuilder builder = new PlanBuilder(session, idAllocator, metadata);
    plan = planProvider.apply(builder);
    types = builder.getTypes();
    return this;
}
Also used : PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 33 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestJoinNodeFlattener method testDoesNotAllowOuterJoin.

@Test(expectedExceptions = IllegalStateException.class)
public void testDoesNotAllowOuterJoin() {
    PlanBuilder p = planBuilder();
    VariableReferenceExpression a1 = p.variable("A1");
    VariableReferenceExpression b1 = p.variable("B1");
    JoinNode outerJoin = p.join(FULL, p.values(a1), p.values(b1), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1), Optional.empty());
    toMultiJoinNode(outerJoin, noLookup(), DEFAULT_JOIN_LIMIT, functionResolution, determinismEvaluator);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) MultiJoinNode.toMultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) MultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 34 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestJoinNodeFlattener method testCombinesCriteriaAndFilters.

@Test
public void testCombinesCriteriaAndFilters() {
    PlanBuilder p = planBuilder();
    VariableReferenceExpression a1 = p.variable("A1");
    VariableReferenceExpression b1 = p.variable("B1");
    VariableReferenceExpression b2 = p.variable("B2");
    VariableReferenceExpression c1 = p.variable("C1");
    VariableReferenceExpression c2 = p.variable("C2");
    ValuesNode valuesA = p.values(a1);
    ValuesNode valuesB = p.values(b1, b2);
    ValuesNode valuesC = p.values(c1, c2);
    RowExpression bcFilter = and(call(OperatorType.GREATER_THAN.name(), functionResolution.comparisonFunction(OperatorType.GREATER_THAN, c2.getType(), BIGINT), BOOLEAN, ImmutableList.of(c2, constant(0L, BIGINT))), call(OperatorType.NOT_EQUAL.name(), functionResolution.comparisonFunction(OperatorType.NOT_EQUAL, c2.getType(), BIGINT), BOOLEAN, ImmutableList.of(c2, constant(7L, BIGINT))), call(OperatorType.GREATER_THAN.name(), functionResolution.comparisonFunction(OperatorType.GREATER_THAN, b2.getType(), c2.getType()), BOOLEAN, ImmutableList.of(b2, c2)));
    RowExpression add = call(OperatorType.ADD.name(), functionResolution.arithmeticFunction(OperatorType.ADD, a1.getType(), c1.getType()), a1.getType(), ImmutableList.of(a1, c1));
    RowExpression abcFilter = call(OperatorType.LESS_THAN.name(), functionResolution.comparisonFunction(OperatorType.LESS_THAN, add.getType(), b1.getType()), BOOLEAN, ImmutableList.of(add, b1));
    JoinNode joinNode = p.join(INNER, valuesA, p.join(INNER, valuesB, valuesC, ImmutableList.of(equiJoinClause(b1, c1)), ImmutableList.of(b1, b2, c1, c2), Optional.of(bcFilter)), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1, b2, c1, c2), Optional.of(abcFilter));
    MultiJoinNode expected = new MultiJoinNode(new LinkedHashSet<>(ImmutableList.of(valuesA, valuesB, valuesC)), and(createEqualsExpression(b1, c1), createEqualsExpression(a1, b1), bcFilter, abcFilter), ImmutableList.of(a1, b1, b2, c1, c2));
    assertEquals(toMultiJoinNode(joinNode, noLookup(), DEFAULT_JOIN_LIMIT, functionResolution, determinismEvaluator), expected);
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) MultiJoinNode.toMultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) MultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode.toMultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) MultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) Test(org.testng.annotations.Test)

Example 35 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestJoinNodeFlattener method testConvertsBushyTrees.

@Test
public void testConvertsBushyTrees() {
    PlanBuilder p = planBuilder();
    VariableReferenceExpression a1 = p.variable("A1");
    VariableReferenceExpression b1 = p.variable("B1");
    VariableReferenceExpression c1 = p.variable("C1");
    VariableReferenceExpression d1 = p.variable("D1");
    VariableReferenceExpression d2 = p.variable("D2");
    VariableReferenceExpression e1 = p.variable("E1");
    VariableReferenceExpression e2 = p.variable("E2");
    ValuesNode valuesA = p.values(a1);
    ValuesNode valuesB = p.values(b1);
    ValuesNode valuesC = p.values(c1);
    ValuesNode valuesD = p.values(d1, d2);
    ValuesNode valuesE = p.values(e1, e2);
    JoinNode joinNode = p.join(INNER, p.join(INNER, p.join(INNER, valuesA, valuesB, ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1), Optional.empty()), valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1, c1), Optional.empty()), p.join(INNER, valuesD, valuesE, ImmutableList.of(equiJoinClause(d1, e1), equiJoinClause(d2, e2)), ImmutableList.of(d1, d2, e1, e2), Optional.empty()), ImmutableList.of(equiJoinClause(b1, e1)), ImmutableList.of(a1, b1, c1, d1, d2, e1, e2), Optional.empty());
    MultiJoinNode expected = MultiJoinNode.builder().setSources(valuesA, valuesB, valuesC, valuesD, valuesE).setFilter(and(createEqualsExpression(a1, b1), createEqualsExpression(a1, c1), createEqualsExpression(d1, e1), createEqualsExpression(d2, e2), createEqualsExpression(b1, e1))).setOutputVariables(a1, b1, c1, d1, d2, e1, e2).build();
    assertEquals(toMultiJoinNode(joinNode, noLookup(), 5, functionResolution, determinismEvaluator), expected);
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) MultiJoinNode.toMultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) MultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode.toMultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) MultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) Test(org.testng.annotations.Test)

Aggregations

PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)70 Test (org.testng.annotations.Test)56 PlanNode (com.facebook.presto.spi.plan.PlanNode)41 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)31 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)25 ImmutableList (com.google.common.collect.ImmutableList)23 ImmutableMap (com.google.common.collect.ImmutableMap)23 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)21 TopNNode (com.facebook.presto.spi.plan.TopNNode)20 Map (java.util.Map)19 Function (java.util.function.Function)19 Assert.assertEquals (org.testng.Assert.assertEquals)19 Ordering (com.facebook.presto.spi.plan.Ordering)18 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)18 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)18 Optional (java.util.Optional)18 BiConsumer (java.util.function.BiConsumer)18 Collectors (java.util.stream.Collectors)18 PinotColumnHandle (com.facebook.presto.pinot.PinotColumnHandle)16 SortOrder (com.facebook.presto.common.block.SortOrder)15