Skip to content

ESQL: Fix EsqlNodeSubclassTest failure from mutating #125503

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

Merged
merged 2 commits into from
Mar 24, 2025
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