Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QL: Make UnaryPlan.replaceChild public and use it where appropriate #76071

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import java.util.Objects;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static org.elasticsearch.xpack.ql.optimizer.OptimizerRules.PropagateNullable;

Expand Down Expand Up @@ -448,13 +447,13 @@ protected LogicalPlan rule(OrderBy orderBy) {
// preserve the order for the base query, everything else needs to be ascending
List<Order> pushedOrder = baseFilter ? orderBy.order() : ascendingOrders;
OrderBy order = new OrderBy(filter.source(), filter.child(), pushedOrder);
orderedQueries.add((KeyedFilter) filter.replaceChildrenSameSize(singletonList(order)));
orderedQueries.add(filter.replaceChild(order));
baseFilter = false;
}

KeyedFilter until = join.until();
OrderBy order = new OrderBy(until.source(), until.child(), ascendingOrders);
until = (KeyedFilter) until.replaceChildrenSameSize(singletonList(order));
until = until.replaceChild(order);

OrderDirection direction = orderBy.order().get(0).direction();
plan = join.with(orderedQueries, until, direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected NodeInfo<Limit> info() {
}

@Override
protected Head replaceChild(LogicalPlan newChild) {
public Head replaceChild(LogicalPlan newChild) {
return new Head(source(), limit(), newChild);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected NodeInfo<KeyedFilter> info() {
}

@Override
protected KeyedFilter replaceChild(LogicalPlan newChild) {
public KeyedFilter replaceChild(LogicalPlan newChild) {
return new KeyedFilter(source(), newChild, keys, timestamp, tiebreaker);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected NodeInfo<Limit> info() {
}

@Override
protected LimitWithOffset replaceChild(LogicalPlan newChild) {
public LimitWithOffset replaceChild(LogicalPlan newChild) {
return new LimitWithOffset(source(), limit(), offset, newChild);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected NodeInfo<Limit> info() {
}

@Override
protected Tail replaceChild(LogicalPlan newChild) {
public Tail replaceChild(LogicalPlan newChild) {
return new Tail(source(), newChild, limit());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@

import static java.lang.Math.signum;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.elasticsearch.xpack.ql.expression.Literal.FALSE;
import static org.elasticsearch.xpack.ql.expression.Literal.TRUE;
import static org.elasticsearch.xpack.ql.expression.predicate.Predicates.combineAnd;
Expand Down Expand Up @@ -1207,14 +1206,12 @@ else if (child instanceof UnaryPlan) {
}
// if at least one expression can be pushed down, update the tree
if (conjunctions.size() > 0) {
child = child.replaceChildrenSameSize(
singletonList(filter.with(unary.child(), Predicates.combineAnd(conjunctions)))
);
child = unary.replaceChild(filter.with(unary.child(), Predicates.combineAnd(conjunctions)));
plan = filter.with(child, Predicates.combineAnd(inPlace));
}
} else {
// push down filter
plan = child.replaceChildrenSameSize(singletonList(filter.with(unary.child(), condition)));
plan = unary.replaceChild(filter.with(unary.child(), condition));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected NodeInfo<Aggregate> info() {
}

@Override
protected Aggregate replaceChild(LogicalPlan newChild) {
public Aggregate replaceChild(LogicalPlan newChild) {
return new Aggregate(source(), newChild, groupings, aggregates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected NodeInfo<Filter> info() {
}

@Override
protected Filter replaceChild(LogicalPlan newChild) {
public Filter replaceChild(LogicalPlan newChild) {
return new Filter(source(), newChild, condition);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected NodeInfo<Limit> info() {
}

@Override
protected Limit replaceChild(LogicalPlan newChild) {
public Limit replaceChild(LogicalPlan newChild) {
return new Limit(source(), limit, newChild);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected NodeInfo<OrderBy> info() {
}

@Override
protected OrderBy replaceChild(LogicalPlan newChild) {
public OrderBy replaceChild(LogicalPlan newChild) {
return new OrderBy(source(), newChild, order);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected NodeInfo<Project> info() {
}

@Override
protected Project replaceChild(LogicalPlan newChild) {
public Project replaceChild(LogicalPlan newChild) {
return new Project(source(), newChild, projections);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final UnaryPlan replaceChildren(List<LogicalPlan> newChildren) {
return replaceChild(newChildren.get(0));
}

protected abstract UnaryPlan replaceChild(LogicalPlan newChild);
public abstract UnaryPlan replaceChild(LogicalPlan newChild);

public LogicalPlan child() {
return child;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ private static LogicalPlan propagateMissing(LogicalPlan plan, AttributeSet missi

// LeafPlans are tables and BinaryPlans are joins so pushing can only happen on unary
if (plan instanceof UnaryPlan) {
return plan.replaceChildrenSameSize(singletonList(propagateMissing(((UnaryPlan) plan).child(), missing, failed)));
UnaryPlan unary = (UnaryPlan) plan;
return unary.replaceChild(propagateMissing(unary.child(), missing, failed));
}

failed.addAll(missing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ static class SkipQueryForLiteralAggregations extends OptimizerRule<Aggregate> {
@Override
protected LogicalPlan rule(Aggregate plan) {
if (plan.groupings().isEmpty() && plan.child() instanceof EsRelation && plan.aggregates().stream().allMatch(this::foldable)) {
return plan.replaceChildrenSameSize(singletonList(new LocalRelation(plan.source(), new SingletonExecutable())));
return plan.replaceChild(new LocalRelation(plan.source(), new SingletonExecutable()));
}

return plan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected NodeInfo<Distinct> info() {
}

@Override
protected Distinct replaceChild(LogicalPlan newChild) {
public Distinct replaceChild(LogicalPlan newChild) {
return new Distinct(source(), newChild);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected NodeInfo<Filter> info() {
}

@Override
protected Having replaceChild(LogicalPlan newChild) {
public Having replaceChild(LogicalPlan newChild) {
return new Having(source(), newChild, condition());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected NodeInfo<Pivot> info() {
}

@Override
protected Pivot replaceChild(LogicalPlan newChild) {
public Pivot replaceChild(LogicalPlan newChild) {
return new Pivot(source(), newChild, column, values, aggregates, grouping);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected NodeInfo<SubQueryAlias> info() {
}

@Override
protected SubQueryAlias replaceChild(LogicalPlan newChild) {
public SubQueryAlias replaceChild(LogicalPlan newChild) {
return new SubQueryAlias(source(), newChild, alias);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected NodeInfo<With> info() {
}

@Override
protected With replaceChild(LogicalPlan newChild) {
public With replaceChild(LogicalPlan newChild) {
return new With(source(), newChild, subQueries);
}

Expand Down