Grand Aggregate C Count and Approxdc Functions

The C mco_seq_agg_count() and mco_seq_agg_approxdc() functions compute the count of all elements in the sequence and a count of distinct elements for the input sequence. The mco_seq_agg_count() API returns a uint8 value and the mco_seq_agg_approxdc() and mco_seq_agg_approxdc_hash() APIs return a uint4 value in the first element of the result sequence. Whereas mco_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 for mco_seq_agg_approxdc_hash() is typically the result of function mco_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, &quote_cursor);

            rc != MCO_S_CURSOR_END;

            rc = mco_cursor_next(trans, &quote_cursor))
            {
                Quote_from_cursor(trans, &quote_cursor, &quote);

                /* Initialize iterators */
                Quote_close_iterator(&quote, &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]);

            }
        }
        ...
    }