Class 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:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  AbstractTopNFunction.AbstractTopNHelper
      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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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 getDefaultTopNSize()
      Gets default topN size.
      protected boolean hasOffset()  
      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
    • Field Detail

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

    • Method Detail

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