java.lang.Object
org.elasticsearch.index.codec.tsdb.pipeline.numeric.stages.DeltaCodecStage
All Implemented Interfaces:
NumericCodecStage, TransformDecoder, TransformEncoder

public final class DeltaCodecStage extends Object implements NumericCodecStage
Delta encoding transform stage for monotonic sequences.

Effectiveness

Applied only when the sequence is monotonic (at least 2 increases with 0 decreases, or at least 2 decreases with 0 increases). Non-monotonic or constant sequences are skipped because deltas would not reduce the dynamic range.

Example

Monotonic ascending [100, 200, 350, 500] produces deltas [100, 150, 150] with first value 100 stored as metadata.

Metadata layout

Written to the stage metadata section (see BlockFormat):

   +---------------------+
   | ZLong(first)        |  1-10 bytes, zigzag-encoded first value
   +---------------------+
 

Zigzag encoding ensures small absolute values (both positive and negative) use few bytes, which is typical for the starting point of a monotonic sequence.

  • Field Details

    • INSTANCE

      public static final DeltaCodecStage INSTANCE
      Singleton instance.
  • Method Details

    • id

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

      public void encode(long[] values, int valueCount, EncodingContext context)
      Description copied from interface: TransformEncoder
      Transforms values in-place and writes any metadata to the context.

      If the stage determines that the transformation would not be effective, it may return without modifying the values or writing metadata. The pipeline checks EncodingContext.isStageApplied(int) to detect this.

      Specified by:
      encode in interface TransformEncoder
      Parameters:
      values - the values to transform in-place
      valueCount - the number of valid values in the array
      context - the encoding context for metadata and stage tracking
    • decode

      public void decode(long[] values, int valueCount, DecodingContext context) throws IOException
      Description copied from interface: TransformDecoder
      Reverses the transformation on values in-place using metadata from the context.
      Specified by:
      decode in interface TransformDecoder
      Parameters:
      values - the values to reverse-transform in-place
      valueCount - the number of valid values in the array
      context - the decoding context for reading stage metadata
      Throws:
      IOException - if an I/O error occurs while reading metadata
    • encodeStatic

      public static void encodeStatic(DeltaCodecStage stage, long[] values, int valueCount, EncodingContext context) throws IOException
      Throws:
      IOException
    • decodeStatic

      public static void decodeStatic(DeltaCodecStage stage, long[] values, int valueCount, DecodingContext context) throws IOException
      Throws:
      IOException