Skip to content

Commit 44fcd8f

Browse files
committed
Add LogicalPlanOptimizer test
1 parent f4cc63d commit 44fcd8f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or;
4242
import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNotNull;
4343
import org.elasticsearch.xpack.esql.core.expression.predicate.operator.comparison.BinaryComparison;
44+
import org.elasticsearch.xpack.esql.core.tree.Source;
4445
import org.elasticsearch.xpack.esql.core.type.DataType;
4546
import org.elasticsearch.xpack.esql.core.type.EsField;
4647
import org.elasticsearch.xpack.esql.core.util.Holder;
@@ -113,7 +114,9 @@
113114
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan;
114115
import org.elasticsearch.xpack.esql.plan.logical.join.InlineJoin;
115116
import org.elasticsearch.xpack.esql.plan.logical.join.Join;
117+
import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig;
116118
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes;
119+
import org.elasticsearch.xpack.esql.plan.logical.join.LookupJoin;
117120
import org.elasticsearch.xpack.esql.plan.logical.local.EsqlProject;
118121
import org.elasticsearch.xpack.esql.plan.logical.local.LocalRelation;
119122
import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier;
@@ -139,6 +142,7 @@
139142
import static org.elasticsearch.xpack.esql.EsqlTestUtils.TWO;
140143
import static org.elasticsearch.xpack.esql.EsqlTestUtils.as;
141144
import static org.elasticsearch.xpack.esql.EsqlTestUtils.emptySource;
145+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.fieldAttribute;
142146
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getFieldAttribute;
143147
import static org.elasticsearch.xpack.esql.EsqlTestUtils.loadMapping;
144148
import static org.elasticsearch.xpack.esql.EsqlTestUtils.localSource;
@@ -1294,6 +1298,29 @@ public void testCombineLimits() {
12941298
);
12951299
}
12961300

1301+
public void testPushdownLimitsPastLeftJoin() {
1302+
var leftChild = emptySource();
1303+
var rightChild = new LocalRelation(Source.EMPTY, List.of(fieldAttribute()), LocalSupplier.EMPTY);;
1304+
assertNotEquals(leftChild, rightChild);
1305+
1306+
var joinConfig = new JoinConfig(JoinTypes.LEFT, List.of(), List.of(), List.of());
1307+
var join = switch (randomIntBetween(0, 2)) {
1308+
case 0 -> new Join(EMPTY, leftChild, rightChild, joinConfig);
1309+
case 1 -> new LookupJoin(EMPTY, leftChild, rightChild, joinConfig);
1310+
case 2 -> new InlineJoin(EMPTY, leftChild, rightChild, joinConfig);
1311+
default -> throw new IllegalArgumentException();
1312+
};
1313+
1314+
var limit = new Limit(EMPTY, L(10), join);
1315+
1316+
var optimizedPlan = new PushDownAndCombineLimits().rule(limit);
1317+
1318+
assertEquals(
1319+
join.replaceChildren(limit.replaceChild(join.left()), join.right()),
1320+
optimizedPlan
1321+
);
1322+
}
1323+
12971324
public void testMultipleCombineLimits() {
12981325
var numberOfLimits = randomIntBetween(3, 10);
12991326
var minimum = randomIntBetween(10, 99);

0 commit comments

Comments
 (0)