Interface BytesRefBlock

All Superinterfaces:
org.apache.lucene.util.Accountable, AutoCloseable, Block, BlockLoader.Block, Closeable, RefCounted, Releasable, Writeable
All Known Implementing Classes:
BytesRefArrayBlock, BytesRefArrowBufBlock, BytesRefVectorBlock, ConstantNullBlock, OrdinalBytesRefBlock

Block that stores BytesRef values. This class is generated. Edit X-Block.java.st instead.
  • Field Details

    • NULL_VALUE

      static final org.apache.lucene.util.BytesRef NULL_VALUE
  • Method Details

    • getBytesRef

      org.apache.lucene.util.BytesRef getBytesRef(int valueIndex, org.apache.lucene.util.BytesRef dest)
      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 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
         }
      
      Parameters:
      valueIndex - the value index
      Returns:
      the data value (as a BytesRef)
    • get

      PagedBytesCursor get(int valueIndex, PagedBytesCursor scratch)
      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
         }
      
      Parameters:
      valueIndex - the value index
      scratch - the cursor to initialize and return
      Returns:
      the initialized cursor pointing to the value's bytes
    • hasValue

      default boolean hasValue(int position, org.apache.lucene.util.BytesRef value, org.apache.lucene.util.BytesRef scratch)
      Checks if this block has the given value at position. If at this index we have a multivalue, then it returns true if any values match.
      Parameters:
      position - the index at which we should check the value(s)
      value - the value to check against
      scratch - the scratch BytesRef to use for this operation
    • asVector

      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
      Returns:
      an efficient dense single-value view of this block
    • asOrdinals

      OrdinalBytesRefBlock asOrdinals()
      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.
    • slice

      default BytesRefBlock slice(int beginInclusive, int endExclusive)
      Description copied from interface: Block
      Return a subset of this Block from position beginInclusive to position endExclusive. This may return the same instance if the range covers all positions, but if it does it will RefCounted.incRef() it.

      NOTE: Implementations will not try to optimize zero length slices as we expect them to be rare.

      Specified by:
      slice in interface Block
    • filter

      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
      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
    • filter

      default BytesRefBlock filter(boolean mayContainDuplicates, int... positions)
      Description copied from interface: Block
      Creates a new block that only exposes the positions provided.
      Specified by:
      filter in interface Block
      Parameters:
      mayContainDuplicates - may the positions array contain duplicate positions?
      positions - the positions to retain
      Returns:
      a filtered block
    • deepCopy

      default BytesRefBlock deepCopy(BlockFactory blockFactory)
      Make a deep copy of this Block using the provided BlockFactory, likely copying all data.
      Specified by:
      deepCopy in interface Block
    • keepMask

      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
    • lookup

      ReleasableIterator<? extends 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
    • expand

      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
    • valueMaxByteSize

      int valueMaxByteSize()
      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
      Returns:
      the maximum byte size of any single value in this block
    • readFrom

      static BytesRefBlock readFrom(BlockStreamInput in) throws IOException
      Throws:
      IOException
    • writeTo

      default void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Block
      Writes only the data of the block to a stream output. This method should be used when the type of the block is known during reading.
      Specified by:
      writeTo in interface Block
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • equals

      boolean equals(Object obj)
      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.
      Overrides:
      equals in class Object
    • hashCode

      int hashCode()
      Returns the hash code of this block, as defined by hash(BytesRefBlock).
      Overrides:
      hashCode in class Object
    • equals

      static boolean equals(BytesRefBlock block1, BytesRefBlock block2)
      Returns true if the given blocks are equal to each other, otherwise false. Two blocks are considered equal if they have the same position count, and contain the same values (including absent null values) in the same order. This definition ensures that the equals method works properly across different implementations of the BytesRefBlock interface.
    • hash

      static int hash(BytesRefBlock block)
      Generates the hash code for the given block. The hash code is computed from the block's values. This ensures that block1.equals(block2) implies that block1.hashCode()==block2.hashCode() for any two blocks, block1 and block2, as required by the general contract of Object.hashCode().