The Hash Aggregate C++ Sequence methods take various input arguments and return two iterators: result for the grouping values and groups for the group aggregates.
void hashAggMax(Sequence<T>& result, GenericSequence& groups, GenericSequence const& groupBy) const Returns a sequence of the same type with the maximum value for each group of elements void hashAggMin(Sequence<T>& result, GenericSequence& groups, GenericSequence const& groupBy) const Returns a sequence of the same type with the minimum value for each group of elements void hashAggSum(Sequence<R>& result, GenericSequence& groups, GenericSequence const& groupBy) const Returns a sequence of the same type with the sum of each group of elements void hashAggAvg(Sequence<double>& result, GenericSequence& groups, GenericSequence const& groupBy) const Returns a double
result sequence with the average of each group of elementsvoid hashAggApproxDistinctCount(Sequence<uint4>& result, GenericSequence& groups, GenericSequence const& groupBy) const Returns a uint4
result sequence with the approximate district count for each group of elementsvoid hashAggCount(Sequence<uint8>& result, GenericSequence& groups) const Returns a uint8
result sequence with the count of the number of elements in each groupvoid hashAggDistinctCount(Sequence<uint8>& result, GenericSequence& groups, GenericSequence const& groupBy) const Returns a uint8
result_count sequence with the count of the number of distinct elements in each groupvoid hashAggDupCount(Sequence<uint8>& result, GenericSequence& groups, GenericSequence const& groupBy,
mco_size_t minOccurrences) const
Returns a
uint8
sequence with the count of duplicates in each group. ParameterminOccurrences
specifies minimum number for occurrences of a particular value to be counted. WithminOccurrences=1
this method is equivalent tohashAggDistinctCount()
, withminOccurrences=2
it counts items encountered more than once.Example
Following is an example code snippet demonstrating 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.:
{ mco_trans_h trans; mco_cursor_t quote_cursor; Quote quote; mco_seq_iterator_t close_iterator, volume_div_10_iterator; mco_seq_iterator_t group_iterator, avg_iterator; MCO_RET rc; ... for (rc = mco_cursor_first(trans, "e_cursor); rc != MCO_S_CURSOR_END; rc = mco_cursor_next(trans, "e_cursor)) { Sequence<double> result; Sequence<uint4> groups; Quote_from_cursor(trans, "e_cursor, "e); quote.close_iterator().hashAggAvg(result, groups, quote.volume_iterator() / Sequence<uint4>(10)); print_sequence(quote, result); } ... }