Skip to content

Commit 7fe8f79

Browse files
committed
adjust one more test
1 parent 7904057 commit 7fe8f79

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/inlinestats.csv-spec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4454,11 +4454,12 @@ required_capability: join_lookup_v12
44544454
FROM airports
44554455
| EVAL backup_scalerank = scalerank
44564456
| RENAME scalerank AS language_code
4457-
| SORT abbrev DESC
4457+
// | SORT abbrev DESC // this would work here, but not in a FORK config (GenerativeForkIT), which disables column pruning
44584458
| LOOKUP JOIN languages_lookup ON language_code
44594459
| RENAME language_name as scalerank
44604460
| DROP language_code
44614461
| INLINE STATS count=COUNT(*) BY scalerank
4462+
| SORT abbrev DESC
44624463
| KEEP abbrev, *scalerank
44634464
| LIMIT 5
44644465
;

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.xpack.esql.plan.logical.Sample;
2828
import org.elasticsearch.xpack.esql.plan.logical.TopN;
2929
import org.elasticsearch.xpack.esql.plan.logical.join.InlineJoin;
30+
import org.elasticsearch.xpack.esql.plan.logical.join.Join;
3031
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes;
3132
import org.elasticsearch.xpack.esql.plan.logical.join.StubRelation;
3233
import org.elasticsearch.xpack.esql.plan.logical.local.EsqlProject;
@@ -902,6 +903,55 @@ public void testInlineStatsAfterEnrichAndSort() {
902903
var stub = as(agg.child(), StubRelation.class);
903904
}
904905

906+
/**
907+
* Project[[abbrev{f}#20, scalerank{f}#22 AS backup_scalerank#5, language_name{f}#29 AS scalerank#13]]
908+
* \_Limit[1000[INTEGER],true,false]
909+
* \_Join[LEFT,[scalerank{f}#22],[language_code{f}#28],null]
910+
* |_TopN[[Order[abbrev{f}#20,DESC,FIRST]],1000[INTEGER],false]
911+
* | \_EsRelation[airports][abbrev{f}#20, city{f}#26, city_location{f}#27, coun..]
912+
* \_EsRelation[languages_lookup][LOOKUP][language_code{f}#28, language_name{f}#29]
913+
*/
914+
public void testInlineJoinPrunedAfterSortAndLookupJoin() {
915+
var query = """
916+
FROM airports
917+
| EVAL backup_scalerank = scalerank
918+
| RENAME scalerank AS language_code
919+
| SORT abbrev DESC
920+
| LOOKUP JOIN languages_lookup ON language_code
921+
| RENAME language_name as scalerank
922+
| DROP language_code
923+
| INLINE STATS count=COUNT(*) BY scalerank
924+
| KEEP abbrev, *scalerank
925+
""";
926+
if (releaseBuildForInlineStats(query)) {
927+
return;
928+
}
929+
var plan = planAirports(query);
930+
931+
var project = as(plan, Project.class);
932+
assertThat(Expressions.names(project.projections()), is(List.of("abbrev", "backup_scalerank", "scalerank")));
933+
934+
var limit = as(project.child(), Limit.class);
935+
assertThat(limit.limit().fold(FoldContext.small()), equalTo(1000));
936+
937+
var join = as(limit.child(), Join.class);
938+
assertThat(join.config().type(), is(JoinTypes.LEFT));
939+
940+
var topN = as(join.left(), TopN.class);
941+
assertThat(topN.limit().fold(FoldContext.small()), equalTo(1000));
942+
assertThat(topN.order(), hasSize(1));
943+
var order = as(topN.order().get(0), Order.class);
944+
assertThat(order.direction(), equalTo(Order.OrderDirection.DESC));
945+
assertThat(order.nullsPosition(), equalTo(Order.NullsPosition.FIRST));
946+
assertThat(Expressions.name(order.child()), is("abbrev"));
947+
948+
var leftRelation = as(topN.child(), EsRelation.class);
949+
assertThat(leftRelation.concreteIndices(), is(Set.of("airports")));
950+
951+
var rightRelation = as(join.right(), EsRelation.class);
952+
assertThat(rightRelation.concreteIndices(), is(Set.of("languages_lookup")));
953+
}
954+
905955
public void testFailureWhenSortAndSortBreakerBeforeInlineStats() {
906956
assumeTrue("LIMIT before INLINE STATS limitation check", EsqlCapabilities.Cap.INLINE_STATS.isEnabled());
907957
/*

0 commit comments

Comments
 (0)