use of com.facebook.presto.spi.plan.TopNNode in project presto by prestodb.
the class SymbolMapper method map.
public TopNNode map(TopNNode node, PlanNode source, PlanNodeId newNodeId) {
ImmutableList.Builder<VariableReferenceExpression> variables = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, SortOrder> orderings = ImmutableMap.builder();
Set<VariableReferenceExpression> seenCanonicals = new HashSet<>(node.getOrderingScheme().getOrderByVariables().size());
for (VariableReferenceExpression variable : node.getOrderingScheme().getOrderByVariables()) {
VariableReferenceExpression canonical = map(variable);
if (seenCanonicals.add(canonical)) {
seenCanonicals.add(canonical);
variables.add(canonical);
orderings.put(canonical, node.getOrderingScheme().getOrdering(variable));
}
}
ImmutableMap<VariableReferenceExpression, SortOrder> orderingMap = orderings.build();
return new TopNNode(node.getSourceLocation(), newNodeId, source, node.getCount(), new OrderingScheme(variables.build().stream().map(variable -> new Ordering(variable, orderingMap.get(variable))).collect(toImmutableList())), node.getStep());
}
use of com.facebook.presto.spi.plan.TopNNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testTopN.
@Test
public void testTopN() {
PlanNode node = new TopNNode(Optional.empty(), newId(), filter(baseTableScan, and(equals(AV, BV), equals(BV, CV), lessThan(CV, bigintLiteral(10)))), 1, new OrderingScheme(ImmutableList.of(new Ordering(AV, SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.PARTIAL);
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// Pass through
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(AV, BV), equals(BV, CV), lessThan(CV, bigintLiteral(10))));
}
use of com.facebook.presto.spi.plan.TopNNode in project presto by prestodb.
the class TestPinotQueryGenerator method testAggregationWithOrderByPushDownInTopN.
@Test(expectedExceptions = NoSuchElementException.class)
public void testAggregationWithOrderByPushDownInTopN() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
AggregationNode agg = planBuilder.aggregation(aggBuilder -> aggBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("agg"), getRowExpression("sum(fare)", defaultSessionHolder)));
TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), agg, 50L, new OrderingScheme(ImmutableList.of(new Ordering(variable("city"), SortOrder.DESC_NULLS_FIRST))), TopNNode.Step.FINAL);
testPinotQuery(pinotConfig, topN, "", defaultSessionHolder, ImmutableMap.of());
}
use of com.facebook.presto.spi.plan.TopNNode in project presto by prestodb.
the class TestPinotQueryGenerator method testSimpleSelectWithTopN.
@Test
public void testSimpleSelectWithTopN() {
pinotConfig.setPushdownTopNBrokerQueries(true);
SessionHolder sessionHolder = new SessionHolder(pinotConfig);
PlanBuilder planBuilder = createPlanBuilder(new SessionHolder(pinotConfig));
TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, regionId, city, fare);
TopNNode topNFare = topN(planBuilder, 50L, ImmutableList.of("fare"), ImmutableList.of(false), tableScanNode);
testPinotQuery(pinotConfig, topNFare, "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare DESC LIMIT 50", sessionHolder, ImmutableMap.of());
TopNNode topnFareAndCity = topN(planBuilder, 50L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode);
testPinotQuery(pinotConfig, topnFareAndCity, "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
ProjectNode projectNode = project(planBuilder, topnFareAndCity, ImmutableList.of("regionid", "city"));
testPinotQuery(pinotConfig, projectNode, "SELECT regionId, city FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
}
Aggregations