Class UpdatableTopNFunction
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
org.apache.flink.table.runtime.operators.rank.AbstractSyncStateTopNFunction
org.apache.flink.table.runtime.operators.rank.UpdatableTopNFunction
- All Implemented Interfaces:
Serializable,org.apache.flink.api.common.functions.Function,org.apache.flink.api.common.functions.RichFunction,org.apache.flink.streaming.api.checkpoint.CheckpointedFunction
public class UpdatableTopNFunction
extends AbstractSyncStateTopNFunction
implements org.apache.flink.streaming.api.checkpoint.CheckpointedFunction
A TopN function could handle updating stream. It is a fast version of
RetractableTopNFunction which only hold top n data in state, and keep sorted map in heap.
However, the function only works in some special scenarios: 1. sort field collation is ascending
and its mono is decreasing, or sort field collation is descending and its mono is increasing 2.
input data has unique keys and unique key must contain partition key 3. input stream could not
contain DELETE record or UPDATE_BEFORE record- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.flink.table.runtime.operators.rank.AbstractTopNFunction
AbstractTopNFunction.AbstractTopNHelperNested 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 inherited from class org.apache.flink.table.runtime.operators.rank.AbstractSyncStateTopNFunction
rankEndFields inherited from class org.apache.flink.table.runtime.operators.rank.AbstractTopNFunction
constantRankEnd, hitCount, inputRowType, invalidCounter, isConstantRankEnd, keyContext, outputRankNumber, rankEndFetcher, rankStart, requestCount, sortKeyComparator, sortKeySelector, ttlConfig -
Constructor Summary
ConstructorsConstructorDescriptionUpdatableTopNFunction(org.apache.flink.api.common.state.StateTtlConfig ttlConfig, InternalTypeInfo<org.apache.flink.table.data.RowData> inputRowType, RowDataKeySelector rowKeySelector, GeneratedRecordComparator generatedRecordComparator, RowDataKeySelector sortKeySelector, RankType rankType, RankRange rankRange, boolean generateUpdateBefore, boolean outputRankNumber, long cacheSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidinitializeState(org.apache.flink.runtime.state.FunctionInitializationContext context) voidopen(org.apache.flink.api.common.functions.OpenContext openContext) voidprocessElement(org.apache.flink.table.data.RowData input, 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.streaming.api.functions.KeyedProcessFunction.Context context, org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out) voidsnapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context) Methods inherited from class org.apache.flink.table.runtime.operators.rank.AbstractSyncStateTopNFunction
collectDelete, collectInsert, collectUpdateAfter, collectUpdateBefore, initRankEnd, isInRankEnd, isInRankRangeMethods inherited from class org.apache.flink.table.runtime.operators.rank.AbstractTopNFunction
checkSortKeyInBufferRange, collectDelete, collectDelete, collectInsert, collectInsert, collectUpdateAfter, collectUpdateAfter, collectUpdateBefore, collectUpdateBefore, getDefaultTopNSize, hasOffset, isInRankRange, registerMetric, registerMetric, setKeyContextMethods inherited from class org.apache.flink.streaming.api.functions.KeyedProcessFunction
onTimerMethods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
close, getIterationRuntimeContext, getRuntimeContext, setRuntimeContext
-
Constructor Details
-
UpdatableTopNFunction
public UpdatableTopNFunction(org.apache.flink.api.common.state.StateTtlConfig ttlConfig, InternalTypeInfo<org.apache.flink.table.data.RowData> inputRowType, RowDataKeySelector rowKeySelector, GeneratedRecordComparator generatedRecordComparator, RowDataKeySelector sortKeySelector, RankType rankType, RankRange rankRange, boolean generateUpdateBefore, boolean outputRankNumber, long cacheSize)
-
-
Method Details
-
open
- Specified by:
openin interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
openin classAbstractSyncStateTopNFunction- Throws:
Exception
-
initializeState
public void initializeState(org.apache.flink.runtime.state.FunctionInitializationContext context) throws Exception - Specified by:
initializeStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-
processElement
public void processElement(org.apache.flink.table.data.RowData input, org.apache.flink.streaming.api.functions.KeyedProcessFunction<org.apache.flink.table.data.RowData, org.apache.flink.table.data.RowData, throws Exceptionorg.apache.flink.table.data.RowData>.org.apache.flink.streaming.api.functions.KeyedProcessFunction.Context context, org.apache.flink.util.Collector<org.apache.flink.table.data.RowData> out) - Specified by:
processElementin classorg.apache.flink.streaming.api.functions.KeyedProcessFunction<org.apache.flink.table.data.RowData,org.apache.flink.table.data.RowData, org.apache.flink.table.data.RowData> - Throws:
Exception
-
snapshotState
public void snapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context) throws Exception - Specified by:
snapshotStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-