From faf6b75159d99f386f5b6db065474d6d1a604e25 Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Tue, 14 Oct 2025 10:59:37 +0200 Subject: [PATCH] ES|QL: Make ResolveUnionTypes rule stateless (#136492) (#136527) --- docs/changelog/136492.yaml | 5 +++++ .../org/elasticsearch/xpack/esql/analysis/Analyzer.java | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 docs/changelog/136492.yaml 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 1c27446903615..e597fd2279548 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 @@ -1442,11 +1442,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()) { @@ -1456,10 +1454,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)