Interface UserDefinedAggregateFunction

    • 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.