use of com.facebook.presto.sql.planner.plan.SortNode in project presto by prestodb.
the class SortMatcher 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());
SortNode sortNode = (SortNode) node;
if (!orderingSchemeMatches(orderBy, sortNode.getOrderingScheme(), symbolAliases)) {
return NO_MATCH;
}
return MatchResult.match();
}
use of com.facebook.presto.sql.planner.plan.SortNode in project presto by prestodb.
the class QueryPlanner method sort.
private PlanBuilder sort(PlanBuilder subPlan, Optional<OrderBy> orderBy, Optional<String> limit, List<Expression> orderByExpressions) {
if (!orderBy.isPresent()) {
return subPlan;
}
Iterator<SortItem> sortItems = orderBy.get().getSortItems().iterator();
ImmutableList.Builder<Symbol> orderBySymbols = ImmutableList.builder();
Map<Symbol, SortOrder> orderings = new HashMap<>();
for (Expression fieldOrExpression : orderByExpressions) {
Symbol symbol = subPlan.translate(fieldOrExpression);
SortItem sortItem = sortItems.next();
if (!orderings.containsKey(symbol)) {
orderBySymbols.add(symbol);
orderings.put(symbol, toSortOrder(sortItem));
}
}
PlanNode planNode;
if (limit.isPresent() && !limit.get().equalsIgnoreCase("all")) {
planNode = new TopNNode(idAllocator.getNextId(), subPlan.getRoot(), Long.parseLong(limit.get()), orderBySymbols.build(), orderings, false);
} else {
planNode = new SortNode(idAllocator.getNextId(), subPlan.getRoot(), orderBySymbols.build(), orderings);
}
return subPlan.withNewRoot(planNode);
}
use of com.facebook.presto.sql.planner.plan.SortNode in project presto by prestodb.
the class MergeLimitWithSort method apply.
@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
if (!(node instanceof LimitNode)) {
return Optional.empty();
}
LimitNode parent = (LimitNode) node;
PlanNode source = lookup.resolve(parent.getSource());
if (!(source instanceof SortNode)) {
return Optional.empty();
}
SortNode child = (SortNode) source;
return Optional.of(new TopNNode(parent.getId(), child.getSource(), parent.getCount(), child.getOrderBy(), child.getOrderings(), parent.isPartial()));
}
use of com.facebook.presto.sql.planner.plan.SortNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testSort.
@Test
public void testSort() {
PlanNode node = new SortNode(Optional.empty(), newId(), filter(baseTableScan, and(equals(AV, BV), equals(BV, CV), lessThan(CV, bigintLiteral(10)))), new OrderingScheme(ImmutableList.of(new Ordering(AV, SortOrder.ASC_NULLS_LAST))), false);
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.sql.planner.plan.SortNode in project presto by prestodb.
the class QueryPlanner method sort.
private PlanBuilder sort(PlanBuilder subPlan, Optional<OrderBy> orderBy, List<Expression> orderByExpressions) {
if (!orderBy.isPresent() || (isSkipRedundantSort(session)) && analysis.isOrderByRedundant(orderBy.get())) {
return subPlan;
}
PlanNode planNode;
OrderingScheme orderingScheme = toOrderingScheme(orderByExpressions.stream().map(subPlan::translate).collect(toImmutableList()), orderBy.get().getSortItems().stream().map(PlannerUtils::toSortOrder).collect(toImmutableList()));
planNode = new SortNode(getSourceLocation(orderBy.get()), idAllocator.getNextId(), subPlan.getRoot(), orderingScheme, false);
return subPlan.withNewRoot(planNode);
}
Aggregations