The C
mco_seq_agg_count()
andmco_seq_agg_approxdc()
functions compute the count of all elements in the sequence and a count of distinct elements for the input sequence. Themco_seq_agg_count()
API returns auint8
value and themco_seq_agg_approxdc()
andmco_seq_agg_approxdc_hash()
APIs return auint4
value in the first element of the result sequence. Whereasmco_seq_agg_approxdc()
returns the approximate distinct count of a single sequence,mco_seq_agg_approxdc_hash()
returns the approximate distinct count for multiple sequences. The input formco_seq_agg_approxdc_hash()
is typically the result of functionmco_seq_hash()
for one or more sequences.Example
Following is an example code snippet demonstrating these functions:
void grand_aggregate(mco_db_h db) { mco_trans_h trans; mco_cursor_t quote_cursor; Quote quote; mco_seq_iterator_t close_iterator, count_iterator, approxdc_iterator; mco_seq_iterator_t high_iterator, low_iterator, approxdc_hash_iterator; mco_seq_iterator_t hash_iterator[2]; uint8 count, approxdc; 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); /* Initialize iterators */ Quote_close_iterator("e, &close_iterator)); /* Construct operator's pipeline */ ... rc = mco_seq_agg_count(&count_iterator, &close_iterator); rc = mco_seq_next_uint8(&count_iterator, &count); ... rc = mco_seq_agg_approxdc(&approxdc_iterator, &close_iterator[1]); rc = mco_seq_next_double(&approxdc_iterator, &approxdc); ... mco_seq_hash(&hash_iterator[0], &high_iterator, 0); mco_seq_hash(&hash_iterator[1], &low_iterator, &hash_iterator[0]); mco_seq_agg_approxdc_hash(&approxdc_hash_iterator, &hash_iterator[1]); } } ... }