Class FixedLengthRecordSorter<T>

java.lang.Object
org.apache.flink.runtime.operators.sort.FixedLengthRecordSorter<T>
All Implemented Interfaces:
IndexedSortable, InMemorySorter<T>, org.apache.flink.util.Disposable

public final class FixedLengthRecordSorter<T> extends Object implements InMemorySorter<T>
  • Constructor Summary

    Constructors
    Constructor
    Description
    FixedLengthRecordSorter(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, org.apache.flink.api.common.typeutils.TypeComparator<T> comparator, List<org.apache.flink.core.memory.MemorySegment> memory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compare(int i, int j)
    Compare items at the given addresses consistent with the semantics of Comparator.compare(Object, Object).
    int
    compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ)
    Compare records at the given addresses consistent with the semantics of Comparator.compare(Object, Object).
    void
    Disposes the sorter.
    long
    Gets the total capacity of this sorter, in bytes.
    final org.apache.flink.util.MutableObjectIterator<T>
    Gets an iterator over all records in this buffer in their logical order.
    long
    Gets the number of bytes currently occupied in this sorter, records and sort index.
    getRecord(int logicalPosition)
    Gets the record at the given logical position.
    getRecord(T reuse, int logicalPosition)
    Gets the record at the given logical position.
    boolean
    Checks whether the buffer is empty.
    int
    Gets the size of each record, the number of bytes separating the head of successive records.
    int
    Gets the number of elements in each memory segment.
    void
    Resets the sort buffer back to the state where it is empty.
    int
    Gets the number of elements in the sortable.
    void
    swap(int i, int j)
    Swap items at the given addresses.
    void
    swap(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ)
    Swap records at the given addresses.
    boolean
    write(T record)
    Writes a given record to this sort buffer.
    void
    Writes the records in this buffer in their logical order to the given output.
    void
    writeToOutput(ChannelWriterOutputView output, int start, int num)
    Writes a subset of the records in this buffer in their logical order to the given output.
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FixedLengthRecordSorter

      public FixedLengthRecordSorter(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer, org.apache.flink.api.common.typeutils.TypeComparator<T> comparator, List<org.apache.flink.core.memory.MemorySegment> memory)
  • Method Details

    • recordSize

      public int recordSize()
      Description copied from interface: IndexedSortable
      Gets the size of each record, the number of bytes separating the head of successive records.
      Specified by:
      recordSize in interface IndexedSortable
      Returns:
      The record size
    • recordsPerSegment

      public int recordsPerSegment()
      Description copied from interface: IndexedSortable
      Gets the number of elements in each memory segment.
      Specified by:
      recordsPerSegment in interface IndexedSortable
      Returns:
      The number of records per segment
    • reset

      public void reset()
      Resets the sort buffer back to the state where it is empty. All contained data is discarded.
      Specified by:
      reset in interface InMemorySorter<T>
    • isEmpty

      public boolean isEmpty()
      Checks whether the buffer is empty.
      Specified by:
      isEmpty in interface InMemorySorter<T>
      Returns:
      True, if no record is contained, false otherwise.
    • dispose

      public void dispose()
      Description copied from interface: InMemorySorter
      Disposes the sorter. This method does not release the memory segments used by the sorter.
      Specified by:
      dispose in interface org.apache.flink.util.Disposable
      Specified by:
      dispose in interface InMemorySorter<T>
    • getCapacity

      public long getCapacity()
      Description copied from interface: InMemorySorter
      Gets the total capacity of this sorter, in bytes.
      Specified by:
      getCapacity in interface InMemorySorter<T>
      Returns:
      The sorter's total capacity.
    • getOccupancy

      public long getOccupancy()
      Description copied from interface: InMemorySorter
      Gets the number of bytes currently occupied in this sorter, records and sort index.
      Specified by:
      getOccupancy in interface InMemorySorter<T>
      Returns:
      The number of bytes occupied.
    • getRecord

      public T getRecord(int logicalPosition) throws IOException
      Description copied from interface: InMemorySorter
      Gets the record at the given logical position.
      Specified by:
      getRecord in interface InMemorySorter<T>
      Parameters:
      logicalPosition - The logical position of the record.
      Throws:
      IOException - Thrown, if an exception occurred during deserialization.
    • getRecord

      public T getRecord(T reuse, int logicalPosition) throws IOException
      Description copied from interface: InMemorySorter
      Gets the record at the given logical position.
      Specified by:
      getRecord in interface InMemorySorter<T>
      Parameters:
      reuse - The reuse object to deserialize the record into.
      logicalPosition - The logical position of the record.
      Throws:
      IOException - Thrown, if an exception occurred during deserialization.
    • write

      public boolean write(T record) throws IOException
      Writes a given record to this sort buffer. The written record will be appended and take the last logical position.
      Specified by:
      write in interface InMemorySorter<T>
      Parameters:
      record - The record to be written.
      Returns:
      True, if the record was successfully written, false, if the sort buffer was full.
      Throws:
      IOException - Thrown, if an error occurred while serializing the record into the buffers.
    • compare

      public int compare(int i, int j)
      Description copied from interface: IndexedSortable
      Compare items at the given addresses consistent with the semantics of Comparator.compare(Object, Object).
      Specified by:
      compare in interface IndexedSortable
    • compare

      public int compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ)
      Description copied from interface: IndexedSortable
      Compare records at the given addresses consistent with the semantics of Comparator.compare(Object, Object).
      Specified by:
      compare in interface IndexedSortable
      Parameters:
      segmentNumberI - index of memory segment containing first record
      segmentOffsetI - offset into memory segment containing first record
      segmentNumberJ - index of memory segment containing second record
      segmentOffsetJ - offset into memory segment containing second record
      Returns:
      a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
    • swap

      public void swap(int i, int j)
      Description copied from interface: IndexedSortable
      Swap items at the given addresses.
      Specified by:
      swap in interface IndexedSortable
    • swap

      public void swap(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ)
      Description copied from interface: IndexedSortable
      Swap records at the given addresses.
      Specified by:
      swap in interface IndexedSortable
      Parameters:
      segmentNumberI - index of memory segment containing first record
      segmentOffsetI - offset into memory segment containing first record
      segmentNumberJ - index of memory segment containing second record
      segmentOffsetJ - offset into memory segment containing second record
    • size

      public int size()
      Description copied from interface: IndexedSortable
      Gets the number of elements in the sortable.
      Specified by:
      size in interface IndexedSortable
      Returns:
      The number of elements.
    • getIterator

      public final org.apache.flink.util.MutableObjectIterator<T> getIterator()
      Gets an iterator over all records in this buffer in their logical order.
      Specified by:
      getIterator in interface InMemorySorter<T>
      Returns:
      An iterator returning the records in their logical order.
    • writeToOutput

      public void writeToOutput(ChannelWriterOutputView output) throws IOException
      Writes the records in this buffer in their logical order to the given output.
      Specified by:
      writeToOutput in interface InMemorySorter<T>
      Parameters:
      output - The output view to write the records to.
      Throws:
      IOException - Thrown, if an I/O exception occurred writing to the output view.
    • writeToOutput

      public void writeToOutput(ChannelWriterOutputView output, LargeRecordHandler<T> largeRecordsOutput) throws IOException
      Specified by:
      writeToOutput in interface InMemorySorter<T>
      Throws:
      IOException
    • writeToOutput

      public void writeToOutput(ChannelWriterOutputView output, int start, int num) throws IOException
      Writes a subset of the records in this buffer in their logical order to the given output.
      Specified by:
      writeToOutput in interface InMemorySorter<T>
      Parameters:
      output - The output view to write the records to.
      start - The logical start position of the subset.
      num - The number of elements to write.
      Throws:
      IOException - Thrown, if an I/O exception occurred writing to the output view.