Skip to content

Conversation

@ncordon
Copy link
Contributor

@ncordon ncordon commented Nov 20, 2025

Why

Now that we have added outputField to Top, we should not be using Max or Min when there is an outputField because those expressions do not take an outputField.

This was causing some test flakiness. The tests were not failing consistently because this only happens for a limit of 1 (and limit is also randomized in the tests).

Closes #134083

@ncordon ncordon added >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v9.3.0 labels Nov 20, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @ncordon, I've created a changelog YAML for you.

@ncordon ncordon force-pushed the fix-edge-case-in-top branch from cd95fe8 to 954c27f Compare November 20, 2025 17:12
@ncordon ncordon marked this pull request as ready for review November 20, 2025 17:12
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Hi @ncordon, I've created a changelog YAML for you.

}
if (orderField() instanceof Literal && limitField() instanceof Literal && limitValue() == 1) {
// To replace Top by Min or Max, we cannot have an `outputField`
if (orderField() instanceof Literal && limitField() instanceof Literal && limitValue() == 1 && outputField() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some CSV test reproducing this case? To ensure that this indeed failed before the fix.
A surrogate changing the result type of the expression is a quite hardcore error at planning time.
Our unit tests happen to execute the surrogate logic, but it's really executed as part of the planning, so having an integration test checking it looks safer (Apart of the unit tests, which look fine)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. If I backtrack the fix, the following error is thrown in those tests (which I find not very helpful), so you are right the planner would not let this through:

Output has changed from [[shortest_employee{r}#577, tallest_employee{r}#581]] to [[shortest_employee{r}#577, tallest_employee{r}#581]].

Copy link
Contributor

@ivancea ivancea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ncordon ncordon merged commit 3b4d53e into elastic:main Nov 24, 2025
34 checks passed
szybia added a commit to szybia/elasticsearch that referenced this pull request Nov 24, 2025
…-json

* upstream/main: (247 commits)
  Mute org.elasticsearch.xpack.inference.integration.SemanticTextIndexOptionsIT testValidateIndexOptionsWithBasicLicense elastic#138513
  Mute org.elasticsearch.xpack.esql.heap_attack.HeapAttackLookupJoinIT testLookupExplosionBigString elastic#138510
  This shouldn't be zero (elastic#138501)
  sum of empty histogram is now null (elastic#138378)
  Test ES|QL bfloat16 support (elastic#138499)
  Fix exception handling in S3 `compareAndExchangeRegister` (elastic#138488)
  Mute org.elasticsearch.xpack.exponentialhistogram.ExponentialHistogramFieldMapperTests testFormattedDocValues elastic#138504
  Mute org.elasticsearch.ingest.geoip.IngestGeoIpClientYamlTestSuiteIT test {yaml=ingest_geoip/60_ip_location_databases/Test adding, getting, and removing ip location databases} elastic#138502
  ESQL: Refactor HeapAttackIT (elastic#138432)
  [Inference API] Add ElasticInferenceServiceDenseTextEmbeddingsServiceSettings to InferenceNamedWriteablesProvider (elastic#138484)
  Store split indices (elastic#138396)
  ES|QL Update CHUNK to support chunking_settings as optional argument (elastic#138123)
  Extract common blob-update logic in `S3HttpHandler` (elastic#138490)
  Cleanup esql request building api (elastic#138398)
  Round sum and avg in exponential_histogram CSV tests (elastic#138472)
  ESQL: load exponential_histogram total count as double instead of long (elastic#138417)
  [SIMD] Use fixed width native types for better Java interoperability (elastic#138429)
  Do not use Min or Max as Top's surrogate when there is an outputField (elastic#138380)
  ES|QL: Fix generative tests (elastic#138478)
  Mute org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT testCreatesEisChatCompletion_DoesNotRemoveEndpointWhenNoLongerAuthorized elastic#138480
  ...
afoucret pushed a commit to afoucret/elasticsearch that referenced this pull request Nov 26, 2025
ncordon added a commit to ncordon/elasticsearch that referenced this pull request Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] TopTests class failing

3 participants