use of io.crate.planner.operators.Order in project crate by crate.
the class MoveOrderBeneathUnion method apply.
@Override
public LogicalPlan apply(Order order, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
Union union = captures.get(unionCapture);
List<LogicalPlan> unionSources = union.sources();
assert unionSources.size() == 2 : "A UNION must have exactly 2 unionSources";
Order lhsOrder = updateSources(order, unionSources.get(0));
Order rhsOrder = updateSources(order, unionSources.get(1));
return union.replaceSources(List.of(lhsOrder, rhsOrder));
}
use of io.crate.planner.operators.Order in project crate by crate.
the class MoveOrderBeneathRename method apply.
@Override
public LogicalPlan apply(Order plan, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
Rename rename = captures.get(renameCapture);
Function<? super Symbol, ? extends Symbol> mapField = FieldReplacer.bind(rename::resolveField);
OrderBy mappedOrderBy = plan.orderBy().map(mapField);
if (rename.source().outputs().containsAll(mappedOrderBy.orderBySymbols())) {
Order newOrder = new Order(rename.source(), mappedOrderBy);
return rename.replaceSources(List.of(newOrder));
} else {
return null;
}
}
use of io.crate.planner.operators.Order in project crate by crate.
the class MoveOrderBeneathNestedLoop method apply.
@Override
public LogicalPlan apply(Order order, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
NestedLoopJoin nestedLoop = captures.get(nlCapture);
Set<RelationName> relationsInOrderBy = Collections.newSetFromMap(new IdentityHashMap<>());
Consumer<ScopedSymbol> gatherRelationsFromField = f -> relationsInOrderBy.add(f.relation());
Consumer<Reference> gatherRelationsFromRef = r -> relationsInOrderBy.add(r.ident().tableIdent());
OrderBy orderBy = order.orderBy();
for (Symbol orderExpr : orderBy.orderBySymbols()) {
FieldsVisitor.visitFields(orderExpr, gatherRelationsFromField);
RefVisitor.visitRefs(orderExpr, gatherRelationsFromRef);
}
if (relationsInOrderBy.size() == 1) {
RelationName relationInOrderBy = relationsInOrderBy.iterator().next();
if (relationInOrderBy == nestedLoop.topMostLeftRelation().relationName()) {
LogicalPlan lhs = nestedLoop.sources().get(0);
LogicalPlan newLhs = order.replaceSources(List.of(lhs));
return new NestedLoopJoin(newLhs, nestedLoop.sources().get(1), nestedLoop.joinType(), nestedLoop.joinCondition(), nestedLoop.isFiltered(), nestedLoop.topMostLeftRelation(), true, nestedLoop.isRewriteFilterOnOuterJoinToInnerJoinDone());
}
}
return null;
}
Aggregations