Skip to content

Commit 3afecaa

Browse files
committed
refactor(esql): Improve MvExpand push-down logic in logical optimizer
- Simplified push-down logic for MvExpand past Project operations - Removed unnecessary Limit operation from example comment - Used `replaceChild()` method instead of creating a new MvExpand instance - Streamlined code for pushing down MvExpand past Project nodes - Improved code readability and reduced complexity of optimizer rule
1 parent 6018ce0 commit 3afecaa

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PushDownMvExpandPastProject.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ protected LogicalPlan rule(MvExpand mvExpand) {
3232
// Example:
3333
// MvExpand[salary{r}#168,salary{r}#175]
3434
// \_Project[[$$salary$converted_to$keyword{r$}#178 AS salary#168]]
35-
// \_Limit[1000[INTEGER],false,false]
36-
// \_UnionAll[[salary{r}#174, $$salary$converted_to$keyword{r$}#178]]
35+
// \_UnionAll[[salary{r}#174, $$salary$converted_to$keyword{r$}#178]]
3736
Set<String> inputNames = pj.inputSet().stream().map(NamedExpression::name).collect(Collectors.toSet());
3837
if (projections.stream().anyMatch(e -> e instanceof Alias alias && inputNames.contains(alias.toAttribute().name()))) {
3938
return mvExpand;
@@ -75,7 +74,7 @@ protected LogicalPlan rule(MvExpand mvExpand) {
7574
AttributeMap<Alias> aliases = aliasBuilder.build();
7675

7776
// Push down the MvExpand past the Project
78-
MvExpand pushedDownMvExpand = new MvExpand(mvExpand.source(), pj.child(), mvExpand.target(), mvExpand.expanded());
77+
MvExpand pushedDownMvExpand = mvExpand.replaceChild(pj.child());
7978

8079
// Create a new projection at the top based on mvExpand.output(), plugging back in the aliases
8180
List<NamedExpression> newProjections = new ArrayList<>();

0 commit comments

Comments
 (0)