Skip to content

Commit 98140a3

Browse files
committed
Further tests adjustments
1 parent 4aeca51 commit 98140a3

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

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

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,10 +1044,12 @@ public void testPushdownLimitsPastLeftJoin() {
10441044

10451045
var optimizedPlan = rule.apply(limit, logicalOptimizerCtx);
10461046

1047-
assertEquals(
1048-
new Limit(limit.source(), limit.limit(), join.replaceChildren(limit.replaceChild(join.left()), join.right()), true),
1049-
optimizedPlan
1050-
);
1047+
var expectedPlan = join instanceof InlineJoin
1048+
? new Limit(limit.source(), limit.limit(), join, false)
1049+
: new Limit(limit.source(), limit.limit(), join.replaceChildren(limit.replaceChild(join.left()), join.right()), true);
1050+
1051+
1052+
assertEquals(expectedPlan, optimizedPlan);
10511053

10521054
var optimizedTwice = rule.apply(optimizedPlan, logicalOptimizerCtx);
10531055
// We mustn't create the limit after the JOIN multiple times when the rule is applied multiple times, that'd lead to infinite loops.
@@ -5714,17 +5716,14 @@ public void testReplaceSortByExpressionsWithStats() {
57145716
as(aggregate.child(), EsRelation.class);
57155717
}
57165718

5717-
/**
5718-
* <pre>{@code
5719-
* Limit[1000[INTEGER],true]
5719+
/*
5720+
* Limit[1000[INTEGER],false]
57205721
* \_InlineJoin[LEFT,[emp_no % 2{r}#6],[emp_no % 2{r}#6],[emp_no % 2{r}#6]]
57215722
* |_Eval[[emp_no{f}#7 % 2[INTEGER] AS emp_no % 2#6]]
5722-
* | \_Limit[1000[INTEGER],false] <-- TODO: this needs to go
5723-
* | \_EsRelation[test][_meta_field{f}#13, emp_no{f}#7, first_name{f}#8, ge..]
5723+
* | \_EsRelation[test][_meta_field{f}#13, emp_no{f}#7, first_name{f}#8, ge..]
57245724
* \_Aggregate[[emp_no % 2{r}#6],[COUNT(salary{f}#12,true[BOOLEAN]) AS c#4, emp_no % 2{r}#6]]
57255725
* \_StubRelation[[_meta_field{f}#13, emp_no{f}#7, first_name{f}#8, gender{f}#9, hire_date{f}#14, job{f}#15, job.raw{f}#16, lang
57265726
* uages{f}#10, last_name{f}#11, long_noidx{f}#17, salary{f}#12, emp_no % 2{r}#6]]
5727-
* }</pre>
57285727
*/
57295728
public void testInlinestatsNestedExpressionsInGroups() {
57305729
var query = """
@@ -5739,7 +5738,7 @@ public void testInlinestatsNestedExpressionsInGroups() {
57395738
var inline = as(limit.child(), InlineJoin.class);
57405739
var eval = as(inline.left(), Eval.class);
57415740
assertThat(Expressions.names(eval.fields()), is(List.of("emp_no % 2")));
5742-
limit = asLimit(eval.child(), 1000, false);
5741+
var relation = as(eval.child(), EsRelation.class);
57435742
var agg = as(inline.right(), Aggregate.class);
57445743
var groupings = agg.groupings();
57455744
var ref = as(groupings.get(0), ReferenceAttribute.class);
@@ -5811,17 +5810,14 @@ public void testDoubleInlinestatsGetsPrunedEntirely() {
58115810
var relation = as(topN.child(), EsRelation.class);
58125811
}
58135812

5814-
/**
5815-
* <pre>{@code
5813+
/*
58165814
* Project[[emp_no{f}#15 AS x#11, a{r}#7, emp_no{f}#15]]
5817-
* \_Limit[1[INTEGER],true]
5815+
* \_Limit[1[INTEGER],false]
58185816
* \_InlineJoin[LEFT,[emp_no{f}#15],[emp_no{f}#15],[emp_no{r}#15]]
5819-
* |_Limit[1[INTEGER],false] <-- TODO: this needs to go
5820-
* | \_EsRelation[test][_meta_field{f}#21, emp_no{f}#15, first_name{f}#16, ..]
5817+
* |_EsRelation[test][_meta_field{f}#21, emp_no{f}#15, first_name{f}#16, ..]
58215818
* \_Aggregate[[emp_no{f}#15],[COUNTDISTINCT(languages{f}#18,true[BOOLEAN]) AS a#7, emp_no{f}#15]]
58225819
* \_StubRelation[[_meta_field{f}#21, emp_no{f}#15, first_name{f}#16, gender{f}#17, hire_date{f}#22, job{f}#23, job.raw{f}#24, l
58235820
* anguages{f}#18, last_name{f}#19, long_noidx{f}#25, salary{f}#20]]
5824-
* }</pre>
58255821
*/
58265822
public void testInlinestatsGetsPrunedPartially() {
58275823
var query = """
@@ -5838,13 +5834,11 @@ public void testInlinestatsGetsPrunedPartially() {
58385834

58395835
var project = as(plan, Project.class);
58405836
assertThat(Expressions.names(project.projections()), is(List.of("x", "a", "emp_no")));
5841-
var upperLimit = asLimit(project.child(), 1, true);
5837+
var upperLimit = asLimit(project.child(), 1, false);
58425838
var inlineJoin = as(upperLimit.child(), InlineJoin.class);
58435839
assertThat(Expressions.names(inlineJoin.config().matchFields()), is(List.of("emp_no")));
58445840
// Left
5845-
var limit = as(inlineJoin.left(), Limit.class); // TODO: this needs to go
5846-
assertThat(limit.limit().fold(FoldContext.small()), equalTo(1));
5847-
var relation = as(limit.child(), EsRelation.class);
5841+
var relation = as(inlineJoin.left(), EsRelation.class);
58485842
// Right
58495843
var agg = as(inlineJoin.right(), Aggregate.class);
58505844
assertMap(Expressions.names(agg.output()), is(List.of("a", "emp_no")));
@@ -5869,13 +5863,11 @@ public void testTrippleInlinestatsGetsPrunedPartially() {
58695863

58705864
var project = as(plan, Project.class);
58715865
assertThat(Expressions.names(project.projections()), is(List.of("x", "a", "emp_no")));
5872-
var upperLimit = asLimit(project.child(), 1, true);
5866+
var upperLimit = asLimit(project.child(), 1, false);
58735867
var inlineJoin = as(upperLimit.child(), InlineJoin.class);
58745868
assertThat(Expressions.names(inlineJoin.config().matchFields()), is(List.of("emp_no")));
58755869
// Left
5876-
var limit = as(inlineJoin.left(), Limit.class);
5877-
assertThat(limit.limit().fold(FoldContext.small()), equalTo(1));
5878-
var relation = as(limit.child(), EsRelation.class);
5870+
var relation = as(inlineJoin.left(), EsRelation.class);
58795871
// Right
58805872
var agg = as(inlineJoin.right(), Aggregate.class);
58815873
assertMap(Expressions.names(agg.output()), is(List.of("a", "emp_no")));
@@ -5926,20 +5918,17 @@ public void testInlinestatsWithLookupJoin() {
59265918
assertThat(right.concreteIndices(), is(Set.of("languages_lookup")));
59275919
}
59285920

5929-
/**
5930-
* <pre>{@code
5921+
/*
59315922
* EsqlProject[[avg{r}#4, emp_no{f}#9, first_name{f}#10]]
5932-
* \_Limit[10[INTEGER],true]
5923+
* \_Limit[10[INTEGER],false]
59335924
* \_InlineJoin[LEFT,[emp_no{f}#9],[emp_no{f}#9],[emp_no{r}#9]]
5934-
* |_Limit[10[INTEGER],false] <-- TODO: this needs to go
5935-
* | \_EsRelation[test][_meta_field{f}#15, emp_no{f}#9, first_name{f}#10, g..]
5925+
* |_EsRelation[test][_meta_field{f}#15, emp_no{f}#9, first_name{f}#10, g..]
59365926
* \_Project[[avg{r}#4, emp_no{f}#9]]
59375927
* \_Eval[[$$SUM$avg$0{r$}#20 / $$COUNT$avg$1{r$}#21 AS avg#4]]
59385928
* \_Aggregate[[emp_no{f}#9],[SUM(salary{f}#14,true[BOOLEAN]) AS $$SUM$avg$0#20, COUNT(salary{f}#14,true[BOOLEAN]) AS $$COUNT$
59395929
* avg$1#21, emp_no{f}#9]]
59405930
* \_StubRelation[[_meta_field{f}#15, emp_no{f}#9, first_name{f}#10, gender{f}#11, hire_date{f}#16, job{f}#17, job.raw{f}#18,
59415931
* languages{f}#12, last_name{f}#13, long_noidx{f}#19, salary{f}#14]]
5942-
* }</pre>
59435932
*/
59445933
public void testInlinestatsWithAvg() {
59455934
var query = """
@@ -5955,12 +5944,11 @@ public void testInlinestatsWithAvg() {
59555944

59565945
var esqlProject = as(plan, EsqlProject.class);
59575946
assertThat(Expressions.names(esqlProject.projections()), is(List.of("avg", "emp_no", "first_name")));
5958-
var upperLimit = asLimit(esqlProject.child(), 10, true);
5947+
var upperLimit = asLimit(esqlProject.child(), 10, false);
59595948
var inlineJoin = as(upperLimit.child(), InlineJoin.class);
59605949
assertThat(Expressions.names(inlineJoin.config().matchFields()), is(List.of("emp_no")));
59615950
// Left
5962-
var limit = asLimit(inlineJoin.left(), 10, false); // TODO: this needs to go
5963-
var relation = as(limit.child(), EsRelation.class);
5951+
var relation = as(inlineJoin.left(), EsRelation.class);
59645952
// Right
59655953
var project = as(inlineJoin.right(), Project.class);
59665954
assertThat(Expressions.names(project.projections()), contains("avg", "emp_no"));

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ReplaceStatsFilteredAggWithEvalTests.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,11 @@ public void testReplaceInlinestatsFilteredAggWithEvalSingleAggWithExpression() {
463463
as(limit.child(), EsRelation.class);
464464
}
465465

466-
/**
467-
* Limit[1000[INTEGER],true]
466+
/*
467+
* Limit[1000[INTEGER],false]
468468
* \_InlineJoin[LEFT,[emp_no{f}#9],[emp_no{f}#9],[emp_no{r}#9]]
469469
* |_EsqlProject[[salary{f}#14, emp_no{f}#9]]
470-
* | \_Limit[1000[INTEGER],false]
471-
* | \_EsRelation[test][_meta_field{f}#15, emp_no{f}#9, first_name{f}#10, g..]
470+
* | \_EsRelation[test][_meta_field{f}#15, emp_no{f}#9, first_name{f}#10, g..]
472471
* \_Project[[sum(salary) 1 where false{r}#5, sum(salary) 2{r}#7, emp_no{f}#9]]
473472
* \_Eval[[null[LONG] AS sum(salary) 1 where false#5, $$SUM$sum(salary)_ _2$1{r$}#21 2[INTEGER] AS sum(salary) 2#7]]
474473
* \_Aggregate[[emp_no{f}#9],[SUM(salary{f}#14,true[BOOLEAN],compensated[KEYWORD]) AS $$SUM$sum(salary)_ _2$1#21, emp_no{f}#9]]
@@ -487,8 +486,7 @@ public void testReplaceInlinestatsFilteredAggWithEvalMixedFilterAndNoFilter() {
487486
var ij = as(limit.child(), InlineJoin.class);
488487
var left = as(ij.left(), EsqlProject.class);
489488
assertThat(Expressions.names(left.projections()), contains("salary", "emp_no"));
490-
limit = as(left.child(), Limit.class);
491-
as(limit.child(), EsRelation.class);
489+
var relation = as(left.child(), EsRelation.class);
492490
var right = as(ij.right(), Project.class);
493491
assertMap(
494492
Expressions.names(right.projections()).stream().map(Object::toString).toList(),
@@ -598,12 +596,11 @@ public void testReplaceInlinestatsFilteredAggWithEvalNotTrue() {
598596
as(limit.child(), EsRelation.class);
599597
}
600598

601-
/**
599+
/*
602600
* Limit[1000[INTEGER],true]
603601
* \_InlineJoin[LEFT,[],[],[]]
604602
* |_EsqlProject[[emp_no{f}#8, salary{f}#13, gender{f}#10]]
605-
* | \_Limit[1000[INTEGER],false]
606-
* | \_EsRelation[test][_meta_field{f}#14, emp_no{f}#8, first_name{f}#9, ge..]
603+
* | \_EsRelation[test][_meta_field{f}#14, emp_no{f}#8, first_name{f}#9, ge..]
607604
* \_Aggregate[[],[COUNT(salary{f}#13,true[BOOLEAN]) AS m1#7]]
608605
* \_StubRelation[[emp_no{f}#8, salary{f}#13, gender{f}#10]]
609606
*/
@@ -618,8 +615,7 @@ public void testReplaceInlinestatsFilteredAggWithEvalNotFalse() {
618615

619616
var left = as(ij.left(), EsqlProject.class);
620617
assertThat(Expressions.names(left.projections()), contains("emp_no", "salary", "gender"));
621-
var leftLimit = as(left.child(), Limit.class);
622-
as(leftLimit.child(), EsRelation.class);
618+
var relation = as(left.child(), EsRelation.class);
623619

624620
var right = as(ij.right(), Aggregate.class);
625621
assertThat(Expressions.names(right.aggregates()), contains("m1"));
@@ -687,8 +683,7 @@ public void testReplaceInlinestatsFilteredAggWithEvalCountDistinctInExpression()
687683
* Limit[1000[INTEGER],true]
688684
* \_InlineJoin[LEFT,[emp_no{f}#17],[emp_no{f}#17],[emp_no{r}#17]]
689685
* |_EsqlProject[[emp_no{f}#17, salary{f}#22]]
690-
* | \_Limit[1000[INTEGER],false]
691-
* | \_EsRelation[test][_meta_field{f}#23, emp_no{f}#17, first_name{f}#18, ..]
686+
* | \_EsRelation[test][_meta_field{f}#23, emp_no{f}#17, first_name{f}#18, ..]
692687
* \_Project[[max{r}#6, max_a{r}#9, min{r}#12, min_a{r}#15, emp_no{f}#17]]
693688
* \_Eval[[null[INTEGER] AS max_a#9, null[INTEGER] AS min_a#15]]
694689
* \_Aggregate[[emp_no{f}#17],[MAX(salary{f}#22,true[BOOLEAN]) AS max#6, MIN(salary{f}#22,true[BOOLEAN]) AS min#12, emp_no{f}#17]]
@@ -708,8 +703,7 @@ public void testReplaceInlinestatsFilteredAggWithEvalSameAggWithAndWithoutFilter
708703

709704
var left = as(ij.left(), EsqlProject.class);
710705
assertThat(Expressions.names(left.projections()), contains("emp_no", "salary"));
711-
var leftLimit = as(left.child(), Limit.class);
712-
as(leftLimit.child(), EsRelation.class);
706+
var relation = as(left.child(), EsRelation.class);
713707

714708
var right = as(ij.right(), Project.class);
715709
assertThat(Expressions.names(right.projections()), contains("max", "max_a", "min", "min_a", "emp_no"));

0 commit comments

Comments
 (0)