Hash Aggregate methods take various input arguments and return two iterators: one for the grouping values and one for the group aggregates.
hash_agg_max( ... ) Returns a sequence of the same type with the maximum value for each group of elements hash_agg_min( ... ) Returns a sequence of the same type with the minimum value for each group of elements hash_agg_sum( ... ) Returns a sequence of the same type with the sum of each group of elements hash_agg_avg( ... ) Returns a double
result sequence with the average of each group of elementshash_agg_approxdc( ... ) Returns a uint4
result sequence with the approximate district count for each group of elementshash_agg_count( ... ) Returns a uint8
result_count sequence with the count of the number of elements in each grouphash_agg_distinct_count( ... ) Returns a uint8
result_count sequence with the count of the number of distinct elements in each grouphash_agg_dup_count() Returns a
uint8
sequence with the count of duplicates in each group. Parametermin_occurrences
specifies minimal number for occurrences of a particular value to be counted. Withmin_occurrences=1
this function is equivalent tomco_seq_hash_agg_distinct_count()
, withmin_occurrences=2
it counts items encountered more than once... Ifn_pairs
parameter is 0, thenmco_seq_hash_init_size
is used to specify size of hash table and it is automatically extended when threshold determined bymco_seq_hash_load_factor
is reached.Example
Following is an example code snippet demonstrating how to use a hash aggregate function 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)) { Quote_from_cursor(trans, "e_cursor, "e); Quote_close_iterator("e, &close_iterator); Quote_volume_iterator("e, &volume_iterator); rc = mco_seq_const_uint4(&const_iterator, 10)); rc = mco_seq_div_uint4(&volume_div_10_iterator, &volume_iterator, &const_iterator); rc = mco_seq_hash_agg_avg_float(&avg_iterator, &group_iterator, &close_iterator, &volume_div_10_iterator, 0); ... mco_seq_free_hash(&avg_iterator); } ... }