Skip to content
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

ESQL: Method to convert BooleanBlock to a "mask" #112253

Merged
merged 5 commits into from
Aug 29, 2024
Merged

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Aug 27, 2024

This adds a method, BooleanBlock#toMask to convert BooleanBlocks into a "mask" for use with keepMask.

This adds a method, `BooleanBlock#toMask` to convert `BooleanBlock`s
into a "mask" for use with `keepMask`.
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Aug 27, 2024
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

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

LGTM, only minor remarks!

$elseif(boolean)$
/**
* Convert this to a {@link BooleanVector "mask"} that's appropriate for
* passing to {@link #keepMask}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: let's describe what to expect in case of null values and multivalues.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

/**
* Result from calling {@link BooleanBlock#toMask}. {@link #close closing} this will
* close the contained {@link #mask()}. If you want to keep a reference to it then you'll
* have to {@link Block#incRef()} it.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this doesn't implement incref/RefCounted/AbstractNonThreadSafeRefCounted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Block's ref counted - this is sort of like a single reference to it. Not sure if that's clear though.

Comment on lines 88 to 91
/**
* Convert this to a {@link BooleanVector "mask"} that's appropriate for
* passing to {@link #keepMask}.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This is duplicated in most of the templates, but having this javadoc on the boolean block/vector interfaces should suffice. (Just tested this for ConstantNullBlock, which doesn't have this javadoc comment, and when hovering over toMask I get the correct javadoc from the interface.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I just pushed that bit.

}
}
assertThat(blockFactory.breaker().getUsed(), equalTo(0L));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: there's 2 ways of having null values in an array block:

  • the nullsmask is explicitly set at the position
  • the value count is just 0.

I'm not sure if the added tests cover toMask in the second case.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test never makes 0 value count. Also! Those should mean the same thing.

Copy link
Contributor

@alex-spies alex-spies Aug 29, 2024

Choose a reason for hiding this comment

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

That's my point though: for good measure, I think the a test should make a block with a 0 value count at p (probably without setting the nulls mask at p); toMask should still work. (I'm pretty sure it does rn, but tests are better proof than my word!)

Last time I went digging in these parts of the code (when I added the invariant check for array blocks), there were rare instances where we actually made 0 value counts (by setting the first index for p and p+1 to the same value). Not sure if that's still the case, but I think we at least allow it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll open an PR. I think at this point not setting the null mask but setting the value count is an error. All kinds of things will blow up.

Copy link
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

LGTM

@nik9000 nik9000 merged commit e36b555 into elastic:main Aug 29, 2024
15 checks passed
dakrone pushed a commit to dakrone/elasticsearch that referenced this pull request Aug 30, 2024
This adds a method, `BooleanBlock#toMask` to convert `BooleanBlock`s
into a "mask" for use with `keepMask`.
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this pull request Sep 4, 2024
This adds a method, `BooleanBlock#toMask` to convert `BooleanBlock`s
into a "mask" for use with `keepMask`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants