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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractTopNFunction.AbstractTopNHelperAn abstract helper to do the logic Top-n used for all top-n functions.
-
Field Summary
Fields Modifier and Type Field Description protected LongconstantRankEndprotected longhitCountprotected InternalTypeInfo<org.apache.flink.table.data.RowData>inputRowTypeprotected org.apache.flink.metrics.CounterinvalidCounterprotected booleanisConstantRankEndprotected org.apache.flink.streaming.api.operators.KeyContextkeyContextprotected booleanoutputRankNumberprotected Function<org.apache.flink.table.data.RowData,Long>rankEndFetcherprotected longrankStartprotected longrequestCountprotected Comparator<org.apache.flink.table.data.RowData>sortKeyComparatorprotected org.apache.flink.api.java.functions.KeySelector<org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData>sortKeySelectorprotected org.apache.flink.api.common.state.StateTtlConfigttlConfig
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTopNFunction(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancheckSortKeyInBufferRange(org.apache.flink.table.data.RowData sortKey, TopNBuffer buffer)Checks whether the record should be put into the buffer.protected voidcollectDelete(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)protected voidcollectDelete(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)protected voidcollectInsert(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)protected voidcollectInsert(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)protected voidcollectUpdateAfter(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)protected voidcollectUpdateAfter(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)protected voidcollectUpdateBefore(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow)protected voidcollectUpdateBefore(org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out, org.apache.flink.table.data.RowData inputRow, long rank, long rankEnd)protected longgetDefaultTopNSize()Gets default topN size.protected booleanhasOffset()protected booleanisInRankRange(long rank, long rankEnd)voidopen(org.apache.flink.api.common.functions.OpenContext openContext)protected voidregisterMetric(long heapSize)protected voidregisterMetric(long heapSize, long requestCount, long hitCount)voidsetKeyContext(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
-
-
-
-
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
-
AbstractTopNFunction
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 Detail
-
open
public void open(org.apache.flink.api.common.functions.OpenContext openContext) throws Exception- Specified by:
openin interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
openin classorg.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 testbuffer- 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.
-
-