Analytics Functions

eXtremeDB provides a library of C analytics functions that operate on sequences. These functions use the specialized type mco_seq_iterator_t as the "handle" to manage sequence fields. They all have a result sequence iterator as their first argument that receives the result of the function after applying the other function arguments.

These functions operate on specific sequence types. For example the binary function mco_seq_add_int4() will add two sequences with elements of type int4. To simplify the documentation we use the term TYPE as a placeholder for one of the following actual types:

int1

Signed one-byte integer

int2 Signed two-byte integer
int4 Signed four-byte integer
int8 Signed eight-byte integer
uint1

Unsigned one-byte integer

uint2 Unsigned two-byte integer
uint4 Unsigned four-byte integer
uint8 Unsigned eight-byte integer
float Four-byte floating point
double Eight-byte floating point
datetime Eight-byte datetime

So the function signature mco_seq_add_TYPE() refers to the sequence "add" function mco_seq_add_int1(), mco_seq_add_int2(), .., mco_seq_add_double(), or mco_seq_add_datetime(); i.e. for elements of any of the above types.

To document the operational specifics and usage, these functions are divided into "categories". Please see the page Analytics Functions by Category to view explanations and examples of the individual functions.

SQL Equivalents

It is useful to note that all of the public C sequence functions have SQL equivalents. These SQL equivalents return the result sequence which makes it possible to express a "pipeline" of SQL functions in a more compact form. For example the following pipeline of four C functions calls adjusts historical closing prices for the effect of splits. (To understand the code snippet, assume that sequences trade_date and closing_price contain the time series of trade dates paired with closing prices, and split_date the sequence of split dates for the trades of interest - for this example "IBM".)

 
    mco_seq_iterator_t split;
    mco_seq_iterator_t prd_split_factor;
    mco_seq_iterator_t price_adjustment;
    mco_seq_iterator_t trade_date;
    mco_seq_iterator_t split_date;
    mco_seq_iterator_t closing_price;
    mco_seq_iterator_t adjusted_price;
    ...
     
    rc = mco_seq_cum_agg_prd_float(&prd_split_factor, &split);
    mco_seq_reverse_double(&rev_prd_split_factor, &prd_split_factor);
    mco_seq_stretch_uint4_double(&price_adjustment, &trade_date, &split_date, &rev_prd_split_factor, 1.0);
    mco_seq_mul_double(&adjusted_price, &closing_price, &price_adjustment);
 

The same result sequence can be calculated using the following SQL select statement:

 
    SELECT seq_mul(ClosePrice, seq_stretch(TradeDate, SplitDate,
            seq_reverse(seq_cum_agg_prd(SplitFactor)))) as AdjustedClose
    FROM Security
    WHERE Security.Symbol = ‘IBM’
 

Note the relationship between the functions in SQL and in the C API: The inner-most nested function in the select statement is the first sequence function called in the series of C API functions. The next most nested function, seq_reverse(), is the second function called in the C API, and so on.

Null Values in Sequences

The generated functions classname_fieldname_append_nullable() and classname_fieldname_insert_nullable() can be used to insert null values into sequences.

The functions mco_seq_get_nullable_TYPE() and mco_seq_unget_nullable_TYPE() can be used to convert sequences to nullable arrays and vice versa.