diff --git a/docs/changelog/136492.yaml b/docs/changelog/136492.yaml new file mode 100644 index 0000000000000..5ae71a5cfa79f --- /dev/null +++ b/docs/changelog/136492.yaml @@ -0,0 +1,5 @@ +pr: 136492 +summary: Make `ResolveUnionTypes` rule stateless +area: ES|QL +type: bug +issues: [] diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java index bcdf89f4ca17a..fe47e45705600 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java @@ -1365,11 +1365,9 @@ private static class ResolveUnionTypes extends Rule { record TypeResolutionKey(String fieldName, DataType fieldType) {} - private List unionFieldAttributes; - @Override public LogicalPlan apply(LogicalPlan plan) { - unionFieldAttributes = new ArrayList<>(); + List unionFieldAttributes = new ArrayList<>(); // Collect field attributes from previous runs plan.forEachUp(EsRelation.class, rel -> { for (Attribute attr : rel.output()) { @@ -1379,10 +1377,10 @@ public LogicalPlan apply(LogicalPlan plan) { } }); - return plan.transformUp(LogicalPlan.class, p -> p.childrenResolved() == false ? p : doRule(p)); + return plan.transformUp(LogicalPlan.class, p -> p.childrenResolved() == false ? p : doRule(p, unionFieldAttributes)); } - private LogicalPlan doRule(LogicalPlan plan) { + private LogicalPlan doRule(LogicalPlan plan, List unionFieldAttributes) { int alreadyAddedUnionFieldAttributes = unionFieldAttributes.size(); // See if the eval function has an unresolved MultiTypeEsField field // Replace the entire convert function with a new FieldAttribute (containing type conversion knowledge)