Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions docs/changelog/124611.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 124611
summary: Reuse child `outputSet` inside the plan where possible
area: ES|QL
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.capabilities.TelemetryAware;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

public class Limit extends UnaryPlan implements TelemetryAware {
Expand Down Expand Up @@ -75,6 +78,16 @@ public String getWriteableName() {
return ENTRY.name;
}

@Override
public List<Attribute> output() {
return child().output();
}

@Override
public AttributeSet outputSet() {
return child().outputSet();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a better default implementation of this in UnaryPlan, this might be obsolete. Same goes for the corresponding overrides in the other classes.

}

@Override
protected NodeInfo<Limit> info() {
return NodeInfo.create(this, Limit::new, limit, child(), duplicated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.elasticsearch.xpack.esql.capabilities.TelemetryAware;
import org.elasticsearch.xpack.esql.common.Failures;
import org.elasticsearch.xpack.esql.core.capabilities.Resolvables;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
Expand Down Expand Up @@ -61,6 +63,16 @@ public String getWriteableName() {
return ENTRY.name;
}

@Override
public List<Attribute> output() {
return child().output();
}

@Override
public AttributeSet outputSet() {
return child().outputSet();
}

@Override
protected NodeInfo<OrderBy> info() {
return NodeInfo.create(this, OrderBy::new, child(), order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.core.capabilities.Resolvables;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
Expand Down Expand Up @@ -55,6 +57,16 @@ public String getWriteableName() {
return ENTRY.name;
}

@Override
public List<Attribute> output() {
return child().output();
}

@Override
public AttributeSet outputSet() {
return child().outputSet();
}

@Override
public boolean expressionsResolved() {
return limit.resolved() && Resolvables.resolved(order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.esql.plan.logical;

import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.tree.Source;

import java.util.Collections;
Expand Down Expand Up @@ -42,6 +43,11 @@ public List<Attribute> output() {
return child.output();
}

@Override
public AttributeSet outputSet() {
return child().outputSet();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this is incorrect: now all the subplans that override output() but not outputSet() (eg. Eval) return a wrong output set, based on the child rather than on the actual output

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++, this is dangerous, we normally don't have to override outputSet but rely it to be constructed from output().

A IMHO better way that remains safe:

    public AttributeSet outputSet() {
        if (lazyOutputSet == null) {
            List<Attribute> output = output();
            lazyOutputSet = (output == child.output?) child.outputSet() : new AttributeSet(output);
        }
        return lazyOutputSet;

@Override
public int hashCode() {
return Objects.hashCode(child());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
Expand Down Expand Up @@ -68,6 +69,11 @@ public List<Attribute> output() {
return child().output();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope, but I noticed this is redundant.


@Override
public AttributeSet outputSet() {
return child().outputSet();
}

@Override
public int hashCode() {
return Objects.hash(condition, child());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

public class LimitExec extends UnaryExec {
Expand Down Expand Up @@ -48,6 +51,16 @@ public String getWriteableName() {
return ENTRY.name;
}

@Override
public List<Attribute> output() {
return child().output();
}

@Override
public AttributeSet outputSet() {
return child().outputSet();
}

@Override
protected NodeInfo<? extends LimitExec> info() {
return NodeInfo.create(this, LimitExec::new, child(), limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
Expand Down Expand Up @@ -69,6 +70,16 @@ public String getWriteableName() {
return ENTRY.name;
}

@Override
public List<Attribute> output() {
return child().output();
}

@Override
public AttributeSet outputSet() {
return child().outputSet();
}

@Override
protected NodeInfo<TopNExec> info() {
return NodeInfo.create(this, TopNExec::new, child(), order, limit, estimatedRowSize);
Expand Down