Class FixedLengthRecordSorter<T>
- java.lang.Object
-
- org.apache.flink.runtime.operators.sort.FixedLengthRecordSorter<T>
-
- All Implemented Interfaces:
IndexedSortable
,InMemorySorter<T>
,Disposable
public final class FixedLengthRecordSorter<T> extends Object implements InMemorySorter<T>
-
-
Constructor Summary
Constructors Constructor Description FixedLengthRecordSorter(TypeSerializer<T> serializer, TypeComparator<T> comparator, List<MemorySegment> memory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(int i, int j)
Compare items at the given addresses consistent with the semantics ofComparator.compare(Object, Object)
.int
compare(int segmentNumberI, int segmentOffsetI, int segmentNumberJ, int segmentOffsetJ)
Compare records at the given addresses consistent with the semantics ofComparator.compare(Object, Object)
.void
dispose()
Disposes the sorter.long
getCapacity()
Gets the total capacity of this sorter, in bytes.MutableObjectIterator<T>
getIterator()
Gets an iterator over all records in this buffer in their logical order.long
getOccupancy()
Gets the number of bytes currently occupied in this sorter, records and sort index.T
getRecord(int logicalPosition)
Gets the record at the given logical position.T
getRecord(T reuse, int logicalPosition)
Gets the record at the given logical position.boolean
isEmpty()
Checks whether the buffer is empty.int
recordSize()
Gets the size of each record, the number of bytes separating the head of successive records.int
recordsPerSegment()
Gets the number of elements in each memory segment.void
reset()
Resets the sort buffer back to the state where it is empty.int
size()
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
writeToOutput(ChannelWriterOutputView output)
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
writeToOutput(ChannelWriterOutputView output, LargeRecordHandler<T> largeRecordsOutput)
-
-
-
Constructor Detail
-
FixedLengthRecordSorter
public FixedLengthRecordSorter(TypeSerializer<T> serializer, TypeComparator<T> comparator, List<MemorySegment> memory)
-
-
Method Detail
-
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 interfaceIndexedSortable
- 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 interfaceIndexedSortable
- 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 interfaceInMemorySorter<T>
-
isEmpty
public boolean isEmpty()
Checks whether the buffer is empty.- Specified by:
isEmpty
in interfaceInMemorySorter<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 interfaceDisposable
- Specified by:
dispose
in interfaceInMemorySorter<T>
-
getCapacity
public long getCapacity()
Description copied from interface:InMemorySorter
Gets the total capacity of this sorter, in bytes.- Specified by:
getCapacity
in interfaceInMemorySorter<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 interfaceInMemorySorter<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 interfaceInMemorySorter<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 interfaceInMemorySorter<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 interfaceInMemorySorter<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 ofComparator.compare(Object, Object)
.- Specified by:
compare
in interfaceIndexedSortable
-
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 ofComparator.compare(Object, Object)
.- Specified by:
compare
in interfaceIndexedSortable
- Parameters:
segmentNumberI
- index of memory segment containing first recordsegmentOffsetI
- offset into memory segment containing first recordsegmentNumberJ
- index of memory segment containing second recordsegmentOffsetJ
- 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 interfaceIndexedSortable
-
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 interfaceIndexedSortable
- Parameters:
segmentNumberI
- index of memory segment containing first recordsegmentOffsetI
- offset into memory segment containing first recordsegmentNumberJ
- index of memory segment containing second recordsegmentOffsetJ
- 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 interfaceIndexedSortable
- Returns:
- The number of elements.
-
getIterator
public final MutableObjectIterator<T> getIterator()
Gets an iterator over all records in this buffer in their logical order.- Specified by:
getIterator
in interfaceInMemorySorter<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 interfaceInMemorySorter<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 interfaceInMemorySorter<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 interfaceInMemorySorter<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.
-
-