Built-In Analytics
The jagg package contains the "Analytic", "AnalyticAggregator", and "AnalyticValue"
classes, plus many built-in Analytics. The developer should reference Analytics in
their analytic specification strings without the "Aggregator",
"AnalyticAggregator", or "Aanlytic" suffixes, e.g. “Avg(property)”.
All but 2 of the built-in Aggregators also function
as built-in Analytics. The exceptions are "Max" and "Min", which are covered specially
below.
Here is a list of the 9 built-in Analytics-only analytic functions:
- CumeDistAnalytic – Determines the
cumulative distribution of "order by" values, e.g. "CumeDist()". The
analytic value returned is a Double.
- DenseRankAnalytic - Determines
the rank of an "order by" value within a partition, e.g. "DenseRank()", with "ties"
receiving the same value, with no gaps, e.g. 1, 2, 2, 3, 4. The
analytic value returned is a Long.
- LagAnalytic – Retrieves a property value
from a different row, e.g. "Lag(value1, 2, 0)" returns the value from two rows
behind, or 0 if there is no such value in the partition. The analytic value
returned is an Object.
- LeadAnalytic – Retrieves a property
value from a different row, e.g. "Lead(value1, 2, 0)" returns the value from
two rows ahead, or 0 if there is no such value in the partition. The analytic
value returned is an Object. Note that
lag(prop, n, def) == lead(prop, -n, def).
- NtileAnalytic – Determines the bucket
number, from 1 to n, of a "order by" value within a partition, e.g.
"Ntile(4)". The analytic value returned is a Long.
- PercentRankAnalytic –
Determines the percent rank of a property value, e.g. "PercentRank(prop)", from
0 (inclusive) to 1 (exclusive). The analytic value returned is a
Double.
- RankAnalytic – Determines
the rank of an "order by" value within a partition, e.g. "Rank()", with "ties" receiving
the same value. If ties are present, then gaps may be present in the rankings,
e.g. 1, 2, 2, 4, 5. The analytic value returned is a
Long.
- RatioToReportAnalytic –
Determines ratio of the current numeric property value to the sum of that
property value across the entire partition, e.g. "RatioToReport(testResult)".
The analytic value returned is a Double.
- RowNumberAnalytic – Determines
the row number of an "order by" value, e.g. "RowNumber()". Row numbers returned start with
1 and are unique, even in the case of "ties", e.g. 1, 2, 3, 4, 5.
The analytic value returned is a Long.
The following analytic functions subclass existing built-in Aggregators
and implement AnalyticFunction, to supply different behind-the-scenes
functionality to implement the analytic function:
- MaxAnalyticAggregator -
Determines the maximum value of a property that is Comparable, e.g.
"Max(testResult)". The analytic value returned is a Comparable.
- MinAnalyticAggregator -
Determines the minimum value of a property that is Comparable, e.g.
"Min(testResult)". The analytic value returned is a Comparable.
Offset Analytics
The LagAnalytic and LeadAnalytic analytic functions each
subclass the abstract class AbstractOffsetAnalytic.
AbstractOffsetAnalytic handles much of the analytic processing code, while
each subclass supplies its own logical offset based on its properties.
No-Prop Analytics
Some analytic functions require no properties at all. Their values depend entirely
on the number of rows in the partition, the order by clause, and the position of the
current row in the partition. Such AnalyticFunctions subclass the
abstract class NoPropAnalytic, which disallows any properties.
The following AnalyticFunctions are also NoPropAnalytics:
- DenseRankAnalytic
- RankAnalytic
- RowNumberAnalytic
Dependent Analytics
Some analytic functions require calculations based on other
AnalyticFunctions, but those functions on which they depend require
different window clauses. Such analytic functions are implementations of the
DependentAnalyticFunction interface, of which the abstract class
AbstractDependentAnalyticFunction supplies common code.
The following AnalyticFunctions are also
AbstractDependentAnalyticFunctions:
- CumeDistAnalytic
- NtileAnalytic
- PercentRankAnalytic
- RatioToReportAnalytic
Subclasses of Built-in Aggregators
Most built-in Aggregators also
implement AnalyticFunction, so they can be used directly as
AnalyticFunctions as well. However, 2 built-in Aggregators
required significantly different functionality to be processed as
AnalyticFunctions as well. In these cases, subclasses of the original
Aggregators that implement AnalyticFunction were created
to add the additional functionality.
The following AnalyticFunctions implement AnalyticFunction
and subclass built-in Aggregators that do not implement
AnalyticFunction:
- MaxAnalyticAggregator
- MinAnalyticAggregator