Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
ES|QL categorize with multiple groupings #118173
base: main
Are you sure you want to change the base?
ES|QL categorize with multiple groupings #118173
Changes from all commits
41279c7
9f770d5
d7af8bf
e6ac068
35e9811
b44663a
82a38f9
5121e9a
3c0325a
e05f860
abfc211
54ac1bf
5eb5189
1deb2d4
a633806
e639268
5a4c8bb
5ecc9f9
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit/bikeshed: throwing
IllegalArgumentException
would be more friendly towards test; when assertions trigger, they bring down a whole node because that's an error, not exception. It's probably fine, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't happen, right? If this assertion fails, other code is broken (the verifier). I'll leave it as is unless you object. BTW, do you know if we run assertions in production?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions are disabled in Prod, and this indeed shouldn't happen. Occasionally, a bug slips through, though, and when it triggers an assertion, it kill the whole IT suite run because it kills a node. It's fine to leave as-is, though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ definitely easier to grasp, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for now: We're repeating, potentially, a lot of bytesref values here. I wonder if there is or it would make sense to have a BytesRefBlock that instead of all the bytesrefs, stores every value just once, and then a reference per position:
->
@nik9000 Something to consider for later? Maybe it's too specific for this. And anyway, the next EVAL or whatever will duplicate the value again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a nice thing to have, but definitely out of scope for this PR.
However, the next
EVAL
should not duplicate the value again.If you have:
then an efficient
EVAL x=SUBSTRING(x, 1, 2)
should givewithout ever duplicating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that SUBSTRING to not duplicate, we would need to add that "hashtable" strategy in the BytesRefBlockBuilder. It looks goo (?), but I wonder if using that by default could perform negatively in some scenarios. Something to try eventually probably
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like worth trying in the future. Are you making a note (issue) of this, so that the idea doesn't get lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I'll comment it with Nik, just in case it was considered and discarded already, and then I'll document it in an issue somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little afraid that we allocate potentially quite a bit of memory without asking the breaker first. I believe this will lead to tricky-to-debug situations when the memory pressure is already high and this leads to an OOM. Not sure how likely, but still.
The
blockFactory
has convenience methodspreAdjustBreakerForInt
andadjustBreaker
that we better use here. That needs to be done carefully re. try/catching as not to have a circuit breaker leak.@nik9000 wdyt? Should we play it safe here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of manually handling the memory here, maybe we should just do a
idsVector.writeTo(...)
, so we remove a chunk of code from here, and avoid allocating anything else?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to track these. I'm not sure it has to be a blocker though. Until a few months ago aggs didn't track the a few similar things to this. OTOH, it could cause problems.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it looks like we just
writeIntArray
with this. In that case, yeah, I'd write the ids manually.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I checked and we also don't really track memory in
CategorizeBlockHash.getKeys
;neither do we track the memory for the categorizer itself.Update: actually, we probably do - so that should be covered.The problem here is that due to combinatorial explosion, the untracked memory when writing the idsVector can be a lot larger than the actual categorizer state.
E.g.
STATS ... BY CATEGORIZE(message), field1, field2
.If there are
n
categories ofmessages
,m
distinctfield1
values ando
distinctfield2
values, then the number of rows - and thus ids - will ben*m*o
. And we're copying this twice: once into anint[]
and another time when writing intoout
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave this up to you all to decide...