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<org.apache.flink.table.data.RowData> sortKeyComparator, Supplier<Collection<org.apache.flink.table.data.RowData>> valueSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckSortKeyInBufferRange(org.apache.flink.table.data.RowData sortKey, long topNum)Checks whether the record should be put into the buffer.booleancontainsKey(org.apache.flink.table.data.RowData key)Returnstrueif the buffer contains a mapping for the specified key.Set<Map.Entry<org.apache.flink.table.data.RowData,Collection<org.apache.flink.table.data.RowData>>>entrySet()Returns aSetview of the mappings contained in the buffer.Collection<org.apache.flink.table.data.RowData>get(org.apache.flink.table.data.RowData sortKey)Gets the record list from the buffer under the sortKey.intgetCurrentTopNum()Gets number of total records.org.apache.flink.table.data.RowDatagetElement(int rank)Gets record which rank is given value.Comparator<org.apache.flink.table.data.RowData>getSortKeyComparator()Gets sort key comparator used by buffer.org.apache.flink.table.data.RowDatalastElement()Returns the last record of the last Entry in the buffer.Map.Entry<org.apache.flink.table.data.RowData,Collection<org.apache.flink.table.data.RowData>>lastEntry()Returns the last Entry in the buffer.intput(org.apache.flink.table.data.RowData sortKey, org.apache.flink.table.data.RowData value)Appends a record into the buffer.voidputAll(org.apache.flink.table.data.RowData sortKey, Collection<org.apache.flink.table.data.RowData> values)Puts a record list into the buffer under the sortKey.voidremove(org.apache.flink.table.data.RowData sortKey, org.apache.flink.table.data.RowData value)voidremoveAll(org.apache.flink.table.data.RowData sortKey)Removes all record list from the buffer under the sortKey.org.apache.flink.table.data.RowDataremoveLast()Removes the last record of the last Entry in the buffer.
-
-
-
Constructor Detail
-
TopNBuffer
public TopNBuffer(Comparator<org.apache.flink.table.data.RowData> sortKeyComparator, Supplier<Collection<org.apache.flink.table.data.RowData>> valueSupplier)
-
-
Method Detail
-
put
public int put(org.apache.flink.table.data.RowData sortKey, org.apache.flink.table.data.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(org.apache.flink.table.data.RowData sortKey, Collection<org.apache.flink.table.data.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<org.apache.flink.table.data.RowData> get(org.apache.flink.table.data.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
-
remove
public void remove(org.apache.flink.table.data.RowData sortKey, org.apache.flink.table.data.RowData value)
-
removeAll
public void removeAll(org.apache.flink.table.data.RowData sortKey)
Removes all record list from the buffer under the sortKey.- Parameters:
sortKey- key to remove
-
removeLast
public org.apache.flink.table.data.RowData removeLast()
Removes the last record of the last Entry in the buffer.- Returns:
- removed record
-
lastElement
public org.apache.flink.table.data.RowData lastElement()
Returns the last record of the last Entry in the buffer.
-
getElement
public org.apache.flink.table.data.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<org.apache.flink.table.data.RowData,Collection<org.apache.flink.table.data.RowData>>> entrySet()
Returns aSetview of the mappings contained in the buffer.
-
lastEntry
public Map.Entry<org.apache.flink.table.data.RowData,Collection<org.apache.flink.table.data.RowData>> lastEntry()
Returns the last Entry in the buffer. Returns null if the TreeMap is empty.
-
containsKey
public boolean containsKey(org.apache.flink.table.data.RowData key)
Returnstrueif the buffer contains a mapping for the specified key.- Parameters:
key- key whose presence in the buffer is to be tested- Returns:
trueif 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<org.apache.flink.table.data.RowData> getSortKeyComparator()
Gets sort key comparator used by buffer.- Returns:
- sort key comparator used by buffer
-
checkSortKeyInBufferRange
public boolean checkSortKeyInBufferRange(org.apache.flink.table.data.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.
-
-