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:
  • 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

    Modifier and Type
    Method
    Description
    boolean
    checkSortKeyInBufferRange(org.apache.flink.table.data.RowData sortKey, long topNum)
    Checks whether the record should be put into the buffer.
    boolean
    containsKey(org.apache.flink.table.data.RowData key)
    Returns true if 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>>>
    Returns a Set view 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.
    int
    Gets number of total records.
    org.apache.flink.table.data.RowData
    getElement(int rank)
    Gets record which rank is given value.
    Comparator<org.apache.flink.table.data.RowData>
    Gets sort key comparator used by buffer.
    org.apache.flink.table.data.RowData
    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>>
    Returns the last Entry in the buffer.
    int
    put(org.apache.flink.table.data.RowData sortKey, org.apache.flink.table.data.RowData value)
    Appends a record into the buffer.
    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.
    void
    remove(org.apache.flink.table.data.RowData sortKey, org.apache.flink.table.data.RowData value)
     
    void
    removeAll(org.apache.flink.table.data.RowData sortKey)
    Removes all record list from the buffer under the sortKey.
    org.apache.flink.table.data.RowData
    Removes the last record of the last Entry in the buffer.

    Methods inherited from class java.lang.Object

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

    • TopNBuffer

      public TopNBuffer(Comparator<org.apache.flink.table.data.RowData> sortKeyComparator, Supplier<Collection<org.apache.flink.table.data.RowData>> valueSupplier)
  • Method Details

    • 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 associated
      value - 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 associated
      values - 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 a Set view 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)
      Returns true 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<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 test
      topNum - buffer to add
      Returns:
      true if the record should be put into the buffer.