Class LastDatedValueFunction<T>
- java.lang.Object
-
- org.apache.flink.table.functions.UserDefinedFunction
-
- org.apache.flink.table.functions.ImperativeAggregateFunction<T,ACC>
-
- org.apache.flink.table.functions.AggregateFunction<Row,LastDatedValueFunction.Accumulator<T>>
-
- org.apache.flink.table.examples.java.functions.LastDatedValueFunction<T>
-
- Type Parameters:
T
- input value
- All Implemented Interfaces:
Serializable
,FunctionDefinition
public final class LastDatedValueFunction<T> extends AggregateFunction<Row,LastDatedValueFunction.Accumulator<T>>
Implementation of anAggregateFunction
that returns a row containing the latest non-null value with its corresponding date.The function uses a custom
TypeInference
and thus disables any of the default reflection-based logic. It has a generic parameterT
which will result inObject
(due to type erasure) during runtime. TheTypeInference
will provide the necessary information how to callaccumulate(...)
for the given call in the query.For code readability, we might use some internal utility methods that should rarely change. Implementers can copy those if they don't want to rely on non-official API.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LastDatedValueFunction.Accumulator<T>
Generic accumulator for representing state.
-
Constructor Summary
Constructors Constructor Description LastDatedValueFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accumulate(LastDatedValueFunction.Accumulator<T> acc, T input, LocalDate date)
Generic runtime function that will be called with different kind of instances forinput
depending on actual call in the query.LastDatedValueFunction.Accumulator<T>
createAccumulator()
Creates and initializes the accumulator for thisImperativeAggregateFunction
.TypeInference
getTypeInference(DataTypeFactory typeFactory)
Declares theTypeInference
of this function.Row
getValue(LastDatedValueFunction.Accumulator<T> acc)
Called every time when an aggregation result should be materialized.-
Methods inherited from class org.apache.flink.table.functions.AggregateFunction
getKind
-
Methods inherited from class org.apache.flink.table.functions.ImperativeAggregateFunction
getAccumulatorType, getResultType
-
Methods inherited from class org.apache.flink.table.functions.UserDefinedFunction
close, functionIdentifier, open, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.flink.table.functions.FunctionDefinition
getRequirements, isDeterministic, supportsConstantFolding
-
-
-
-
Method Detail
-
getTypeInference
public TypeInference getTypeInference(DataTypeFactory typeFactory)
Declares theTypeInference
of this function. It specifies:- which argument types are supported when calling this function,
- which
DataType.getConversionClass()
should be used when calling the JVM methodaccumulate(Accumulator, Object, LocalDate)
during runtime, - a similar strategy how to derive an accumulator type,
- and a similar strategy how to derive the output type.
- Specified by:
getTypeInference
in interfaceFunctionDefinition
- Overrides:
getTypeInference
in classAggregateFunction<Row,LastDatedValueFunction.Accumulator<T>>
-
createAccumulator
public LastDatedValueFunction.Accumulator<T> createAccumulator()
Description copied from class:ImperativeAggregateFunction
Creates and initializes the accumulator for thisImperativeAggregateFunction
.The accumulator is an intermediate data structure that stores the aggregated values until a final aggregation result is computed.
- Specified by:
createAccumulator
in classImperativeAggregateFunction<Row,LastDatedValueFunction.Accumulator<T>>
- Returns:
- the accumulator with the initial value
-
accumulate
public void accumulate(LastDatedValueFunction.Accumulator<T> acc, T input, LocalDate date)
Generic runtime function that will be called with different kind of instances forinput
depending on actual call in the query.
-
getValue
public Row getValue(LastDatedValueFunction.Accumulator<T> acc)
Description copied from class:AggregateFunction
Called every time when an aggregation result should be materialized. The returned value could be either an early and incomplete result (periodically emitted as data arrives) or the final result of the aggregation.- Specified by:
getValue
in classAggregateFunction<Row,LastDatedValueFunction.Accumulator<T>>
- Parameters:
acc
- the accumulator which contains the current intermediate results- Returns:
- the aggregation result
-
-