Search in sources :

Example 1 with TopNNode

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

the class TestPinotQueryGeneratorSql method testDefaultNoTopNPushdown.

@Test
public void testDefaultNoTopNPushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
    AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)));
    pinotConfig.setPushdownTopNBrokerQueries(false);
    TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    Optional<PinotQueryGenerator.PinotQueryGeneratorResult> generatedQuery = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(topN, defaultSessionHolder.getConnectorSession());
    assertFalse(generatedQuery.isPresent());
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    testPinotQuery(pinotConfig, aggregationNode, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city LIMIT 10000", sessionHolder, ImmutableMap.of());
}
Also used : OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) Ordering(com.facebook.presto.spi.plan.Ordering) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) TopNNode(com.facebook.presto.spi.plan.TopNNode) Test(org.testng.annotations.Test)

Example 2 with TopNNode

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

the class TestPinotQueryGeneratorSql method testAggregationWithOrderByPushDownInTopN.

@Override
@Test
public void testAggregationWithOrderByPushDownInTopN() {
    pinotConfig.setPushdownTopNBrokerQueries(true);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
    AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)));
    testPinotQuery(pinotConfig, aggregationNode, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city LIMIT 10000", sessionHolder, ImmutableMap.of());
    TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 50L, new OrderingScheme(ImmutableList.of(new Ordering(variable("city"), SortOrder.DESC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
    topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000L, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY sum(fare) LIMIT 1000", sessionHolder, ImmutableMap.of());
    topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000L, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY sum(fare) LIMIT 1000", sessionHolder, ImmutableMap.of());
}
Also used : OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) Ordering(com.facebook.presto.spi.plan.Ordering) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) TopNNode(com.facebook.presto.spi.plan.TopNNode) Test(org.testng.annotations.Test)

Example 3 with TopNNode

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

the class TestPinotQueryGeneratorSql method testSelectionWithOrderBy.

@Test
public void testSelectionWithOrderBy() {
    pinotConfig.setPushdownTopNBrokerQueries(true);
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, regionId, city, fare);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    testPinotQuery(pinotConfig, topN(planBuilder, 50L, ImmutableList.of("fare"), ImmutableList.of(false), tableScanNode), "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare DESC LIMIT 50", sessionHolder, ImmutableMap.of());
    testPinotQuery(pinotConfig, topN(planBuilder, 50L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode), "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
    testPinotQuery(pinotConfig, topN(planBuilder, 50L, ImmutableList.of("city", "fare"), ImmutableList.of(false, true), tableScanNode), "SELECT regionId, city, fare FROM realtimeOnly ORDER BY city DESC, fare LIMIT 50", sessionHolder, ImmutableMap.of());
    TopNNode topNNode = topN(planBuilder, 50L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode);
    testPinotQuery(pinotConfig, project(planBuilder, topNNode, ImmutableList.of("regionid", "city")), "SELECT regionId, city FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
    tableScanNode = tableScan(planBuilder, pinotTable, fare, city, regionId);
    testPinotQuery(pinotConfig, topN(planBuilder, 500L, ImmutableList.of("fare"), ImmutableList.of(false), tableScanNode), "SELECT fare, city, regionId FROM realtimeOnly ORDER BY fare DESC LIMIT 500", sessionHolder, ImmutableMap.of());
    testPinotQuery(pinotConfig, topN(planBuilder, 5000L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode), "SELECT fare, city, regionId FROM realtimeOnly ORDER BY fare, city DESC LIMIT 5000", sessionHolder, ImmutableMap.of());
}
Also used : TableScanNode(com.facebook.presto.spi.plan.TableScanNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) TopNNode(com.facebook.presto.spi.plan.TopNNode) Test(org.testng.annotations.Test)

Example 4 with TopNNode

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

the class TestUnion method testUnionUnderTopN.

@Test
public void testUnionUnderTopN() {
    Plan plan = plan("SELECT * FROM (" + "   SELECT regionkey FROM nation " + "   UNION ALL " + "   SELECT nationkey FROM nation" + ") t(a) " + "ORDER BY a LIMIT 1", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
    List<PlanNode> remotes = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll();
    assertEquals(remotes.size(), 1, "There should be exactly one RemoteExchange");
    assertEquals(((ExchangeNode) Iterables.getOnlyElement(remotes)).getType(), GATHER);
    int numberOfpartialTopN = searchFrom(plan.getRoot()).where(planNode -> planNode instanceof TopNNode && ((TopNNode) planNode).getStep().equals(TopNNode.Step.PARTIAL)).count();
    assertEquals(numberOfpartialTopN, 2, "There should be exactly two partial TopN nodes");
    assertPlanIsFullyDistributed(plan);
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Iterables(com.google.common.collect.Iterables) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) GATHER(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.GATHER) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) REPARTITION(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.REPARTITION) TopNNode(com.facebook.presto.spi.plan.TopNNode) Map(java.util.Map) Assert.assertTrue(org.testng.Assert.assertTrue) Plan(com.facebook.presto.sql.planner.Plan) Assert.assertFalse(org.testng.Assert.assertFalse) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) PlanNodeSearcher.searchFrom(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) Plan(com.facebook.presto.sql.planner.Plan) TopNNode(com.facebook.presto.spi.plan.TopNNode) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 5 with TopNNode

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

the class TopNMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    TopNNode topNNode = (TopNNode) node;
    if (topNNode.getCount() != count) {
        return NO_MATCH;
    }
    if (!orderingSchemeMatches(orderBy, topNNode.getOrderingScheme(), symbolAliases)) {
        return NO_MATCH;
    }
    return match();
}
Also used : TopNNode(com.facebook.presto.spi.plan.TopNNode)

Aggregations

TopNNode (com.facebook.presto.spi.plan.TopNNode)9 Test (org.testng.annotations.Test)7 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)5 Ordering (com.facebook.presto.spi.plan.Ordering)5 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)5 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)5 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)5 PlanNode (com.facebook.presto.spi.plan.PlanNode)3 RowExpression (com.facebook.presto.spi.relation.RowExpression)2 SortOrder (com.facebook.presto.common.block.SortOrder)1 RowExpressionRewriter (com.facebook.presto.expressions.RowExpressionRewriter)1 RowExpressionTreeRewriter (com.facebook.presto.expressions.RowExpressionTreeRewriter)1 PrestoWarning (com.facebook.presto.spi.PrestoWarning)1 MULTIPLE_ORDER_BY (com.facebook.presto.spi.StandardWarningCode.MULTIPLE_ORDER_BY)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 Aggregation (com.facebook.presto.spi.plan.AggregationNode.Aggregation)1 AggregationNode.groupingSets (com.facebook.presto.spi.plan.AggregationNode.groupingSets)1 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)1 PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)1 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)1