The manipulator Java SequenceIterator methods take a variety of sequence arguments and produce result sequences as described below:
SequenceIterator parse(String val, Sequence.Type type)Constructs a sequence from the string literalvalof thetypespecified; for example, "{1.0, -1.1, 0}".SequenceIterator map(SequenceIterator positions)Extracts from the underlying sequence the elements with positions specified in the provided sequence. Thepositionsshould be provided in ascending order (they are intended to be obtained using methodsfilterPos()ortopPos()).SequenceIterator[] tee()Forks the sequence iterator; i.e., creates two instances of iterators for the same sequence. These iterators should be traversed together (used in the same expression). Returns an array with the pair of forked iterators.SequenceIterator constant(double val, Sequence.Type type)Constructs a sequence of thetypespecified with the double constant valueval.SequenceIterator constant(long val, Sequence.Type type)Constructs a sequence of thetypespecified with the long constant valueval.SequenceIterator constant(byte[] val, Sequence.Type type)Constructs a sequence of thetypespecified with the byte array constant valueval.SequenceIterator concat(SequenceIterator tail)Concatenates the two sequences: e.g., for sequence{1,2,3},concat({4,5})would produce result sequence{1,2,3,4,5}. Returns the result sequence iterator.SequenceIterator cat(SequenceIterator other)Concatenates the two sequences: e.g., for sequence{'a','b','c'},cat({'x','y','z'})would produce result sequence{'ax', 'by', 'cz'}. Returns the result sequence iterator.SequenceIterator unique()Copies to the result sequence only the unique elements in the ordered sequence input by "collapsing duplicates".SequenceIterator normalize()Returns the normalized input sequence; i.e., divides each sequence element by the square root of the sum of squares of all elements.SequenceIterator thin(long origin, long step)Copies the input sequence to result, selecting elements with the specified origin and step.SequenceIterator limit(long from, long till)Copies to the result sequence the subsequence from the input using sequence positions from and till.SequenceIterator reverse()Returns in result the sequence in reverse order.SequenceIterator diff()Returns in result the differences between pairs of sequence elements in input.SequenceIterator trend()Returns in result the value 1, -1 or 0 determined by comparing pairs of element values to determine if the values are trending up or down (see page SQL Sequence Trend Function for a detailed description).SequenceIterator repeat(int count)Returns in result each element of the input sequence repeated n_times times.SequenceIterator stretch(SequenceIterator ts1, SequenceIterator ts2, long filler)
also
SequenceIterator stretch(SequenceIterator ts1, SequenceIterator ts2, double filler)
Returns in result the elements of the values sequence stretched to the length of the ts1 sequence by repeating the elements of values while the corresponding timestamp in sequence ts2 is larger than the timestamp from ts1. Uses the filler values for elements where the corresponding timestamp in sequence ts2 is less than the timestamp from ts1.
For example, assume ts1 =
{1,2,3,4,5}, ts2 ={2,4}, values ={1.1,2.2}and filler =1.0. With these input sequences the result will be{1.1,2.2,2.2,1.0,1.0}.(This method can be used to calculate a split-adjusted price where it is necessary to revert time series of splits, calculate the cumulative product and multiply by the price.)
SequenceIterator stretch0(SequenceIterator ts1, SequenceIterator ts2, long filler)
also
SequenceIterator stretch0(SequenceIterator ts1, SequenceIterator ts2, double filler)
Returns in result the elements of the values and filler sequences by injecting the elements of values where the corresponding timestamps in sequence ts2 match the timestamp from ts1. Uses the filler values for elements where the timestamp in sequence ts2 has no matching timestamp in ts1. For example, assume ts1 ={1,2,3,5}, ts2 ={2,3,4}, values ={1.1,1.2,1.3}and filler =0.0. With these input sequences the result will be{0.0,1.1,1.2,1.3,0.0}.SequenceIterator asofJoin(SequenceIterator ts1, SequenceIterator ts2)Returns in result the elements of the values sequence corresponding to the timestamp of ts2 closest to the timestamp of ts1. For example, assume ts1 ={4,9}, ts2 ={1,3,6,10}, and values ={0.1,0.3,0.6,1.0}. With these input sequences the result will be{0.3,1.0}.SequenceIterator cast(Sequence.Type type)Returns in result the sequence converted to the specifiedtype.SequenceIterator cross(int firstCrossDirection)Returns in result the positions in the input sequence where it crosses zero. If the integer argument first_cross_direction is positive, then the result sequence starts with the first cross above zero; if negative, it starts with a cross below zero; if first_cross_direction is zero, then it doesn't matter, i.e., the first cross can be above or below zero.SequenceIterator extrema(int firstExtremum)Returns in result the positions of extrema (local minima and maxima) in the input sequence. If the integer argument first_extremum is positive, then the result sequence starts with the first local maximum; if negative, it starts with a local minimum; if first_extremum is zero, then it doesn't matter.
SequenceIterator hash()also
SequenceIterator hash(SequenceIterator other)
Calculates the 32-bit hash code for each value of the input sequence and produces a result sequence of typeuint4. This function can combine the hash with a previously calculated hash for another sequence (if theotherargument is not null).Example
Following is an example code snippet demonstrating sequence manipulator methods:
public static void windowAggregate(Connection con) { con.startTransaction(Database.TransactionType.ReadOnly); Cursor<Quote> cursor = new Cursor<Quote>(con, Quote.class, "symbol"); for (Quote quote : cursor) { SequenceIterator cross = quote.day.map(quote.close.iterator(). windowAggAvg(20).sub(quote.close.iterator(). windowAggAvg(5)).cross(1)); ... } con.commitTransaction(); }