Class AbstractDelegatingCompoundBlock<T extends Block>
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.lucene.util.Accountable,Writeable,Block,RefCounted,Releasable,BlockLoader.Block
- Direct Known Subclasses:
ExponentialHistogramArrayBlock,TDigestArrayBlock
firstValueIndexes.
The key insight is that value indices in the composite block correspond to positions in the sub-blocks. Sub-blocks are always single-valued per position. For example, a multi-valued exponential histogram block with three histograms at one position would have three corresponding positions in each sub-block.
Null handling is delegated to the first sub-block returned by getSubBlocks() which must be non-null
for non-null composite values.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classManages firstValueIndexes and positionCount for multi-value support.protected static interfaceNested classes/interfaces inherited from interface org.elasticsearch.compute.data.Block
Block.Builder, Block.MvOrderingNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLEFields inherited from interface org.elasticsearch.compute.data.Block
ESQL_AGGREGATE_METRIC_DOUBLE_BLOCK, MAX_LOOKUP, PAGE_MEM_OVERHEAD_PER_BLOCK, SERIALIZE_BLOCK_ARRAY, SERIALIZE_BLOCK_BIG_ARRAY, SERIALIZE_BLOCK_ORDINAL, SERIALIZE_BLOCK_VALUES, SERIALIZE_BLOCK_VECTORFields inherited from interface org.elasticsearch.core.RefCounted
ALWAYS_REFERENCED -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDelegatingCompoundBlock(int positionCount, int[] firstValueIndexes) -
Method Summary
Modifier and TypeMethodDescriptionvoidBefore passing a Block to another Driver, it is necessary to switch the owning block factory to its parent, which is associated with the global circuit breaker.final booleanprotected booleanThe block factory associated with this block.protected abstract TbuildFromSubBlocks(List<Block> subBlocks, int positionCount, int[] firstValueIndexes) Construct a new instance of the block, based on the given list of sub-blocks.protected voidThis is called when the number of references reaches zero.deepCopy(BlockFactory blockFactory) Make a deep copy of thisBlockusing the providedBlockFactory, likely copying all data.booleanDoes this block have multivalued fields? UnlikeBlock.mayHaveMultivaluedFields()this will never return a false positive.filter(boolean mayContainDuplicates, int[] positions, int offset, int length) Creates a new block that only exposes the positions provided.final intgetFirstValueIndex(int position) Returns the index of the first value for the given position.final intReturns the number of positions (rows) in this block.final intReturns the total number of values in this block not counting nulls.final intgetValueCount(int position) Returns the number of values for the given position.final booleanisNull(int position) keepMask(BooleanVector mask) protected final booleanCompares positionCount and firstValueIndexes with another block for equality.final booleanCan this block have multivalued fields? Blocks that returnfalsewill never return more than one fromBlock.getValueCount(int).final booleanfinal Block.MvOrderingHow are multivalued fields ordered?longprotected static <T extends Block>
TreadFrom(BlockStreamInput in, AbstractDelegatingCompoundBlock.Deserializer<T> deserializer) slice(int beginInclusive, int endExclusive) intReturns the maximum byte size of any single value in this block.protected voidWrites the multivalue metadata (positionCount, firstValueIndexes) to a stream.Methods inherited from class org.elasticsearch.compute.data.AbstractNonThreadSafeRefCounted
attachReleasable, close, decRef, hasReferences, incRef, isReleased, tryIncRefMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResourcesMethods inherited from interface org.elasticsearch.compute.data.Block
asVector, attachReleasable, elementType, expand, filter, insertNulls, isReleased, lookup, mvDeduplicated, mvSortedAscending, writeToMethods inherited from interface org.elasticsearch.core.RefCounted
decRef, hasReferences, incRef, mustIncRef, tryIncRefMethods inherited from interface org.elasticsearch.core.Releasable
close
-
Constructor Details
-
AbstractDelegatingCompoundBlock
- Parameters:
positionCount- the number of positions in this blockfirstValueIndexes- maps positions to ranges of value indices in sub-blocks. Null if single-valued.
-
-
Method Details
-
getSubBlocks
- Returns:
- a list of the sub-blocks composing this compound block. The first block must be non-null for
non-null composite values (used for null detection). The order should match the order expected
by
buildFromSubBlocks(List, int, int[]).
-
buildFromSubBlocks
protected abstract T buildFromSubBlocks(List<Block> subBlocks, int positionCount, @Nullable int[] firstValueIndexes) Construct a new instance of the block, based on the given list of sub-blocks.- Parameters:
subBlocks- List of sub-blocks, in the same order asgetSubBlocks()positionCount- the number of positions in the new blockfirstValueIndexes- the firstValueIndexes array for the new block (may be null for single-valued)- Returns:
- a new instance based on the given blocks.
-
getPositionCount
public final int getPositionCount()Description copied from interface:BlockReturns the number of positions (rows) in this block. See class javadoc for the usual way to iterate these positions.- Specified by:
getPositionCountin interfaceBlock- Returns:
- the number of positions (rows) in this block
-
getFirstValueIndex
public final int getFirstValueIndex(int position) Description copied from interface:BlockReturns the index of the first value for the given position. See class javadoc for the usual way to iterate these positions.For densely packed data this will return its parameter unchanged. For fields with
nullvalues or multivalued fields, this will shift. Here's an example:0 <---+ 1 | Values at first position 2 | 3 <---+ 5 <---- Value at second position 6 <---+ Values at third position 7 <---+This represents three rows. The first has the value
[0, 1, 2, 3]. The second has the value5. The third has the value[6, 7]. This method will return0for the first position,4for the second, and5for the third.- Specified by:
getFirstValueIndexin interfaceBlock- Returns:
- the index of the first value for the given position
-
getValueCount
public final int getValueCount(int position) Description copied from interface:BlockReturns the number of values for the given position. See class javadoc for the usual way to iterate these positions.For densely packed data this will return
1. Fornulls this will return0. For multivalued fields, this will return the number of values. Here's an example:0 <---+ 1 | Values at first position 2 | 3 <---+ 5 <---- Value at second position 6 <---+ Values at third position 7 <---+This represents three rows. The first has the value
[0, 1, 2, 3]. The second has the value5. The third has the value[6, 7]. This method will return4for the first position,1for the second, and2for the third.- Specified by:
getValueCountin interfaceBlock- Returns:
- the number of values for the given position
-
getTotalValueCount
public final int getTotalValueCount()Description copied from interface:BlockReturns the total number of values in this block not counting nulls. This powers theCOUNTaggregation and is used to report the number of fields loaded by ESQL.- Specified by:
getTotalValueCountin interfaceBlock- Returns:
- the total number of values in this block not counting nulls
-
isNull
public final boolean isNull(int position) -
mayHaveNulls
public final boolean mayHaveNulls()- Specified by:
mayHaveNullsin interfaceBlock- Returns:
- true if some values might be null. False, if all values are guaranteed to be not null.
-
areAllValuesNull
public final boolean areAllValuesNull()- Specified by:
areAllValuesNullin interfaceBlock- Returns:
- true if all values in this block are guaranteed to be null.
-
mayHaveMultivaluedFields
public final boolean mayHaveMultivaluedFields()Description copied from interface:BlockCan this block have multivalued fields? Blocks that returnfalsewill never return more than one fromBlock.getValueCount(int). This may returntruefor Blocks that do not have multivalued fields, but it will always answer quickly.- Specified by:
mayHaveMultivaluedFieldsin interfaceBlock
-
doesHaveMultivaluedFields
public boolean doesHaveMultivaluedFields()Description copied from interface:BlockDoes this block have multivalued fields? UnlikeBlock.mayHaveMultivaluedFields()this will never return a false positive. In other words, if this returnstruethen there are positions for whichBlock.getValueCount(int)will return more than 1. This will answer quickly if it can but may have to check all positions.- Specified by:
doesHaveMultivaluedFieldsin interfaceBlock
-
mvOrdering
Description copied from interface:BlockHow are multivalued fields ordered?- Specified by:
mvOrderingin interfaceBlock
-
layoutEquals
Compares positionCount and firstValueIndexes with another block for equality. -
assertInvariants
protected boolean assertInvariants() -
allowPassingToDifferentDriver
public void allowPassingToDifferentDriver()Description copied from interface:BlockBefore passing a Block to another Driver, it is necessary to switch the owning block factory to its parent, which is associated with the global circuit breaker. This ensures that when the new driver releases this Block, it returns memory directly to the parent block factory instead of the local block factory of this Block. This is important because the local block factory is not thread safe and doesn't support simultaneous access by more than one thread.- Specified by:
allowPassingToDifferentDriverin interfaceBlock
-
blockFactory
Description copied from interface:BlockThe block factory associated with this block.- Specified by:
blockFactoryin interfaceBlock
-
valueMaxByteSize
public int valueMaxByteSize()Description copied from interface:BlockReturns the maximum byte size of any single value in this block. For fixed-width types this is a constant. ForBytesRef, this scans all values quickly.- Specified by:
valueMaxByteSizein interfaceBlock- Returns:
- the maximum byte size of any single value in this block
-
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceorg.apache.lucene.util.Accountable
-
closeInternal
protected void closeInternal()Description copied from class:AbstractNonThreadSafeRefCountedThis is called when the number of references reaches zero. This is where resources should be released (adjusting circuit breakers if needed).- Specified by:
closeInternalin classAbstractNonThreadSafeRefCounted
-
filter
Description copied from interface:BlockCreates a new block that only exposes the positions provided. -
slice
Description copied from interface:BlockReturn a subset of thisBlockfrom positionbeginInclusiveto positionendExclusive. This may return the same instance if the range covers all positions, but if it does it willRefCounted.incRef()it.NOTE: Implementations will not try to optimize zero length slices as we expect them to be rare.
-
keepMask
Description copied from interface:Block -
deepCopy
Description copied from interface:BlockMake a deep copy of thisBlockusing the providedBlockFactory, likely copying all data. -
writeMultiValueMetadata
Writes the multivalue metadata (positionCount, firstValueIndexes) to a stream.- Throws:
IOException
-
readFrom
protected static <T extends Block> T readFrom(BlockStreamInput in, AbstractDelegatingCompoundBlock.Deserializer<T> deserializer) throws IOException - Throws:
IOException
-