Skip to content

ESQL: Prevent overflow on SUM aggregation#111639

Closed
ivancea wants to merge 30 commits intoelastic:mainfrom
ivancea:sum-warns
Closed

ESQL: Prevent overflow on SUM aggregation#111639
ivancea wants to merge 30 commits intoelastic:mainfrom
ivancea:sum-warns

Conversation

@ivancea
Copy link
Copy Markdown
Contributor

@ivancea ivancea commented Aug 6, 2024

Fixes #110443

This PR does some things:

To be done:

  • Retrocompatibility with older versions

DO NOT MERGE

We can't merge this before the retrocompatibility with older versions is implemented, as we're now adding a new block to the intermediate state.

@ivancea ivancea added >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL labels Aug 6, 2024
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @ivancea, I've updated the changelog YAML for you.

}
}
}
return result;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a copy of some other code. Could we make a static reference instead here? At least for some of it. It's so weird.

protected final BigArrays bigArrays;

private BitArray seen;
private BitArray failed;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's worth a comment here about when these are initialized. And I think it's also worth a comment about why you didn't use an enum or an array of two-bit values. I think it's correct to use to BitArrays here because frequently you won't need either. And when you need seen you often won't need failed. That's why I think you did it this way. And, also, it's probably easier to do it this way....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we could do it with an enum-like array. We would lose tho the "false by default" feature of those bitarrays that avoid growing them for falses, and it would take more memory I expect.
Tbh, I didn't consider it, this looked quite minimal.

Going to comment both of them. If you think using other kind of container would be worth it, just tell me!

* idempotent and fast if already tracking so it's safe to, say, call it once
* for every block of values that arrives containing {@code null}.
*/
final void enableGroupIdTracking(SeenGroupIds seenGroupIds) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this extend from AbstractArrayState? Are these the same plus the extra failure methods?

addedWarnings++;
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's be fine to just move warnings here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, not in the aggregation package, but into compute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The existing Warnings depends on Source too, which is also from esql-core. Here this receives the required Source parts (line and col numbers + text). But I don't think it's worth changing everything to do it that way (?)

I'll check it. I could try something like keeping a "Warnings" in esql-core with just that conversion. Looks weird tho (Not that this doesn't look weird btw)

$endif$
$if(boolean||double||float)$
import org.elasticsearch.compute.data.IntVector;
$endif$
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again, I'm sorry for this silly dance we have to do for imports. I just couldn't figure out a way to turn off the import checkstyle rule for just this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a copypaste+failed things, I didn't touch anything here :hehe:

I'll diff them in case it's worth like, adding an extra parameter to generate both (fallible and non fallible) from the same template. But I'll try to not overcomplicate it, I don't want 2 levels of templating here 😆

ivancea added a commit that referenced this pull request Aug 21, 2024
Add the `warnExceptions` capability to aggregators. Same as for evaluators. This requires:
- Having a "Warnings-like" object in the compute module. I created a new class for that, temporarily
- Added new "FaillibleState" objects, that hold a "failed" boolean/bitset to mark failed groups
- Catching exceptions in all combine methods receiving a single group (Not catching in evaluateFinal/Intermediate, nor in combines that receive the full state)
- Shortcircuiting operations if the group is in "failed" state
- Having a third intermediate state: `values, seen, failed`

Extracted from #111639. Check it to see a use case
# Conflicts:
#	x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/AbstractFallibleArrayState.java
# Conflicts:
#	x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongGroupingAggregatorFunction.java
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this pull request Sep 4, 2024
Add the `warnExceptions` capability to aggregators. Same as for evaluators. This requires:
- Having a "Warnings-like" object in the compute module. I created a new class for that, temporarily
- Added new "FaillibleState" objects, that hold a "failed" boolean/bitset to mark failed groups
- Catching exceptions in all combine methods receiving a single group (Not catching in evaluateFinal/Intermediate, nor in combines that receive the full state)
- Shortcircuiting operations if the group is in "failed" state
- Having a third intermediate state: `values, seen, failed`

Extracted from elastic#111639. Check it to see a use case
davidkyle pushed a commit to davidkyle/elasticsearch that referenced this pull request Sep 5, 2024
Add the `warnExceptions` capability to aggregators. Same as for evaluators. This requires:
- Having a "Warnings-like" object in the compute module. I created a new class for that, temporarily
- Added new "FaillibleState" objects, that hold a "failed" boolean/bitset to mark failed groups
- Catching exceptions in all combine methods receiving a single group (Not catching in evaluateFinal/Intermediate, nor in combines that receive the full state)
- Shortcircuiting operations if the group is in "failed" state
- Having a third intermediate state: `values, seen, failed`

Extracted from elastic#111639. Check it to see a use case
@ivancea ivancea changed the title ESQL: Add warnings capabilities to aggregators, and prevent overflow on SUM aggregation ESQL: Prevent overflow on SUM aggregation Sep 13, 2024
# Conflicts:
#	x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunction.java
#	x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BlockSerializationTests.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java
# Conflicts:
#	x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/SumLongAggregatorFunction.java
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.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ESQL] Aggregations - return null values for individual buckets on errors

4 participants