Skip to content

Commit

Permalink
Make inline sort alias name a prefix match in testPushTopNInlineDista…
Browse files Browse the repository at this point in the history
…nceToSource (elastic#114984)

* Make inline sort alias name a prefix match

This reduces flakiness of this test.

* Added comments on prefix check for variable name
  • Loading branch information
craigtaverner authored Oct 17, 2024
1 parent 17ecb66 commit 6d039c2
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4769,12 +4769,24 @@ public void testPushTopNInlineDistanceToSource() {
var exchange = asRemoteExchange(topN.child());

project = as(exchange.child(), ProjectExec.class);
assertThat(names(project.projections()), contains("abbrev", "name", "location", "country", "city", "$$order_by$0$0"));
// Depending on what is run before this test, the synthetic name could have variable suffixes, so we must only assert on the prefix
assertThat(
names(project.projections()),
contains(
equalTo("abbrev"),
equalTo("name"),
equalTo("location"),
equalTo("country"),
equalTo("city"),
startsWith("$$order_by$0$")
)
);
var extract = as(project.child(), FieldExtractExec.class);
assertThat(names(extract.attributesToExtract()), contains("abbrev", "name", "country", "city"));
var evalExec = as(extract.child(), EvalExec.class);
var alias = as(evalExec.fields().get(0), Alias.class);
assertThat(alias.name(), is("$$order_by$0$0"));
assertThat(alias.name(), startsWith("$$order_by$0$"));
var aliasName = alias.name(); // We need this name to know what to assert on later when comparing the Order to the Sort
var stDistance = as(alias.child(), StDistance.class);
assertThat(stDistance.left().toString(), startsWith("location"));
extract = as(evalExec.child(), FieldExtractExec.class);
Expand All @@ -4784,7 +4796,7 @@ public void testPushTopNInlineDistanceToSource() {
// Assert that the TopN(distance) is pushed down as geo-sort(location)
assertThat(source.limit(), is(topN.limit()));
Set<String> orderSet = orderAsSet(topN.order());
Set<String> sortsSet = sortsAsSet(source.sorts(), Map.of("location", "$$order_by$0$0"));
Set<String> sortsSet = sortsAsSet(source.sorts(), Map.of("location", aliasName));
assertThat(orderSet, is(sortsSet));

// Fine-grained checks on the pushed down sort
Expand Down

0 comments on commit 6d039c2

Please sign in to comment.