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 ClassesModifier and TypeClassDescriptionstatic classAn 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
FieldsModifier and TypeFieldDescriptionprotected final Longprotected longprotected final InternalTypeInfo<org.apache.flink.table.data.RowData>protected org.apache.flink.metrics.Counterprotected final booleanprotected org.apache.flink.streaming.api.operators.KeyContextprotected final booleanprotected final longprotected longprotected 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
ConstructorsModifierConstructorDescriptionprotectedAbstractTopNFunction(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 TypeMethodDescriptionprotected 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 longGets default topN size.protected booleanprotected 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, processElementMethods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
close, getIterationRuntimeContext, getRuntimeContext, setRuntimeContext
-
Field Details
-
ttlConfig
protected final org.apache.flink.api.common.state.StateTtlConfig ttlConfig -
outputRankNumber
protected final boolean outputRankNumber -
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
-
sortKeyComparator
-
keyContext
protected org.apache.flink.streaming.api.operators.KeyContext keyContext -
rankEndFetcher
-
invalidCounter
protected org.apache.flink.metrics.Counter invalidCounter -
hitCount
protected long hitCount -
requestCount
protected long requestCount
-
-
Constructor Details
-
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 Details
-
open
- 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.
-