Search in sources :

Example 71 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestDruidQueryGenerator method testDistinctSelection.

@Test
public void testDistinctSelection() {
    PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, druidTable, regionId, secondsSinceEpoch, city, fare));
    testDQL(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justScan).singleGroupingSet(variable("region.id"))), "SELECT \"region.Id\", count(*) FROM \"realtimeOnly\" GROUP BY \"region.Id\"");
}
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 72 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestDruidQueryGenerator method testDQL.

private void testDQL(DruidConfig givenDruidConfig, Function<PlanBuilder, PlanNode> planBuilderConsumer, String expectedDQL, SessionHolder sessionHolder, Map<String, String> outputVariables) {
    PlanNode planNode = planBuilderConsumer.apply(createPlanBuilder(sessionHolder));
    testDQL(givenDruidConfig, planNode, expectedDQL, sessionHolder, outputVariables);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode)

Example 73 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class TestDruidQueryGenerator method testCountStar.

@Test
public void testCountStar() {
    BiConsumer<PlanBuilder, PlanBuilder.AggregationBuilder> aggregationFunctionBuilder = (planBuilder, aggregationBuilder) -> aggregationBuilder.addAggregation(planBuilder.variable("agg"), getRowExpression("count(*)", defaultSessionHolder));
    PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, druidTable, regionId, secondsSinceEpoch, city, fare));
    PlanNode filter = buildPlan(planBuilder -> filter(planBuilder, tableScan(planBuilder, druidTable, regionId, secondsSinceEpoch, city, fare), getRowExpression("fare > 3", defaultSessionHolder)));
    PlanNode anotherFilter = buildPlan(planBuilder -> filter(planBuilder, tableScan(planBuilder, druidTable, regionId, secondsSinceEpoch, city, fare), getRowExpression("secondssinceepoch between 200 and 300 and \"region.id\" >= 40", defaultSessionHolder)));
    testDQL(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(justScan).globalGrouping())), "SELECT count(*) FROM \"realtimeOnly\"");
    testDQL(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(filter).globalGrouping())), "SELECT count(*) FROM \"realtimeOnly\" WHERE (\"fare\" > 3)");
    testDQL(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(filter).singleGroupingSet(variable("region.id")))), "SELECT \"region.Id\", count(*) FROM \"realtimeOnly\" WHERE (\"fare\" > 3) GROUP BY \"region.Id\"");
    testDQL(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(justScan).singleGroupingSet(variable("region.id")))), "SELECT \"region.Id\", count(*) FROM \"realtimeOnly\" GROUP BY \"region.Id\"");
    testDQL(planBuilder -> limit(planBuilder, 5L, planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(justScan).singleGroupingSet(variable("region.id"))))), "SELECT \"region.Id\", count(*) FROM \"realtimeOnly\" GROUP BY \"region.Id\" LIMIT 5");
    testDQL(planBuilder -> planBuilder.aggregation(aggBuilder -> aggregationFunctionBuilder.accept(planBuilder, aggBuilder.source(anotherFilter).singleGroupingSet(variable("region.id"), variable("city")))), "SELECT \"region.Id\", \"city\", count(*) FROM \"realtimeOnly\" WHERE ((\"secondsSinceEpoch\" BETWEEN 200 AND 300) AND (\"region.Id\" >= 40)) GROUP BY \"region.Id\", \"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) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 74 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode 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 75 with PlanNode

use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.

the class GraphvizPrinter method printFragmentNodes.

private static void printFragmentNodes(StringBuilder output, PlanFragment fragment, PlanNodeIdGenerator idGenerator, Session session, FunctionAndTypeManager functionAndTypeManager) {
    String clusterId = "cluster_" + fragment.getId();
    output.append("subgraph ").append(clusterId).append(" {").append('\n');
    output.append(format("label = \"%s\"", fragment.getPartitioning())).append('\n');
    PlanNode plan = fragment.getRoot();
    plan.accept(new NodePrinter(output, idGenerator, session, functionAndTypeManager), null);
    output.append("}").append('\n');
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode)

Aggregations

PlanNode (com.facebook.presto.spi.plan.PlanNode)228 Test (org.testng.annotations.Test)114 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)94 ImmutableList (com.google.common.collect.ImmutableList)56 RowExpression (com.facebook.presto.spi.relation.RowExpression)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)42 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)41 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)40 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)40 Map (java.util.Map)39 Optional (java.util.Optional)38 List (java.util.List)36 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)35 Set (java.util.Set)30 Assert.assertEquals (org.testng.Assert.assertEquals)23 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)20 Function (java.util.function.Function)20 Metadata (com.facebook.presto.metadata.Metadata)19