Class TopNBuffer
- java.lang.Object
-
- org.apache.flink.table.runtime.operators.rank.TopNBuffer
-
- All Implemented Interfaces:
Serializable
public class TopNBuffer extends Object implements Serializable
TopNBuffer stores mapping from sort key to records list, sortKey is RowData type, each record is RowData type. TopNBuffer could also track rank number of each record.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TopNBuffer(Comparator<RowData> sortKeyComparator, Supplier<Collection<RowData>> valueSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkSortKeyInBufferRange(RowData sortKey, long topNum)
Checks whether the record should be put into the buffer.boolean
containsKey(RowData key)
Returnstrue
if the buffer contains a mapping for the specified key.Set<Map.Entry<RowData,Collection<RowData>>>
entrySet()
Returns aSet
view of the mappings contained in the buffer.Collection<RowData>
get(RowData sortKey)
Gets the record list from the buffer under the sortKey.int
getCurrentTopNum()
Gets number of total records.RowData
getElement(int rank)
Gets record which rank is given value.Comparator<RowData>
getSortKeyComparator()
Gets sort key comparator used by buffer.RowData
lastElement()
Returns the last record of the last Entry in the buffer.Map.Entry<RowData,Collection<RowData>>
lastEntry()
Returns the last Entry in the buffer.int
put(RowData sortKey, RowData value)
Appends a record into the buffer.void
putAll(RowData sortKey, Collection<RowData> values)
Puts a record list into the buffer under the sortKey.void
remove(RowData sortKey, RowData value)
void
removeAll(RowData sortKey)
Removes all record list from the buffer under the sortKey.RowData
removeLast()
Removes the last record of the last Entry in the buffer.
-
-
-
Constructor Detail
-
TopNBuffer
public TopNBuffer(Comparator<RowData> sortKeyComparator, Supplier<Collection<RowData>> valueSupplier)
-
-
Method Detail
-
put
public int put(RowData sortKey, RowData value)
Appends a record into the buffer.- Parameters:
sortKey
- sort key with which the specified value is to be associatedvalue
- record which is to be appended- Returns:
- the size of the collection under the sortKey.
-
putAll
public void putAll(RowData sortKey, Collection<RowData> values)
Puts a record list into the buffer under the sortKey. Note: if buffer already contains sortKey, putAll will overwrite the previous value- Parameters:
sortKey
- sort key with which the specified values are to be associatedvalues
- record lists to be associated with the specified key
-
get
public Collection<RowData> get(RowData sortKey)
Gets the record list from the buffer under the sortKey.- Parameters:
sortKey
- key to get- Returns:
- the record list from the buffer under the sortKey
-
removeAll
public void removeAll(RowData sortKey)
Removes all record list from the buffer under the sortKey.- Parameters:
sortKey
- key to remove
-
removeLast
public RowData removeLast()
Removes the last record of the last Entry in the buffer.- Returns:
- removed record
-
lastElement
public RowData lastElement()
Returns the last record of the last Entry in the buffer.
-
getElement
public RowData getElement(int rank)
Gets record which rank is given value.- Parameters:
rank
- rank value to search- Returns:
- the record which rank is given value
-
entrySet
public Set<Map.Entry<RowData,Collection<RowData>>> entrySet()
Returns aSet
view of the mappings contained in the buffer.
-
lastEntry
public Map.Entry<RowData,Collection<RowData>> lastEntry()
Returns the last Entry in the buffer. Returns null if the TreeMap is empty.
-
containsKey
public boolean containsKey(RowData key)
Returnstrue
if the buffer contains a mapping for the specified key.- Parameters:
key
- key whose presence in the buffer is to be tested- Returns:
true
if the buffer contains a mapping for the specified key
-
getCurrentTopNum
public int getCurrentTopNum()
Gets number of total records.- Returns:
- the number of total records.
-
getSortKeyComparator
public Comparator<RowData> getSortKeyComparator()
Gets sort key comparator used by buffer.- Returns:
- sort key comparator used by buffer
-
checkSortKeyInBufferRange
public boolean checkSortKeyInBufferRange(RowData sortKey, long topNum)
Checks whether the record should be put into the buffer.- Parameters:
sortKey
- sortKey to testtopNum
- buffer to add- Returns:
- true if the record should be put into the buffer.
-
-