Skip to content

ESQL: Fix Max doubles bug with negatives and add tests for Max and Min #110586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 9, 2024

Conversation

ivancea
Copy link
Contributor

@ivancea ivancea commented Jul 8, 2024

MAX() currently doesn't work with doubles smaller than Double.MIN_VALUE (Note that Double.MIN_VALUE returns the smallest non-zero positive, not the smallest double).

This PR adds tests for Max and Min, and fixes the bug (Detected by the tests).

Also, as the tests now generate the docs, replaced the old docs with the generated ones, and updated the Max&Min examples.

@ivancea ivancea added >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL ES|QL-ui Impacts ES|QL UI labels Jul 8, 2024
@ivancea ivancea requested a review from nik9000 July 8, 2024 13:11
Copy link
Contributor

github-actions bot commented Jul 8, 2024

Documentation preview:

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/kibana-esql (ES|QL-ui)

@elasticsearchmachine
Copy link
Collaborator

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

@@ -166,7 +168,9 @@ private void aggregateWithIntermediates(Expression expression) {

Page inputPage = rows(testCase.getMultiRowFields());
try {
aggregator.processPage(inputPage);
if (inputPage.getPositionCount() > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

This is fine for now, but I wonder if we should make rows make a List<Page> and we dump them all in. So if it spits out no pages that's cool. At some point we're going to have to signal "empty" with no results, but that could live in rows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it already. Maybe check it; I'm creating pages of 1-10 elements. Went with the small values as some hand-made tests may have just a few elements. But it should still work either way, so whatever

rowsCount
)
) {
int pageSize = randomIntBetween(1, 10);
Copy link
Member

Choose a reason for hiding this comment

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

10,000 is a pretty normal size in production. Maybe randomBoolean() ? between(1, 100) : Math.toIntExact(BlockFactory.DEFAULT_MAX_BLOCK_PRIMITIVE_ARRAY_SIZE.getBytes()). Half the time we'll have degenerately small data and half the time it'll probably just be one page.

@ivancea ivancea added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Jul 9, 2024
# Conflicts:
#	docs/reference/esql/functions/aggregation-functions.asciidoc
@elasticsearchmachine elasticsearchmachine merged commit 5d3512f into elastic:main Jul 9, 2024
15 checks passed
@ivancea ivancea deleted the max-min-aggs-tests branch July 9, 2024 11:05
@ivancea ivancea restored the max-min-aggs-tests branch July 9, 2024 11:48
@nik9000 nik9000 added the v8.15.0 label Jul 9, 2024
@nik9000
Copy link
Member

nik9000 commented Jul 9, 2024

backport incoming

@ivancea ivancea deleted the max-min-aggs-tests branch July 9, 2024 12:34
ivancea added a commit that referenced this pull request Jul 9, 2024
Partial backport from #110586

Just the Max fix and an extra test for it.
tvernum pushed a commit that referenced this pull request Feb 25, 2025
#110586)

`MAX()` currently doesn't work with doubles smaller than
`Double.MIN_VALUE` (Note that `Double.MIN_VALUE` returns the smallest
non-zero positive, not the smallest double).

This PR adds tests for Max and Min, and fixes the bug (Detected by the
tests).

Also, as the tests now generate the docs, replaced the old docs with the
generated ones, and updated the Max&Min examples.
tvernum pushed a commit that referenced this pull request Feb 25, 2025
#110586)

`MAX()` currently doesn't work with doubles smaller than
`Double.MIN_VALUE` (Note that `Double.MIN_VALUE` returns the smallest
non-zero positive, not the smallest double).

This PR adds tests for Max and Min, and fixes the bug (Detected by the
tests).

Also, as the tests now generate the docs, replaced the old docs with the
generated ones, and updated the Max&Min examples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >bug ES|QL-ui Impacts ES|QL UI Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.15.0 v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants