The Group Aggregate Java SequenceIterator methods (except
groupAggWavg()
andgroupAggCount()
) take an input groupBy sequence argument and produce a result sequence containing the calculated aggregate for each group. The object's sequence is split into groups based on the values in the groupBy sequence which is expected to be ordered.
SequenceIterator groupAggCount() Returns a sequence with the count of the number of elements in each group SequenceIterator groupAggMax(SequenceIterator groupBy) Returns a sequence with the maximum value for each group of elements SequenceIterator groupAggMin(SequenceIterator groupBy) Returns a sequence with the minimum value for each group of elements SequenceIterator groupAggFirst(SequenceIterator groupBy) Returns a sequence with the first element of each group SequenceIterator groupAggLast(SequenceIterator groupBy) Returns a sequence with the last element of each group SequenceIterator groupAggSum(SequenceIterator groupBy) Returns a sequence with the sum of each group of elements SequenceIterator groupAggAvg(SequenceIterator groupBy) Returns a sequence with the average of each group of elements SequenceIterator groupAggVar(SequenceIterator groupBy) Returns a sequence with the variance of each group of elements SequenceIterator groupAggVarSamp(SequenceIterator groupBy) Returns a sequence with the sample variance of each group of elements SequenceIterator groupAggDev(SequenceIterator groupBy) Returns a sequence with the Standard Deviation of each group of elements SequenceIterator groupAggDevSamp(SequenceIterator groupBy) Returns a sequence with the Sample Standard Deviation of each group of elements SequenceIterator groupAggApproxDC(SequenceIterator groupBy) Returns a sequence with the approximate count of distinct values for each group SequenceIterator groupAggApproxHashDC(SequenceIterator groupBy) Returns a sequence with the approximate count of distinct values for each group for multiple sequences. Whereas
groupAggApproxDC()
returns the approximate distinct count for each group of a single sequence,groupAggApproxHashDC()
returns the approximate distinct count for multiple sequencesSequenceIterator groupAggWavg(SequenceIterator weight, SequenceIterator groupBy) Returns the
double
result sequence with the weighted average for each groupExample
Following is an example code snippet demonstrating a group aggregate function:
Cursor<Quote> cursor = new Cursor<Quote>(con, Quote.class, "symbol"); for (Quote quote : cursor) { } public static void groupByAggregate(Connection con) { con.startTransaction(Database.TransactionType.ReadOnly); Cursor<Quote> cursor = new Cursor<Quote>(con, Quote.class, "symbol"); for (Quote quote : cursor) { // Select interval SequenceIterator dayIterator = quote.day.search(20130101, OrderedSequence.Boundary.Inclusive, 20140101, OrderedSequence.Boundary.Exclusive); SequenceIterator groupBy = dayIterator.div(SequenceIterator.constant(100, Sequence.Type.UInt4)); SequenceIterator groupSum = quote.volume.project(dayIterator).groupAggSum(groupBy); ... } con.commitTransaction(); }