Class AbstractTopNFunction

java.lang.Object
org.apache.flink.api.common.functions.AbstractRichFunction
org.apache.flink.streaming.api.functions.KeyedProcessFunction<org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData>
org.apache.flink.table.runtime.operators.rank.AbstractTopNFunction
All Implemented Interfaces:
Serializable, org.apache.flink.api.common.functions.Function, org.apache.flink.api.common.functions.RichFunction
Direct Known Subclasses:
AbstractAsyncStateTopNFunction, AbstractSyncStateTopNFunction

public abstract class AbstractTopNFunction extends org.apache.flink.streaming.api.functions.KeyedProcessFunction<org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData>
Base class for TopN Function.

TODO: move util methods and metrics to AbstractTopNHelper after using AbstractTopNHelper in all TopN functions.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An abstract helper to do the logic Top-n used for all top-n functions.

    Nested classes/interfaces inherited from class org.apache.flink.streaming.api.functions.KeyedProcessFunction

    org.apache.flink.streaming.api.functions.KeyedProcessFunction.Context, org.apache.flink.streaming.api.functions.KeyedProcessFunction.OnTimerContext
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Long
     
    protected long
     
    protected final InternalTypeInfo<org.apache.flink.table.data.RowData>
     
    protected org.apache.flink.metrics.Counter
     
    protected final boolean
     
    protected org.apache.flink.streaming.api.operators.KeyContext
     
    protected final boolean
     
    protected Function<org.apache.flink.table.data.RowData,Long>
     
    protected final long
     
    protected long
     
    protected Comparator<org.apache.flink.table.data.RowData>
     
    protected final org.apache.flink.api.java.functions.KeySelector<org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData>
     
    protected final org.apache.flink.api.common.state.StateTtlConfig
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractTopNFunction(org.apache.flink.api.common.state.StateTtlConfig ttlConfig, InternalTypeInfo<org.apache.flink.table.data.RowData> inputRowType, GeneratedRecordComparator generatedSortKeyComparator, RowDataKeySelector sortKeySelector, RankType rankType, RankRange rankRange, boolean generateUpdateBefore, boolean outputRankNumber)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    checkSortKeyInBufferRange(org.apache.flink.table.data.RowData sortKey, TopNBuffer buffer)
    Checks whether the record should be put into the buffer.
    protected void
    collectDelete(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
     
    protected void
    collectDelete(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
     
    protected void
    collectInsert(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
     
    protected void
    collectInsert(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
     
    protected void
    collectUpdateAfter(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
     
    protected void
    collectUpdateAfter(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
     
    protected void
    collectUpdateBefore(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
     
    protected void
    collectUpdateBefore(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
     
    protected long
    Gets default topN size.
    protected boolean
     
    protected boolean
    isInRankRange(long rank, long rankEnd)
     
    void
    open(org.apache.flink.api.common.functions.OpenContext openContext)
     
    protected void
    registerMetric(long heapSize)
     
    protected void
    registerMetric(long heapSize, long requestCount, long hitCount)
     
    void
    setKeyContext(org.apache.flink.streaming.api.operators.KeyContext keyContext)
    Sets keyContext to RankFunction.

    Methods inherited from class org.apache.flink.streaming.api.functions.KeyedProcessFunction

    onTimer, processElement

    Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction

    close, getIterationRuntimeContext, getRuntimeContext, setRuntimeContext

    Methods inherited from class java.lang.Object

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

    • ttlConfig

      protected final org.apache.flink.api.common.state.StateTtlConfig ttlConfig
    • outputRankNumber

      protected final boolean outputRankNumber
    • inputRowType

      protected final InternalTypeInfo<org.apache.flink.table.data.RowData> inputRowType
    • sortKeySelector

      protected final org.apache.flink.api.java.functions.KeySelector<org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData> sortKeySelector
    • isConstantRankEnd

      protected final boolean isConstantRankEnd
    • rankStart

      protected final long rankStart
    • constantRankEnd

      @Nullable protected final Long constantRankEnd
    • sortKeyComparator

      protected Comparator<org.apache.flink.table.data.RowData> sortKeyComparator
    • keyContext

      protected org.apache.flink.streaming.api.operators.KeyContext keyContext
    • rankEndFetcher

      protected transient Function<org.apache.flink.table.data.RowData,Long> rankEndFetcher
    • invalidCounter

      protected org.apache.flink.metrics.Counter invalidCounter
    • hitCount

      protected long hitCount
    • requestCount

      protected long requestCount
  • Constructor Details

  • Method Details

    • open

      public void open(org.apache.flink.api.common.functions.OpenContext openContext) throws Exception
      Specified by:
      open in interface org.apache.flink.api.common.functions.RichFunction
      Overrides:
      open in class org.apache.flink.api.common.functions.AbstractRichFunction
      Throws:
      Exception
    • getDefaultTopNSize

      protected long getDefaultTopNSize()
      Gets default topN size.
      Returns:
      default topN size
    • checkSortKeyInBufferRange

      protected boolean checkSortKeyInBufferRange(org.apache.flink.table.data.RowData sortKey, TopNBuffer buffer)
      Checks whether the record should be put into the buffer.
      Parameters:
      sortKey - sortKey to test
      buffer - buffer to add
      Returns:
      true if the record should be put into the buffer.
    • registerMetric

      protected void registerMetric(long heapSize)
    • registerMetric

      protected void registerMetric(long heapSize, long requestCount, long hitCount)
    • collectInsert

      protected void collectInsert(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
    • collectInsert

      protected void collectInsert(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
    • collectDelete

      protected void collectDelete(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
    • collectDelete

      protected void collectDelete(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
    • collectUpdateAfter

      protected void collectUpdateAfter(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
    • collectUpdateAfter

      protected void collectUpdateAfter(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
    • collectUpdateBefore

      protected void collectUpdateBefore(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)
    • collectUpdateBefore

      protected void collectUpdateBefore(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)
    • isInRankRange

      protected boolean isInRankRange(long rank, long rankEnd)
    • hasOffset

      protected boolean hasOffset()
    • setKeyContext

      public void setKeyContext(org.apache.flink.streaming.api.operators.KeyContext keyContext)
      Sets keyContext to RankFunction.
      Parameters:
      keyContext - keyContext of current function.