java.lang.Object
java.lang.Record
org.elasticsearch.index.codec.tsdb.pipeline.numeric.stages.BitPackCodecStage
Record Components:
forUtil - the utility for encoding and decoding packed values
All Implemented Interfaces:
PayloadCodecStage, PayloadDecoder, PayloadEncoder

public record BitPackCodecStage(DocValuesForUtil forUtil) extends Record implements PayloadCodecStage
Bit-packing terminal payload stage.

Effectiveness

Always applied as the terminal stage. Computes the minimum number of bits needed to represent the largest value, then packs all values at that bit width using DocValuesForUtil.

Example

Values [0, 50, 100, 150] need 8 bits per value (max=150), so 128 values are packed into 128 bytes instead of 1024 bytes (raw longs).

Payload layout

Written directly to the data stream as the payload section of the block (see BlockFormat):

   +------------------------+---------------------------------------------+
   | VInt(bitsPerValue)     | ForUtil packed data                         |
   | 1-5 bytes              | ceil(blockSize * bitsPerValue / 8) bytes    |
   +------------------------+---------------------------------------------+
 

The bitsPerValue is rounded by DocValuesForUtil.roundBits(int) to align with ForUtil's SIMD-friendly block widths. This data is written to the payload section of the block, not through the metadata buffer. The packed data size depends on both the bit width and the block size.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a BitPackCodecStage record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    decode(long[] values, org.apache.lucene.store.DataInput in, DecodingContext context)
    Deserializes bytes from the input stream back to values.
    void
    encode(long[] values, int valueCount, org.apache.lucene.store.DataOutput out, EncodingContext context)
    Serializes values to the output stream.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the forUtil record component.
    final int
    Returns a hash code value for this object.
    byte
    id()
    Returns the unique stage identifier.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BitPackCodecStage

      public BitPackCodecStage(DocValuesForUtil forUtil)
      Creates an instance of a BitPackCodecStage record class.
      Parameters:
      forUtil - the value for the forUtil record component
  • Method Details

    • id

      public byte id()
      Description copied from interface: PayloadEncoder
      Returns the unique stage identifier.
      Specified by:
      id in interface PayloadDecoder
      Specified by:
      id in interface PayloadEncoder
      Returns:
      the stage ID byte
    • encode

      public void encode(long[] values, int valueCount, org.apache.lucene.store.DataOutput out, EncodingContext context) throws IOException
      Description copied from interface: PayloadEncoder
      Serializes values to the output stream.
      Specified by:
      encode in interface PayloadEncoder
      Parameters:
      values - the values to encode
      valueCount - the number of valid values in the array
      out - the data output stream
      context - the encoding context with block metadata
      Throws:
      IOException - if an I/O error occurs
    • decode

      public int decode(long[] values, org.apache.lucene.store.DataInput in, DecodingContext context) throws IOException
      Description copied from interface: PayloadDecoder
      Deserializes bytes from the input stream back to values.
      Specified by:
      decode in interface PayloadDecoder
      Parameters:
      values - the output array to populate
      in - the data input stream
      context - the decoding context with block metadata
      Returns:
      the number of values decoded
      Throws:
      IOException - if an I/O error occurs
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • forUtil

      public DocValuesForUtil forUtil()
      Returns the value of the forUtil record component.
      Returns:
      the value of the forUtil record component