Skip to content

Commit b2fa443

Browse files
Make inline sort alias name a prefix match in testPushTopNInlineDistanceToSource (#114984) (#115015)
* Make inline sort alias name a prefix match This reduces flakiness of this test. * Added comments on prefix check for variable name
1 parent 2749664 commit b2fa443

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,12 +4769,24 @@ public void testPushTopNInlineDistanceToSource() {
47694769
var exchange = asRemoteExchange(topN.child());
47704770

47714771
project = as(exchange.child(), ProjectExec.class);
4772-
assertThat(names(project.projections()), contains("abbrev", "name", "location", "country", "city", "$$order_by$0$0"));
4772+
// Depending on what is run before this test, the synthetic name could have variable suffixes, so we must only assert on the prefix
4773+
assertThat(
4774+
names(project.projections()),
4775+
contains(
4776+
equalTo("abbrev"),
4777+
equalTo("name"),
4778+
equalTo("location"),
4779+
equalTo("country"),
4780+
equalTo("city"),
4781+
startsWith("$$order_by$0$")
4782+
)
4783+
);
47734784
var extract = as(project.child(), FieldExtractExec.class);
47744785
assertThat(names(extract.attributesToExtract()), contains("abbrev", "name", "country", "city"));
47754786
var evalExec = as(extract.child(), EvalExec.class);
47764787
var alias = as(evalExec.fields().get(0), Alias.class);
4777-
assertThat(alias.name(), is("$$order_by$0$0"));
4788+
assertThat(alias.name(), startsWith("$$order_by$0$"));
4789+
var aliasName = alias.name(); // We need this name to know what to assert on later when comparing the Order to the Sort
47784790
var stDistance = as(alias.child(), StDistance.class);
47794791
assertThat(stDistance.left().toString(), startsWith("location"));
47804792
extract = as(evalExec.child(), FieldExtractExec.class);
@@ -4784,7 +4796,7 @@ public void testPushTopNInlineDistanceToSource() {
47844796
// Assert that the TopN(distance) is pushed down as geo-sort(location)
47854797
assertThat(source.limit(), is(topN.limit()));
47864798
Set<String> orderSet = orderAsSet(topN.order());
4787-
Set<String> sortsSet = sortsAsSet(source.sorts(), Map.of("location", "$$order_by$0$0"));
4799+
Set<String> sortsSet = sortsAsSet(source.sorts(), Map.of("location", aliasName));
47884800
assertThat(orderSet, is(sortsSet));
47894801

47904802
// Fine-grained checks on the pushed down sort

0 commit comments

Comments
 (0)