Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -939,6 +939,7 @@ private LogicalPlan resolveKeep(Project p, List<Attribute> childOutput) {
}

private LogicalPlan resolveDrop(Drop drop, List<Attribute> childOutput) {
// Make a copy of childOutput because we may mutate this to simplify resolution of e.g. RENAME.
List<NamedExpression> resolvedProjections = new ArrayList<>(childOutput);

for (var ne : drop.removals()) {
Expand Down Expand Up @@ -974,6 +975,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