Class BytesRefArrayBlock

java.lang.Object
org.elasticsearch.compute.data.AbstractNonThreadSafeRefCounted
org.elasticsearch.compute.data.BytesRefArrayBlock
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.lucene.util.Accountable, Writeable, Block, BytesRefBlock, RefCounted, Releasable, BlockLoader.Block

public final class BytesRefArrayBlock extends AbstractNonThreadSafeRefCounted implements BytesRefBlock
Block implementation that stores values in a BytesRefArrayVector. Does not take ownership of the given BytesRefArray and does not adjust circuit breakers to account for it. This class is generated. Edit X-ArrayBlock.java.st instead.
  • Field Details

    • positionCount

      protected final int positionCount
    • firstValueIndexes

      @Nullable protected final int[] firstValueIndexes
    • nullsMask

      @Nullable protected final BitSet nullsMask
  • Method Details

    • asVector

      public BytesRefVector asVector()
      Description copied from interface: Block
      Returns an efficient dense single-value view of this block. Null, if the block is not dense single-valued. That is, if mayHaveNulls returns true, or getTotalValueCount is not equal to getPositionCount.
      Specified by:
      asVector in interface Block
      Specified by:
      asVector in interface BytesRefBlock
      Returns:
      an efficient dense single-value view of this block
    • valueMaxByteSize

      public int valueMaxByteSize()
      Description copied from interface: BytesRefBlock
      The maximum size in bytes of any single value stored in this block, or 0 if there are no values. Scans all value indices to find the maximum.
      Specified by:
      valueMaxByteSize in interface Block
      Specified by:
      valueMaxByteSize in interface BytesRefBlock
      Returns:
      the maximum byte size of any single value in this block
    • asOrdinals

      public OrdinalBytesRefBlock asOrdinals()
      Description copied from interface: BytesRefBlock
      Returns an ordinal bytesref block if this block is backed by a dictionary and ordinals; otherwise, returns null. Callers must not release the returned block as no extra reference is retained by this method.
      Specified by:
      asOrdinals in interface BytesRefBlock
    • getBytesRef

      public org.apache.lucene.util.BytesRef getBytesRef(int valueIndex, org.apache.lucene.util.BytesRef dest)
      Description copied from interface: BytesRefBlock
      Build a contiguous array of bytes for the value stored at the given position. The underlying data is generally stored in pages that look like byte[][] with some data spanning more than one of the inner byte[] arrays. In that case, this builds a byte[] in the BytesRef, copies the bytes, and returns it. Otherwise, this returns a zero-copy snapshot of the underlying data. Except arrow. Arrow always copies.

      If possible, use BytesRefBlock.get(int, org.elasticsearch.common.bytes.PagedBytesCursor) because it only needs to copy in the arrow implementation.

      There are Block.getValueCount(int) values in each position. You can access them all with something like:

         int start = getFirstValueIndex(position);
         int end = start + getValueCount(position);
         for (int i = start; i < end; i++) {
            BytesRef v = getBytesRef(i, scratch);
            // do stuff
         }
      
      Specified by:
      getBytesRef in interface BytesRefBlock
      Parameters:
      valueIndex - the value index
      Returns:
      the data value (as a BytesRef)
    • get

      public PagedBytesCursor get(int valueIndex, PagedBytesCursor scratch)
      Description copied from interface: BytesRefBlock
      Retrieves the bytes value stored at the given value index using a PagedBytesCursor for zero-copy access to the underlying paged byte storage. Except arrow. Arrow always copies.

      There are Block.getValueCount(int) values in each position. You can access them all with something like:

         int start = getFirstValueIndex(position);
         int end = start + getValueCount(position);
         for (int i = start; i < end; i++) {
            PagedBytesCursor v = get(i, scratch);
            // do stuff
         }
      
      Specified by:
      get in interface BytesRefBlock
      Parameters:
      valueIndex - the value index
      scratch - the cursor to initialize and return
      Returns:
      the initialized cursor pointing to the value's bytes
    • filter

      public BytesRefBlock filter(boolean mayContainDuplicates, int[] positions, int offset, int length)
      Description copied from interface: Block
      Creates a new block that only exposes the positions provided.
      Specified by:
      filter in interface Block
      Specified by:
      filter in interface BytesRefBlock
      Parameters:
      mayContainDuplicates - may the positions array contain duplicate positions?
      positions - the positions to retain
      offset - the start index in the positions array
      length - the number of positions to use from the array
      Returns:
      a filtered block
    • keepMask

      public BytesRefBlock keepMask(BooleanVector mask)
      Description copied from interface: Block
      Build a Block with the same values as this Block, but replacing all values for which mask.getBooleanValue(position) returns false with null. The mask vector must be at least as long as this Block.
      Specified by:
      keepMask in interface Block
      Specified by:
      keepMask in interface BytesRefBlock
    • lookup

      public ReleasableIterator<BytesRefBlock> lookup(IntBlock positions, ByteSizeValue targetBlockSize)
      Description copied from interface: Block
      Builds an Iterator of new Blocks with the same Block.elementType() as this Block whose values are copied from positions in this Block. It has the same number of positions as the positions parameter.

      For example, if this block contained [a, b, [b, c]] and were called with the block [0, 1, 1, [1, 2]] then the result would be [a, b, b, [b, b, c]].

      This process produces count(this) * count(positions) values per positions which could be quite large. Instead of returning a single Block, this returns an Iterator of Blocks containing all of the promised values.

      The returned ReleasableIterator may retain a reference to the positions parameter. Close it to release those references.

      This block is built using the same BlockFactory as was used to build the positions parameter.

      Specified by:
      lookup in interface Block
      Specified by:
      lookup in interface BytesRefBlock
    • elementType

      public ElementType elementType()
      Description copied from interface: Block
      Returns the element type of this block.
      Specified by:
      elementType in interface Block
      Returns:
      the element type of this block
    • expand

      public BytesRefBlock expand()
      Description copied from interface: Block
      Expand multivalued fields into one row per value. Returns the same block if there aren't any multivalued fields to expand. The returned block needs to be closed by the caller to release the block's resources.
      Specified by:
      expand in interface Block
      Specified by:
      expand in interface BytesRefBlock
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface org.apache.lucene.util.Accountable
    • equals

      public boolean equals(Object obj)
      Description copied from interface: BytesRefBlock
      Compares the given object with this block for equality. Returns true if and only if the given object is a BytesRefBlock, and both blocks are equal.
      Specified by:
      equals in interface BytesRefBlock
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Description copied from interface: BytesRefBlock
      Returns the hash code of this block, as defined by BytesRefBlock.hash(BytesRefBlock).
      Specified by:
      hashCode in interface BytesRefBlock
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • allowPassingToDifferentDriver

      public void allowPassingToDifferentDriver()
      Description copied from interface: Block
      Before 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:
      allowPassingToDifferentDriver in interface Block
    • blockFactory

      public BlockFactory blockFactory()
      Description copied from interface: Block
      The block factory associated with this block.
      Specified by:
      blockFactory in interface Block
    • closeInternal

      public void closeInternal()
      Description copied from class: AbstractNonThreadSafeRefCounted
      This is called when the number of references reaches zero. This is where resources should be released (adjusting circuit breakers if needed).
      Specified by:
      closeInternal in class AbstractNonThreadSafeRefCounted
    • mayHaveMultivaluedFields

      public final boolean mayHaveMultivaluedFields()
      Description copied from interface: Block
      Can this block have multivalued fields? Blocks that return false will never return more than one from Block.getValueCount(int). This may return true for Blocks that do not have multivalued fields, but it will always answer quickly.
      Specified by:
      mayHaveMultivaluedFields in interface Block
    • doesHaveMultivaluedFields

      public boolean doesHaveMultivaluedFields()
      Description copied from interface: Block
      Does this block have multivalued fields? Unlike Block.mayHaveMultivaluedFields() this will never return a false positive. In other words, if this returns true then there are positions for which Block.getValueCount(int) will return more than 1. This will answer quickly if it can but may have to check all positions.
      Specified by:
      doesHaveMultivaluedFields in interface Block
    • mvOrdering

      public final Block.MvOrdering mvOrdering()
      Description copied from interface: Block
      How are multivalued fields ordered?
      Specified by:
      mvOrdering in interface Block
    • shiftNullsToExpandedPositions

      protected final BitSet shiftNullsToExpandedPositions()
    • getTotalValueCount

      public final int getTotalValueCount()
      Description copied from interface: Block
      Returns the total number of values in this block not counting nulls. This powers the COUNT aggregation and is used to report the number of fields loaded by ESQL.
      Specified by:
      getTotalValueCount in interface Block
      Returns:
      the total number of values in this block not counting nulls
    • getPositionCount

      public final int getPositionCount()
      Description copied from interface: Block
      Returns the number of positions (rows) in this block. See class javadoc for the usual way to iterate these positions.
      Specified by:
      getPositionCount in interface Block
      Returns:
      the number of positions (rows) in this block
    • getFirstValueIndex

      public final int getFirstValueIndex(int position)
      Gets the index of the first value for the given position.
      Specified by:
      getFirstValueIndex in interface Block
      Returns:
      the index of the first value for the given position
    • getValueCount

      public final int getValueCount(int position)
      Gets the number of values for the given position, possibly 0.
      Specified by:
      getValueCount in interface Block
      Returns:
      the number of values for the given position
    • isNull

      public final boolean isNull(int position)
      Specified by:
      isNull in interface Block
      Parameters:
      position - the position
      Returns:
      true if the value stored at the given position is null, false otherwise
    • mayHaveNulls

      public final boolean mayHaveNulls()
      Specified by:
      mayHaveNulls in interface Block
      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:
      areAllValuesNull in interface Block
      Returns:
      true if all values in this block are guaranteed to be null.