The Sequence operator generates a new sequence value for each tuple that passes through the operator, based on the current value of a sequence identifier and an updating expression. You can use the sequence values downstream as required by your application, such as to generate unique identifiers for tuples or to specify expressions that you want to use as keywords for query tables.
The Sequence operator adds a field to the schema definition for its incoming stream, which is otherwise passed through unmodified. The newly added field contains values that StreamBase generates according to a sequence definition you specify as part of the operator. The settings for the operator include a name for the output field to be added, a name for the sequence variable to be used to hold the most recent value of the sequence, and an expression to use to calculate each value in the sequence.
To specify a Sequence operator, drag it from the Operators drawer in Studio's Palette view to the EventFlow canvas. More than one downstream operator can share the Sequence operator's added field by dragging more than one arc from the Sequence operator's output stream.
You can designate two or more Sequence operators to share the same Sequence ID state by specifying the same Sequence ID for those operators. This can be useful in several cases:
-
You can add sequence values generated from the same Sequence ID to the tuples of more than one incoming stream as a way of coordinating two related but separate streams.
-
You can use one of a pair of Sequence operators to reset the value to zero (or to another point) when certain processing conditions are met.
For example, to start a Sequence operator counting from 100:
-
Link two Sequence operators with the same Sequence ID.
-
Set the update expression for the first Sequence operator to
.100 -
Use the Once adapter to initialize the Sequence ID value by connecting the output of the Once adapter to the input of the first Sequence operator.
-
Use only the second Sequence operator to append to an incoming stream, which now begins sequencing with 100.
-
You can also implement a sequence operator in StreamSQL using dynamic variables, as described on Using Dynamic Variables to Implement a Sequence Operator.
Name: Every application component must have a unique name. Use this field to specify or change the component's name. The name must contain only alphabetic characters, numbers, and underscores, and no hyphens or other special characters. The first character must be alphabetic or an underscore.
Enable Error Output Port: Check this box to add an Error Port to this component. In the EventFlow canvas, the Error Port shows as a red output port, always the last port for the component. See Using Error Ports and Error Streams to learn about Error Ports.
Description: Optionally, enter a description to briefly describe the component's purpose and function. In the EventFlow canvas, you can see the description by pressing Ctrl while the component's tooltip is displayed.
In the Properties view for a Sequence operator, the Settings tab requires the following parameters:
| Parameter | Description |
|---|---|
| Output field name |
Name of the field added to the output tuple to contain the generated sequence
value. The type of the added field is long, and
its default initial value is 0.
|
| Sequence ID |
Name of the variable that holds the most recent value of the sequence. The
scope of the Sequence ID variable is the containing module. The default name
is the operator name plus id.
You can specify the same Sequence ID for more than one Sequence operator in the same module, in which case all such operators share the same state. See Linking Sequence Operators for a discussion of this feature. |
| Update Expression | A StreamBase expression for updating the value of the Sequence ID. The default value for this expression increments the Sequence ID field by 1. |
For example, say the field name for the output is seqid,
the Sequence ID is id, and the update expression is
id+10. In this case, StreamBase increases
the value of id by 10 in the seqid field for each successive incoming tuple.
The Dynamic Variables tab allows you to define variables for this operator that can then be used in one of its expressions. A dynamic variable can be updated by any input stream or output stream in your application. For more information, see Using Dynamic Variables.
