Skip to content
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 @@ -454,6 +454,8 @@ protected LogicalPlan rule(LogicalPlan plan, AnalyzerContext context) {
}
final List<Attribute> childrenOutput = new ArrayList<>();

// Gather all the children's output in case of non-unary plans; even for unaries, we need to copy because we may mutate this to
// simplify resolution of e.g. RENAME.
for (LogicalPlan child : plan.children()) {
var output = child.output();
childrenOutput.addAll(output);
Expand Down Expand Up @@ -974,6 +976,10 @@ private LogicalPlan resolveRename(Rename rename, List<Attribute> childrenOutput)
return new EsqlProject(rename.source(), rename.child(), projections);
}

/**
* This will turn a {@link Rename} into an equivalent {@link Project}.
* Can mutate {@code childrenOutput}; hand this a copy if you want to avoid mutation.
*/
public static List<NamedExpression> projectionsForRename(Rename rename, List<Attribute> childrenOutput, Logger logger) {
List<NamedExpression> projections = new ArrayList<>(childrenOutput);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.expression.function.UnsupportedAttribute;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -47,7 +48,11 @@ public List<Alias> renamings() {
@Override
public List<Attribute> output() {
// Normally shouldn't reach here, as Rename only exists before resolution.
List<NamedExpression> projectionsAfterResolution = ResolveRefs.projectionsForRename(this, this.child().output(), null);
List<NamedExpression> projectionsAfterResolution = ResolveRefs.projectionsForRename(
this,
new ArrayList<>(this.child().output()),
null
);

return Expressions.asAttributes(projectionsAfterResolution);
}
Expand Down