The C++ class Sequence provides a set of analytics methods that operate on
sequences. These methods inherit functionality from the specialized C API typemco_seq_iterator_tas the "handle" to manage sequence fields. The categories below link to pages describing the methods in detail. The examples in 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_symon fieldsymboland all of the other fields exceptday_strare of type sequence where the fielddayis an ordered sequence. Theday_strfield is added to provide a convenient character array representation of the date type stored in fieldday. 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 out the values of the Quote character fieldsymboland sequence fieldsdayandhigh:mco_trans_h trans; mco_date day; mco_cursor_t quote_cursor; Quote quote; MCO_RET rc; rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans); if ( MCO_S_OK == rc ) { /* Iterate through all Quote objects */ Quote::by_sym::cursor(trans, "e_cursor); for (rc = mco_cursor_first(trans, "e_cursor); rc != MCO_S_CURSOR_END; rc = mco_cursor_next(trans, "e_cursor)) { /* Get current object */ quote.from_cursor(trans, "e_cursor); /* Initialize iterators */ Sequence<uint4> day_iterator = quote.day_iterator(); Sequence<float> high_iterator = quote.high_iterator(); Sequence< Char<15> > day_str_iterator = quote.day_str_iterator(); /* Iterate sequence fields */ while (day_iterator.next(day)) { Char<MAX_SYMBOL_LEN> symbol = quote.symbol; Char<15> day_str = ++day_str_iterator; printf("%s[%u(%s)]: %f\n", (char*)symbol, day, (char*)day_str, ++high_iterator); } } mco_trans_commit(trans); }Please use the links below to view descriptions and examples of these methods by category:
Methods that take a single input sequence and produce a result sequence of values, such as abs, neg, match.Methods that take two input sequences and produce a result sequence of values, such as add, sub, mul, div, mod, max, min.Methods that take two input sequences and produce a result sequence of Boolean values for the comparison operators: ==, !=, >, >=, <, <=.Methods that take two input sequences and produce a result sequence of Boolean values using the following logical operators: not, and, or, xor.Methods that collapse two sequences to scalar values, such as weighted sum, weighted average, covariance, correlation.Methods that perform operations on one or two input sequences based on a condition, such as if, cond, filter, filter_pos.Methods that perform various manipulations of input sequences.Methods that extract values from and reset sequence iterators, such as next, reset.Methods that return the topnelements (or their positions) of the input sequence: top_max, top_min, top_pos_max, top_pos_min.Methods that perform run-length encoding (RLE) operations: count, decode, is_rle.Methods that take a single input sequence iterator argument and produce a scalar value in the result sequence.Methods that split the input sequence into groups based on the values of agroup_byargument.Methods that split the input sequence into intervals specified by the interval argument, which determines the maximum number of elements in the group.Methods that work like the Grid methods, but whose interval argument indicates the nextNelements from the input sequence.Methods that group the resulting sequence by a grouping sequence that is not ordered.Methods that accumulate the average, sum, product, etc. of all preceding elements in the result sequence.Methods that provide sort, rank, and histogram functionality.