Skip to content

Commit bcc88f1

Browse files
committed
Fix EsqlNodeSubclassTest failure from mutating
We shouldn't mutate LogicalPlan.child().output() (or just LogicalPlan.output()); we did so in RENAME, but only in EsqlNodeSubclassTest, making them flaky.
1 parent 1078bd0 commit bcc88f1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ private LogicalPlan resolveKeep(Project p, List<Attribute> childOutput) {
939939
}
940940

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

944945
for (var ne : drop.removals()) {
@@ -974,6 +975,10 @@ private LogicalPlan resolveRename(Rename rename, List<Attribute> childrenOutput)
974975
return new EsqlProject(rename.source(), rename.child(), projections);
975976
}
976977

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

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/Rename.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.xpack.esql.core.tree.Source;
1919
import org.elasticsearch.xpack.esql.expression.function.UnsupportedAttribute;
2020

21+
import java.util.ArrayList;
2122
import java.util.List;
2223
import java.util.Objects;
2324

@@ -47,7 +48,11 @@ public List<Alias> renamings() {
4748
@Override
4849
public List<Attribute> output() {
4950
// Normally shouldn't reach here, as Rename only exists before resolution.
50-
List<NamedExpression> projectionsAfterResolution = ResolveRefs.projectionsForRename(this, this.child().output(), null);
51+
List<NamedExpression> projectionsAfterResolution = ResolveRefs.projectionsForRename(
52+
this,
53+
new ArrayList<>(this.child().output()),
54+
null
55+
);
5156

5257
return Expressions.asAttributes(projectionsAfterResolution);
5358
}

0 commit comments

Comments
 (0)