-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.compute.data; | ||
|
||
import org.elasticsearch.core.Releasable; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public record ToMask(BooleanVector mask, boolean hadMultivaluedFields) implements Releasable { | ||
alex-spies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Override | ||
public void close() { | ||
mask.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,32 @@ $if(BytesRef)$ | |
public OrdinalBytesRefBlock asOrdinals() { | ||
return null; | ||
} | ||
|
||
$elseif(boolean)$ | ||
/** | ||
* Convert this to a {@link BooleanVector "mask"} that's appropriate for | ||
* passing to {@link #keepMask}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
*/ | ||
@Override | ||
public ToMask toMask() { | ||
if (getPositionCount() == 0) { | ||
return new ToMask(blockFactory().newConstantBooleanVector(false, 0), false); | ||
} | ||
try (BooleanVector.FixedBuilder builder = blockFactory().newBooleanVectorFixedBuilder(getPositionCount())) { | ||
boolean hasMv = false; | ||
for (int p = 0; p < getPositionCount(); p++) { | ||
builder.appendBoolean(switch (getValueCount(p)) { | ||
case 0 -> false; | ||
case 1 -> getBoolean(getFirstValueIndex(p)); | ||
default -> { | ||
hasMv = true; | ||
yield false; | ||
} | ||
}); | ||
} | ||
return new ToMask(builder.build(), hasMv); | ||
} | ||
} | ||
$endif$ | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,18 @@ $endif$ | |
return new $Type$VectorBlock(this); | ||
} | ||
|
||
$if(boolean)$ | ||
/** | ||
* Convert this to a {@link BooleanVector "mask"} that's appropriate for | ||
* passing to {@link #keepMask}. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed that bit. |
||
@Override | ||
public ToMask toMask() { | ||
incRef(); | ||
return new ToMask(this, false); | ||
} | ||
$endif$ | ||
|
||
@Override | ||
public $type$ get$Type$(int position) { | ||
return values.get(position); | ||
|
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 think this doesn't implement incref/RefCounted/AbstractNonThreadSafeRefCounted.
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.
Block
's ref counted - this is sort of like a single reference to it. Not sure if that's clear though.