C Analytics Functions by Category

The table below provides links to pages describing the functions in detail. The examples on these pages use the following schema definition for a database of stock quotes:

    #define uint4 unsigned<4>
    #define MAX_SYMBOL_LEN 21

    declare database stockdb;

    class Quote
    {
        char<MAX_SYMBOL_LEN> symbol;
        sequence<date asc> day;
        sequence<float> low;
        sequence<float> high;
        sequence<float> open;
        sequence<float> close;
        sequence<uint4> volume;
        sequence<char<15>> day_str;

        unique tree<symbol> by_sym;
    };

Note that the primary key for this table is the unique index by_sym on the symbol field, and all other fields except day_str are of type sequence, with the day field being an ordered sequence. The day_str field is added to provide a convenient character array representation of the date type stored in the day field. Typically, analytics operations are performed on one or more sequence fields extracted from a Quote object, which is effectively a "row" from a "result set" cursor. For example, the following code snippet iterates through the entire database, printing the values of the Quote character field symbol and sequence fields day and high:

    mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans);

    /* Iterate through all objects */
    Quote_by_sym_index_cursor(trans, &quote_cursor);
    for (rc = mco_cursor_first(trans, &quote_cursor);
        rc != MCO_S_CURSOR_END;
        rc = mco_cursor_next(trans, &quote_cursor))
    {
        /* Get current object */
        Quote_from_cursor(trans, &quote_cursor, &quote);

        /* Get symbol name */
        Quote_symbol_get(&quote, symbol, sizeof symbol);

        /* Initialize iterators */
        Quote_high_iterator(&quote, &high_iterator);
        Quote_day_iterator(&quote, &day_iterator);
        Quote_day_str_iterator(&quote, &day_str_iterator);

        while ((rc = mco_seq_next_uint4(&day_iterator, &day)) != MCO_S_CURSOR_END)
        {
            mco_seq_next_float(&high_iterator, &high);
            mco_seq_next_char(&day_str_iterator, buff);
            printf("%s[(%s)]: %f\n", symbol, buff, high);
        }
    }
    mco_trans_commit(trans);

Please use the links below to view descriptions and examples of these functions by category:

Unary Functions
Functions that take a single input sequence and produce a result sequence of values, such as abs, neg, and match.
Binary Functions
Functions that take two input sequences and produce a result sequence of values, such as add, sub, mul, div, mod, max, and min.
Comparison Functions
Functions that take two input sequences and produce a result sequence of Boolean values for the comparison operators ==, !=, >, >=, <, and <=.
Logical Functions
Functions that take two input sequences and produce a result sequence of Boolean values from the following logical operators: not, and, or, and xor.
Conversion Functions
Functions that convert values in the input sequence to the desired type or print data into the result sequence.
Collapse Functions
Functions that collapse two sequences to scalar values, such as weighted sum, weighted average, covariance, and correlation.
Conditional Functions
Functions that perform operations on one or two input sequences based on a condition, such as if, iif, filter, and filter_pos.
Manipulator Functions
Functions that perform various manipulations of input sequences.
Iterator Functions
Functions that extract values from and reset sequence iterators, such as next and reset.
Fixed-Width Character Sequences
The _char variants, their element-width rules, callback signatures, nullable I/O, and buffer lifetime.
Resources and Configuration
Reset, buffer and hash cleanup, custom allocators, binding checks, and process-wide sequence settings.
Generated Functions
Generated functions that perform operations on the database object's sequence fields, such as first, last, append, insert, delete, search, join, count, map, subseq, iterator, from_cursor, project, and store.
Top Functions
Functions that return the top n elements (or their positions) of the input sequence: top_max, top_min, top_pos_max, and top_pos_min.
RLE Functions
Functions that inspect or expand Run-Length Encoding (RLE): count, decode, and is_rle.
Grand Aggregate
Functions that take a single input sequence iterator argument and produce a scalar value in the result sequence.
Group Aggregate
Functions that split the input sequence into groups based on the values of a group_by argument.
Grid Aggregate
Functions that split the input sequence into intervals specified by the interval argument, which determines the maximum number of elements in the group.
Window Aggregate
Like the "Grid" functions illustrated above; however, the interval argument indicates the next N elements from the input sequence.
Hash Aggregate
Functions that group the resulting sequence by a grouping sequence that is not ordered.
Cumulative Aggregate
Functions that accumulate the average, sum, product, etc., of all preceding elements in the result sequence.
Miscellaneous
Functions that provide sort, rank, and histogram functionality.