瀏覽代碼

Fix layout for MV_EXPAND (#102916)

Luigi Dell'Aquila 1 年之前
父節點
當前提交
43c320f75f

+ 6 - 0
docs/changelog/102916.yaml

@@ -0,0 +1,6 @@
+pr: 102916
+summary: Fix layout for MV_EXPAND
+area: ES|QL
+type: bug
+issues:
+ - 102912

+ 10 - 0
x-pack/plugin/esql/qa/testFixtures/src/main/resources/mv_expand.csv-spec

@@ -306,3 +306,13 @@ a:long      | b:long      | c:long      | gender:keyword | str:keyword   | x:key
 57          |57           |57           |M               |"57,M"         |M              
 0           |10           |10           |null            |null         |null           
 ;
+
+
+//see https://github.com/elastic/elasticsearch/issues/102912
+statsDissectThatOverwritesAndMvExpand#[skip:-8.11.99]
+row  a = "a", b = 1 | stats  e = min(b) by a | dissect a "%{e}" | mv_expand e;
+
+a:keyword | e:keyword
+a         | a
+;
+

+ 9 - 0
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/Layout.java

@@ -119,5 +119,14 @@ public interface Layout {
             }
             return new DefaultLayout(Collections.unmodifiableMap(layout), numberOfChannels);
         }
+
+        public void replace(NameId id, NameId id1) {
+            for (ChannelSet channel : this.channels) {
+                if (channel != null && channel.nameIds.contains(id)) {
+                    channel.nameIds.remove(id);
+                    channel.nameIds.add(id1);
+                }
+            }
+        }
     }
 }

+ 2 - 13
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java

@@ -581,20 +581,9 @@ public class LocalExecutionPlanner {
 
     private PhysicalOperation planMvExpand(MvExpandExec mvExpandExec, LocalExecutionPlannerContext context) {
         PhysicalOperation source = plan(mvExpandExec.child(), context);
-        List<Attribute> childOutput = mvExpandExec.child().output();
         int blockSize = 5000;// TODO estimate row size and use context.pageSize()
-
-        Layout.Builder layout = new Layout.Builder();
-        List<Layout.ChannelSet> inverse = source.layout.inverse();
-        var expandedName = mvExpandExec.expanded().name();
-        for (int index = 0; index < inverse.size(); index++) {
-            if (childOutput.get(index).name().equals(expandedName)) {
-                layout.append(mvExpandExec.expanded());
-            } else {
-                layout.append(inverse.get(index));
-            }
-        }
-
+        Layout.Builder layout = source.layout.builder();
+        layout.replace(mvExpandExec.target().id(), mvExpandExec.expanded().id());
         return source.with(
             new MvExpandOperator.Factory(source.layout.get(mvExpandExec.target().id()).channel(), blockSize),
             layout.build()