Package io.lenses.sql.udf
Interface UserDefinedAggregateFunction
-
- All Superinterfaces:
UserDefinedFunction
- All Known Subinterfaces:
UserDefinedTableAggregateFunction
public interface UserDefinedAggregateFunction extends UserDefinedFunction
Interface for User Defined Aggregate Functions. E.g. sum, max, count
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Valueadd(Value aggregateKey, Value aggregatedValue, Value toBeAdded)Handles adding a new value to the current aggregated value.Valueempty()The empty/initial aggregate value of this function.default java.util.Optional<FinalStep>finalStep()An optional final step that calculates and returns the result.default voidinit(Value[] args)This method can be overridden by users to perform initialization logic.Valuemerge(Value aggregateKey, Value first, Value second)Merges to aggregated values in case of windowing.DataTypetyper(DataType argType)Defines a mapping from input to output types.-
Methods inherited from interface io.lenses.sql.udf.UserDefinedFunction
name, owner, version
-
-
-
-
Method Detail
-
typer
DataType typer(DataType argType) throws UdfException
Defines a mapping from input to output types.- Parameters:
argType- The data type of the single argument.- Returns:
- The data type of the result.
- Throws:
UdfException- if the given data type is not supported by this UDF.
-
empty
Value empty()
The empty/initial aggregate value of this function.- Returns:
- the initial value.
-
init
default void init(Value[] args)
This method can be overridden by users to perform initialization logic. It is guaranteed to be called before empty, add, merge, and in case of table-based aggregations, subtract.- Parameters:
args- The tail of the arguments passed to the UDAF.
-
add
Value add(Value aggregateKey, Value aggregatedValue, Value toBeAdded) throws UdfException
Handles adding a new value to the current aggregated value.- Parameters:
aggregateKey- The key of the field being aggregated on.aggregatedValue- The current aggregated value.toBeAdded- The value to be added to the current aggregated value.- Returns:
- The updated aggregated value.
- Throws:
UdfException- if adding the new value to the current aggregated value fails.
-
merge
Value merge(Value aggregateKey, Value first, Value second) throws UdfException
Merges to aggregated values in case of windowing.- Parameters:
aggregateKey- The key of the field being aggregated on.first- The first aggregated value.second- The second aggregated value.- Returns:
- The combined aggregated value.
- Throws:
UdfException- if the merge fails.
-
finalStep
default java.util.Optional<FinalStep> finalStep()
An optional final step that calculates and returns the result.- Returns:
- An optional function that will be called with the aggregated value to calculate the final result.
-
-