Hash Aggregate Java SequenceIterator Methods

The Hash Aggregate Java SequenceIterator methods take various input arguments and return a GroupByResult result for the grouping values and groups for the group aggregates. The GroupByResult can then be converted to a SequenceIterator by calling its getIterator() method. When finished, the GroupByResult method close() should be called to release internal resources.

GroupByResult hashAggCount(int nGroups)
Returns a sequence with the count of the number of elements in each group.
GroupByResult hashAggMax(SequenceIterator groupBy, int nGroups)
Returns a sequence with the maximum value for each group of elements.
GroupByResult hashAggMin(SequenceIterator groupBy, int nGroups)
Returns a sequence of the same type with the minimum value for each group of elements.
GroupByResult hashAggSum(SequenceIterator groupBy, int nGroups)
Returns a sequence of the same type with the sum of each group of elements.
GroupByResult hashAggAvg(SequenceIterator groupBy, int nGroups)
Returns a sequence with the average of each group of elements.
GroupByResult hashAggApproxdc(SequenceIterator groupBy, int nGroups)
Returns a sequence with the approximate distinct count for each group of elements.
GroupByResult hashAggDistinctCount(SequenceIterator groupBy, int nGroups, int nPairs)
Returns a sequence with the count of the number of distinct elements in each group.
GroupByResult hashAggDupCount(SequenceIterator groupBy, int nGroups, int nPairs, int minOccurrences)

Returns a sequence with the count of duplicates in each group. Parameter minOccurrences specifies the minimum number of occurrences of a particular value to be counted. With minOccurrences=1, this method is equivalent to hashAggDistinctCount(); with minOccurrences=2, it counts items encountered more than once.

Example

The following code snippet demonstrates the use of a hash aggregate method to calculate the average Close price for Volume values in ranges of 0..9, 10..19, 20..29, etc.:

    public static void hashAggregate(Connection con)
    {
        con.startTransaction(Database.TransactionType.ReadOnly);
        Cursor<Quote> cursor = new Cursor<Quote>(con, Quote.class, "symbol");
        for (Quote quote : cursor)
        {
            SequenceIterator ranges = SequenceIterator.constant(10, Sequence.Type.UInt4);
            SequenceIterator volRanges = quote.volume.iterator().div(ranges);
            GroupByResult result = quote.close.iterator().hashAggAvg(volRanges, 0);
            SequenceIterator avg = result.getAggIterator();
            result.close();
            ...
        }
        con.commitTransaction();
    }