All Group Aggregate C API functions take two input sequence iterator arguments, input and group_by, except
mco_seq_group_agg_wavg_TYPE()
which has left and right sequences as well as group_by. The result of all Group Aggregate functions is returned in the result sequence as the calculated aggregate for each group. The input sequence is split into groups based on the values in the group_by sequence which is expected to be ordered.Except for
mco_seq_group_agg_wavg_TYPE()
,the function signatures are of the following form:MCO_RET mco_seq_group_agg_operation(mco_seq_iterator_h result, mco_seq_iterator_h input, mco_seq_iterator_h group_by);or
MCO_RET mco_seq_group_agg_operation_TYPE(mco_seq_iterator_h result, mco_seq_iterator_h input, mco_seq_iterator_h group_by);where TYPE is one of the types listed in the Analytics Functions page and operation is one of the following:
mco_seq_group_agg_count() Returns the uint8
result sequence with the count of the number of elements in each groupmco_seq_group_agg_max_TYPE() Returns the result sequence of the same TYPE
with the maximum value for each group of elementsmco_seq_group_agg_min_TYPE() Returns the result sequence of the same TYPE
with the minimum value for each group of elementsmco_seq_group_agg_first_TYPE() Returns the result sequence of the same TYPE
with the first element of each groupmco_seq_group_agg_last_TYPE() Returns the result sequence of the same TYPE
with the last element of each groupmco_seq_group_agg_sum_TYPE() Returns the result sequence of the same TYPE
with the sum of each group of elementsmco_seq_group_agg_avg_TYPE() Returns the double
result sequence with the average of each group of elementsmco_seq_group_agg_var_TYPE() Returns the double
result sequence with the variance of each group of elementsmco_seq_group_agg_var_samp_TYPE() Returns the double
result sequence with the sample variance of each group of elementsmco_seq_group_agg_dev_TYPE() Returns the double
result sequence with the Standard Deviation of each group of elementsmco_seq_group_agg_dev_samp_TYPE() Returns the double
result sequence with the Sample Standard Deviation of each group of elementsmco_seq_group_agg_approxdc() Returns the uint4
result sequence with the approximate count of distinct values for each groupmco_seq_group_agg_approxdc_hash() Returns the
uint4
result sequence with the approximate count of distinct values for each group for multiple sequences. Whereasmco_seq_group_agg_approxdc()
returns the approximate distinct count for each group of a single sequence,mco_seq_group_agg_approxdc_hash()
returns the approximate distinct count for multiple sequences. The input formco_seq_group_agg_approxdc_hash()
is typically the result of functionmco_seq_hash()
for one or more sequences.mco_seq_group_agg_wavg_TYPE() Returns the
double
result sequence with the weighted average for each groupMCO_RET mco_seq_group_agg_wavg_TYPE( mco_seq_iterator_h result, mco_seq_iterator_h left, mco_seq_iterator_h right, mco_seq_iterator_h group_by);Example
Following is an example code snippet demonstrating a group aggregate function:
{ mco_trans_h trans; mco_cursor_t quote_cursor; Quote quote; mco_seq_iterator_t volume_iterator, day_iterator; mco_seq_iterator_t month_iterator, const_iterator, sum_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_day_search("e, &day_iterator, DMY(1,1,2013), MCO_SEQ_BOUNDARY_INCLUSIVE, DMY(1,1,2014), MCO_SEQ_BOUNDARY_EXCLUSIVE); Quote_volume_project("e, &volume_iterator, &day_iterator); // As date is represetned as YYYYMMDD, to group it by month // we must divide date by 100 rc = mco_seq_const_uint4(&const_iterator, 100); mco_seq_div_uint4(&month_iterator, &day_iterator, &const_iterator); mco_seq_group_agg_sum_uint4(&sum_iterator, &volume_iterator, &month_iterator); ... } ... }