use of io.crate.analyze.OrderBy 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.analyze.OrderBy 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;
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class RamAccountingPageIteratorTest method testRamAccountingWrappingAppliedForOrderedIterators.
@Test
public void testRamAccountingWrappingAppliedForOrderedIterators() {
PositionalOrderBy orderBy = PositionalOrderBy.of(new OrderBy(Collections.singletonList(Literal.of(1)), new boolean[] { false }, new boolean[] { false }), Collections.singletonList(Literal.of(1)));
PagingIterator<Integer, Row> repeatingSortedPagingIterator = PagingIterator.create(2, true, orderBy, () -> null);
assertThat(repeatingSortedPagingIterator, instanceOf(RamAccountingPageIterator.class));
assertThat(((RamAccountingPageIterator) repeatingSortedPagingIterator).delegatePagingIterator, instanceOf(SortedPagingIterator.class));
PagingIterator<Integer, Row> nonRepeatingSortedPagingIterator = PagingIterator.create(2, false, orderBy, () -> null);
assertThat(nonRepeatingSortedPagingIterator, instanceOf(RamAccountingPageIterator.class));
assertThat(((RamAccountingPageIterator) nonRepeatingSortedPagingIterator).delegatePagingIterator, instanceOf(SortedPagingIterator.class));
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class WindowAggTest method testOrderByIsMergedWithPartitionByWithPartialColumnOverlap.
@Test
public void testOrderByIsMergedWithPartitionByWithPartialColumnOverlap() {
OrderBy orderBy = WindowAgg.createOrderByInclPartitionBy(wd("avg(x) OVER (PARTITION BY x, y ORDER BY x)"));
assertThat(orderBy, notNullValue());
assertThat(orderBy.orderBySymbols(), contains(isReference("x"), isReference("y")));
}
use of io.crate.analyze.OrderBy in project crate by crate.
the class WindowAggTest method testOrderByIsMergedWithPartitionByWithPartialColumnOverlapButReverseOrder.
@Test
public void testOrderByIsMergedWithPartitionByWithPartialColumnOverlapButReverseOrder() {
OrderBy orderBy = WindowAgg.createOrderByInclPartitionBy(wd("avg(x) OVER (PARTITION BY y, x ORDER BY x)"));
assertThat(orderBy, notNullValue());
assertThat(orderBy.orderBySymbols(), contains(isReference("y"), isReference("x")));
}
Aggregations