Class RowSetShiftData

java.lang.Object
io.deephaven.engine.rowset.RowSetShiftData
All Implemented Interfaces:
LogOutputAppendable, Serializable

public final class RowSetShiftData extends Object implements Serializable, LogOutputAppendable
A set of sorted shifts. To apply shifts without losing data, use apply(RowKeyRangeShiftCallback). The callback will be invoked with shifts in an order that will preserve data when applied immediately using memmove semantics. Internally the shifts are ordered by rangeStart. The RowSetShiftData.Builder will verify that no two ranges overlap before or after shifting and assert that the constructed RowSetShiftData will be valid.
See Also:
  • Field Details

  • Method Details

    • size

      public int size()
      The number of shifts embedded in the payload.
      Returns:
      the number of shifts
    • getEffectiveSize

      public long getEffectiveSize()
      The number of keys affected by shift commands.
      Returns:
      number of keys affected by shifts
    • getEffectiveSizeClamped

      public long getEffectiveSizeClamped(long clamp)
      The number of keys affected by shift commands.
      Parameters:
      clamp - the maximum size to return
      Returns:
      number of keys affected by shifts
    • getBeginRange

      public long getBeginRange(int idx)
      Get the inclusive begin offset of the idxth shift.
      Parameters:
      idx - which pair to get offset for
      Returns:
      the offset
    • getEndRange

      public long getEndRange(int idx)
      Get the inclusive end offset of the idxth shift.
      Parameters:
      idx - which pair to get offset for
      Returns:
      the offset
    • getShiftDelta

      public long getShiftDelta(int idx)
      Get the absolute shift of the idxth shift.
      Parameters:
      idx - which pair to get shift for
      Returns:
      the shift
    • validate

      public void validate()
      Verify invariants of internal data structures hold.
    • empty

      public boolean empty()
      Queries whether this RowSetShiftData is empty (i.e. has no shifts).
      Returns:
      true if the size() of this is zero, false if the size is greater than zero
    • nonempty

      public boolean nonempty()
      Queries whether this RowSetShiftData is non-empty (i.e. has at least one shift).
      Returns:
      true if the size() of this TrackingWritableRowSet greater than zero, false if the size is zero
    • toString

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

      public LogOutput append(LogOutput logOutput)
      Specified by:
      append in interface LogOutputAppendable
    • append

      public LogOutput append(LogOutput logOutput, int maxShifts)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • apply

      public void apply(RowKeyRangeShiftCallback shiftCallback)
      Apply all shifts in a memmove-semantics-safe ordering through the provided shiftCallback.

      Use this to move from pre-shift keyspace to post-shift keyspace.

      Parameters:
      shiftCallback - the callback that will process all shifts
    • unapply

      public void unapply(RowKeyRangeShiftCallback shiftCallback)
      Apply all shifts in reverse in a memmove-semantics-safe ordering through the provided shiftCallback.

      Use this to move from post-shift keyspace to pre-shift keyspace.

      Parameters:
      shiftCallback - the callback that will process all reverse shifts
    • apply

      public boolean apply(WritableRowSet rowSet)
      Apply all shifts to rowSet. Moves rowSet from pre-shift keyspace to post-shift keyspace.
      Parameters:
      rowSet - The WritableRowSet to shift
      Returns:
      rowSet
    • apply

      public long apply(long keyToShift)
      Apply all shifts to keyToShift. Moves the single row key from pre-shift keyspace to post-shift keyspace.
      Parameters:
      keyToShift - The single row key to shift
      Returns:
      the key in post-shift space
    • applyShift

      public static boolean applyShift(@NotNull @NotNull WritableRowSet rowSet, long beginRange, long endRange, long shiftDelta)
      Apply a shift to the provided rowSet. Moves rowSet from pre-shift keyspace to post-shift keyspace.
      Parameters:
      rowSet - The rowSet to apply the shift to
      beginRange - start of range (inclusive)
      endRange - end of range (inclusive)
      shiftDelta - amount range has moved by
      Returns:
      Whether there was any overlap found to shift
    • unapply

      public WritableRowSet unapply(WritableRowSet rowSet)
      Unapply all shifts to rowSet. Moves rowSet from post-shift keyspace to pre-shift keyspace.
      Parameters:
      rowSet - The WritableRowSet to shift
      Returns:
      rowSet
    • unapply

      public WritableRowSet unapply(WritableRowSet rowSet, long offset)
      Unapply all shifts to rowSet. Moves rowSet from post-shift keyspace to pre-shift keyspace.
      Parameters:
      rowSet - The WritableRowSet to shift
      offset - An additional offset to apply to all shifts (such as when applying to a wrapped table)
      Returns:
      rowSet
    • unapplyShift

      public static boolean unapplyShift(@NotNull @NotNull WritableRowSet rowSet, long beginRange, long endRange, long shiftDelta)
      Unapply a shift to the provided rowSet. Moves rowSet from post-shift keyspace to pre-shift keyspace.
      Parameters:
      rowSet - The rowSet to apply the shift to
      beginRange - start of range (inclusive)
      endRange - end of range (inclusive)
      shiftDelta - amount range has moved by
      Returns:
      Whether there was any overlap found to shift
    • forAllInRowSet

      public void forAllInRowSet(RowSet filterRowSet, RowSetShiftData.SingleElementShiftCallback callback)
    • applyIterator

      public RowSetShiftData.Iterator applyIterator()
    • intersect

      public RowSetShiftData intersect(RowSet rowSet)
      Intersects this RowSetShiftData against the provided RowSet.
      Parameters:
      rowSet - the rowSet to test for intersections (pre-shift keyspace)
      Returns:
      a rowSetShiftData containing only non-empty shifts
    • extractParallelShiftedRowsFromPostShiftRowSet

      public SafeCloseablePair<RowSet,RowSet> extractParallelShiftedRowsFromPostShiftRowSet(RowSet postShiftRowSet)
      This method creates two parallel RowSet structures that contain postShiftRowSet keys affected by shifts. The two RowSets have the same size. An element at position k in the first RowSet is the pre-shift key for the same row whose post-shift key is at position k in the second RowSet.
      Parameters:
      postShiftRowSet - The RowSet of keys that were shifted in post-shift keyspace. It should not contain rows that did not exist prior to the shift.
      Returns:
      A SafeCloseablePair of preShiftedKeys and postShiftedKeys that intersect this RowSetShiftData with postShiftRowSet.