AnalyticFunction Interface

To accomplish the analytic functionality desired, jAgg uses a cache of objects that implement the AnalyticAggregator class to perform the actual analytic calculations. These AnalyticAggregators wrap objects that implement the AnalyticFunction interface. These objects are analogous to the Oracle object types that can be created for custom aggregation functions. The AnalyticFunction interface does the following:

  1. Defines the interface that the AnalyticAggregator and Analytic classes expect.
  2. Extends the AggregateFunction interface.
  3. Calculates an analytic value based on a sliding window of values in the original List of Objects, for every value in that List of Objects.

Implementing classes implement all of the methods from the AggregateFunction interface. They also implement the method delete to remove a value from the window that was previously added using iterate.

AnalyticFunctions aren't responsible for maintaining or using the partition, order by, or window clauses. The AnalyticAggregator class handles them. However, certain analytic functions can specify that they don't take a user-given window clause. With the takesWindowClause method, AnalyticFunctions can specify whether they accept a user-given window clause. If they don't, then they can specify their own window clause with the getWindowClause method.

Typically, AnalyticFunction is implemented in one of 3 ways.

  • Aggregators that can easily supply a delete method will simply implement AnalyticFunction and be done.
  • A few Aggregators that need more complicated processing to implement delete may wish to have a separate class that subclasses the original Aggregator that implements the AnalyticFunction interface. MaxAnalyticAggregator and MinAnalyticAggregator take this route. By convention, the names of the classes that take this route end in "AnalyticAggregator".
  • Certain AnalyticFunctions are analytic-only; they make no sense in an aggregate function context. Such analytic functions usually inherit directly from Aggregator and implement AnalyticFunction directly. By convention, the names of the classes that take this route end in "Analytic".

Methods

The following methods are declared by the AnalyticFunction interface. The example followed in the explanations for each method below are for a function that computes an average of property values.

  • All AggregateFunction methods are implemented.
  • void delete(Object value) - Extract the property from the value and remove the property from the function's state. Example: subtract the property from the running sum and decrement the running count.
  • boolean takesWindowClause() - Determines whether this AnalyticFunction takes a user-given window clause or supplies its own. Example: It can take a user-given window clause, so this method returns true.
  • WindowClause getWindowClause() - If this AnalyticFunction doesn't accept a user-given window clause, then this method supplies its own window clause. Example: It accepts a user-given window clause, so this method returns null.