Skip to content

Commit

Permalink
Fix layout for MV_EXPAND (#102916)
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed Dec 5, 2023
1 parent ccf92e4 commit 43c320f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/102916.yaml
@@ -0,0 +1,6 @@
pr: 102916
summary: Fix layout for MV_EXPAND
area: ES|QL
type: bug
issues:
- 102912
Expand Up @@ -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
;

Expand Up @@ -119,5 +119,14 @@ public Layout build() {
}
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);
}
}
}
}
}
Expand Up @@ -581,20 +581,9 @@ private PhysicalOperation planLimit(LimitExec limit, LocalExecutionPlannerContex

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()
Expand Down

0 comments on commit 43c320f

Please sign in to comment.