Class ArrayBlock

java.lang.Object
io.trino.spi.block.ArrayBlock
All Implemented Interfaces:
Block, ValueBlock

public final class ArrayBlock extends Object implements ValueBlock
  • Method Details

    • fromElementBlock

      public static ArrayBlock fromElementBlock(int positionCount, Optional<boolean[]> valueIsNullOptional, int[] arrayOffset, Block values)
      Create an array block directly from columnar nulls, values, and offsets into the values. A null array must have no entries.
    • getPositionCount

      public int getPositionCount()
      Description copied from interface: Block
      Returns the number of positions in this block.
      Specified by:
      getPositionCount in interface Block
    • getSizeInBytes

      public long getSizeInBytes()
      Description copied from interface: Block
      Returns the size of this block as if it was compacted, ignoring any over-allocations and any unloaded nested blocks. For example, in dictionary blocks, this only counts each dictionary entry once, rather than each time a value is referenced.
      Specified by:
      getSizeInBytes in interface Block
    • getRetainedSizeInBytes

      public long getRetainedSizeInBytes()
      Description copied from interface: Block
      Returns the retained size of this block in memory, including over-allocations. This method is called from the inner most execution loop and must be fast.
      Specified by:
      getRetainedSizeInBytes in interface Block
    • retainedBytesForEachPart

      public void retainedBytesForEachPart(ObjLongConsumer<Object> consumer)
      Description copied from interface: Block
      consumer visits each of the internal data container and accepts the size for it. This method can be helpful in cases such as memory counting for internal data structure. Also, the method should be non-recursive, only visit the elements at the top level, and specifically should not call retainedBytesForEachPart on nested blocks consumer should be called at least once with the current block and must include the instance size of the current block
      Specified by:
      retainedBytesForEachPart in interface Block
    • getElementsBlock

      public Block getElementsBlock()
    • getEncodingName

      public String getEncodingName()
      Description copied from interface: Block
      Get the encoding for this block.
      Specified by:
      getEncodingName in interface Block
    • mayHaveNull

      public boolean mayHaveNull()
      Description copied from interface: Block
      Is it possible the block may have a null value? If false, the block cannot contain a null, but if true, the block may or may not have a null.
      Specified by:
      mayHaveNull in interface Block
    • toString

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

      public boolean isLoaded()
      Description copied from interface: Block
      Returns true if block data is fully loaded into memory.
      Specified by:
      isLoaded in interface Block
    • getLoadedBlock

      public ArrayBlock getLoadedBlock()
      Description copied from interface: Block
      Returns a fully loaded block that assures all data is in memory. Neither the returned block nor any nested block will be a LazyBlock. The same block will be returned if neither the current block nor any nested blocks are LazyBlock,

      This allows streaming data sources to skip sections that are not accessed in a query.

      Specified by:
      getLoadedBlock in interface Block
    • copyWithAppendedNull

      public ArrayBlock copyWithAppendedNull()
      Description copied from interface: Block
      Returns a block that contains a copy of the contents of the current block, and an appended null at the end. The original block will not be modified. The purpose of this method is to leverage the contents of a block and the structure of the implementation to efficiently produce a copy of the block with a NULL element inserted - so that it can be used as a dictionary. This method is expected to be invoked on completely built Block instances i.e. not on in-progress block builders.
      Specified by:
      copyWithAppendedNull in interface Block
      Specified by:
      copyWithAppendedNull in interface ValueBlock
    • copyPositions

      public ArrayBlock copyPositions(int[] positions, int offset, int length)
      Description copied from interface: Block
      Returns a block containing the specified positions. Positions to copy are stored in a subarray within positions array that starts at offset and has length of length. All specified positions must be valid for this block.

      The returned block must be a compact representation of the original block.

      Specified by:
      copyPositions in interface Block
      Specified by:
      copyPositions in interface ValueBlock
    • getRegion

      public ArrayBlock getRegion(int position, int length)
      Description copied from interface: Block
      Returns a block starting at the specified position and extends for the specified length. The specified region must be entirely contained within this block.

      The region can be a view over this block. If this block is released the region block may also be released. If the region block is released this block may also be released.

      Specified by:
      getRegion in interface Block
      Specified by:
      getRegion in interface ValueBlock
    • fixedSizeInBytesPerPosition

      public OptionalInt fixedSizeInBytesPerPosition()
      Description copied from interface: Block
      Returns the number of bytes (in terms of Block.getSizeInBytes()) required per position that this block contains, assuming that the number of bytes required is a known static quantity and not dependent on any particular specific position. This allows for some complex block wrappings to potentially avoid having to call Block.getPositionsSizeInBytes(boolean[], int) which would require computing the specific positions selected
      Specified by:
      fixedSizeInBytesPerPosition in interface Block
      Returns:
      The size in bytes, per position, if this block type does not require specific position information to compute its size
    • getRegionSizeInBytes

      public long getRegionSizeInBytes(int position, int length)
      Description copied from interface: Block
      Returns the size of block.getRegion(position, length). The method can be expensive. Do not use it outside an implementation of Block.
      Specified by:
      getRegionSizeInBytes in interface Block
    • getPositionsSizeInBytes

      public long getPositionsSizeInBytes(boolean[] positions, int selectedArrayPositions)
      Description copied from interface: Block
      Returns the size of all positions marked true in the positions array. This is equivalent to multiple calls of block.getRegionSizeInBytes(position, length) where you mark all positions for the regions first. The 'selectedPositionsCount' variable may be used to skip iterating through the positions array in case this is a fixed-width block
      Specified by:
      getPositionsSizeInBytes in interface Block
    • copyRegion

      public ArrayBlock copyRegion(int position, int length)
      Description copied from interface: Block
      Returns a block starting at the specified position and extends for the specified length. The specified region must be entirely contained within this block.

      The region returned must be a compact representation of the original block, unless their internal representation will be exactly the same. This method is useful for operators that hold on to a range of values without holding on to the entire block.

      Specified by:
      copyRegion in interface Block
      Specified by:
      copyRegion in interface ValueBlock
    • getArray

      public Block getArray(int position)
    • getSingleValueBlock

      public ArrayBlock getSingleValueBlock(int position)
      Description copied from interface: Block
      Gets the value at the specified position as a single element block. The method must copy the data into a new block.

      This method is useful for operators that hold on to a single value without holding on to the entire block.

      Specified by:
      getSingleValueBlock in interface Block
    • getEstimatedDataSizeForStats

      public long getEstimatedDataSizeForStats(int position)
      Description copied from interface: Block
      Returns the estimated in memory data size for stats of position. Do not use it for other purpose.
      Specified by:
      getEstimatedDataSizeForStats in interface Block
    • isNull

      public boolean isNull(int position)
      Description copied from interface: Block
      Is the specified position null?
      Specified by:
      isNull in interface Block
    • getUnderlyingValueBlock

      public ArrayBlock getUnderlyingValueBlock()
      Description copied from interface: Block
      Returns the underlying value block underlying this block.
      Specified by:
      getUnderlyingValueBlock in interface Block
      Specified by:
      getUnderlyingValueBlock in interface ValueBlock
    • getNulls

      public Optional<ByteArrayBlock> getNulls()
      Description copied from interface: ValueBlock
      Returns a ByteArrayBlock specifying whether the current positions in the Block contain a NULL. Returns Optional.empty() when there are no NULLs in the Block. The returned ByteArrayBlock must not contain NULL values.
      Specified by:
      getNulls in interface ValueBlock
    • apply

      public <T> T apply(ArrayBlock.ArrayBlockFunction<T> function, int position)