Introduction

jAgg runs aggregate calculations on any List of objects. It doesn't care where the objects came from; those object classes don't need to extend any jAgg base class or implement any jAgg interface.

Just supply some Aggregators at a minimum, and jAgg will take care of the rest. These Aggregators specify what aggregate operation to perform, and on which object property to perform them. These properties are assumed to named in Java Beans naming convention, e.g. "propOne" means the zero-argument method "getPropOne". For boolean getters, the zero-argument method "isPropOne" will be searched for also. jAgg returns a List of AggregateValues, which wrap your object and store the aggregate values. It is possible to use "nested" properties, with a "." character separating nested properties, e.g. "item.objectB.displayName". If a method isn't found, e.g. for the property "property", a getProperty() method isn't found, then jAgg will look for a get(String) or a get(Object) method and pass in the property name as the parameter, e.g. get("property").

Optionally, specify a List of properties that jAgg will "group by". This works like the "group by" clause in standard SQL. That is, jAgg will produce one AggregateValue for each set of objects that have the same properties, among those listed.

Optionally, specify grouping sets, rollups, or cubes. Such "super aggregate" operations are implemented to provide subtotals and/or grand totals for certain categories.

Optionally, specify a degree of parallelism. For large datasets, this may make jAgg faster by having different Threads perform the calculations in parallel.

Normally, jAgg uses sorting to gather all objects whose properties compare equal together. Optionally, specify to use Multiset Discrimination instead. AggregateValues may no longer come out in sorted order, but Multiset Discrimination is a faster way to "group" all objects together whose properties compare equal.

jAgg runs analytic calculations on an List of objects. Unlike aggregate operations, analytic calculations will produce a value for every row of data.

Supply some AnalyticFunctions, and jAgg will take care of the rest. AnalyticFunctions may or may not have a property to analyze, but one can specify an optional partition clause, an optional order by clause, and an optional window clause.

jAgg uses sorting to group data in the same partition together, in the desired order, for each analytic function.

Build Your Aggregation Object

There are many different options to specify for aggregate operations, and most of them are optional. Use the Builder class inside the Aggregation class to specify the desired options and create an Aggregation object that will perform the actual aggregation operations.

Here is example code that demonstrates all of the Builder options.

Aggregation agg = new Aggregation.Builder()
   .setAggregators(aggsList)
   .setProperties(propertiesList)
   .setParallelism(numThreads)
   .setUseMsd(true)
   .setCube(integerPropIndexList)
   .build();
List<AggregateValue<Record>> aggValues = agg.groupBy(listOfYourObjects);
            

In place of "setCube", one can also use "setRollups" or "setGroupingSets". Each of these three would overwrite the other if previously called. If any of these three are called, then it is required to call "setProperties" before it is called.

Build Your Analytic Object

Use the Builder class inside the Analytic class to specify the desired AnalyticFunctions and create an Analytic object that will perform the actual analytic operations. AnalyticFunctions must be wrapped in AnalyticAggregators so they can be associated with any partition clause, order by clause, and/or window clause.

Analytic ana = new Analytic.Builder()
   .setAnalytics(analyticAggsList)
   .build();
List<AnalyticValue<Record>> anaValues = agg.analyze(listOfYourObjects);