Reviews
Oracle CoherenceOracle Coherence: Built-in Aggregators
Just as with filters, Coherence ships with a number of useful built-in aggregators, and an equivalent of the AverageAggregator is one of them.
Actually, there are two average aggregators built-in, as you can see in the following table:
- ----------------------------------------------------------------------------------
- Filter Class Description
- ----------------------------------------------------------------------------------
- BigDecimalAverage Calculates the average for a set of numeric values extracted from the cache entries and returns the result as a BigDecimal
- BigDecimalMax Returns the maximum value, as a BigDecimal, for a set of numeric values extracted from the cache entries.
- BigDecimalMin Returns the minimum value, as a BigDecimal, for a set of numeric values extracted from the cache entries.
- BigDecimalSum Calculates the sum for a set of numeric values extracted from the cache entries and returns the result as a BigDecimal.
- DoubleAverage Calculates the average for a set of numeric values extracted from the cache entries and returns the result as a Double.
- DoubleMax Returns the maximum value, as a Double, for a set of numeric values extracted from the cache entries.
- DoubleMin Returns the minimum value, as a Double, for a set of numeric values extracted from the cache entries.
- DoubleSum Calculates the sum for a set of numeric values extracted from the cache entries and returns the result as a Double.
- LongMax Returns the maximum value, as a Long, for a set of numeric values extracted from the cache entries.
- LongMin Returns the minimum value, as a Long, for a set of numeric values extracted from the cache entries.
- LongSum Calculates the sum for a set of numeric values extracted from the cache entries and returns the result as a Long.
- ComparableMax Returns the maximum value for a set of Comparable values extracted from the cache entries.
- ComparableMin Returns the minimum value for a set of Comparable values extracted from the cache entries.
- Count Returns the number of values in an entry set
equivalent to SQL's "select count(*)". - DistinctValues Returns a set of unique values extracted from the cache entries
equivalent to SQL's "select distinct". - CompositeAggregator Executes a collection of aggregators against the same entry set and returns the list of results, one for each aggregator in the collection.
- GroupAggregator A wrapper aggregator that allows you to split entries in a set based on some criteria and to aggregate each subset separately and independently.
The important thing to note about the various average, max, min, and sum aggregators is that they differ from each other in how they treat the numeric values they are aggregating, as well as by the type of the return value.
For example, while you can use the DoubleAverage aggregator to calculate the average for any set of java.lang.Number-derived values, you should be aware that each individual value will be converted to Double first using the Number.doubleValue method, which might lead to rounding errors. What you will typically want to do is use the most appropriate aggregator based on the actual type of the values you are aggregating, and convert the final result to the desired type if necessary.
Using aggregators
So far we have learned how to implement an aggregator and which aggregators are shipped with Coherence, but we haven't learned how to use them yet.
In order to execute an aggregator, you need to use one of the methods defined by the com.tangosol.util.InvocableMap interface:
- public interface InvocableMap extends Map {
- Object aggregate(Collection keys,
- InvocableMap.EntryAggregator aggregator)
- Object aggregate(Filter filter,
- InvocableMap.EntryAggregator aggregator)
- }
There are few more methods in the InvocableMap interface that we will cover in more detail in the next chapter, but these two are all we need to execute aggregators against cache entries.
The first overload of the aggregate method accepts an explicit collection of keys for a set of entries to aggregate, while the second one uses a filter to determine the set of entries aggregation should be performed on. Both methods accept an aggregator instance as a second argument, which can be either one of the built-in aggregators or a custom aggregator you have implemented.
Oracle Coherence
- Oracle Coherence 3.5
- Oracle Coherence: Distributed Caching
- Oracle Coherence: In-place and Parallel Processing
- Oracle Coherence: Coherence within the Oracle Ecosystem
- Oracle Coherence: Querying The Data Grid
- Oracle Coherence: Built-in Filters
- Oracle Coherence: Value and Reflection Extractor
- Oracle Coherence: Other built-in value extractors
- Oracle Coherence: Implementing Custom Value Extractor
- Oracle Coherence: Simplifying Coherence Queries
- Oracle Coherence: Obtaining Query Results
- Oracle Coherence: Controlling Query Scope Using Data Affinity
- Oracle Coherence: Querying Near Cache
- Oracle Coherence: Paging Over Query Results
- Oracle Coherence: Anatomy of an Index
- Oracle Coherence: Creating Indexes
- Oracle Coherence: Query Limitations
- Oracle Coherence: Aggregators
- Oracle Coherence: Built-in Aggregators
- Oracle Coherence: Implementing LookupValuesAggregator







