Operators implemented in SPL
Custom operators provide an easy way to implement custom logic without leaving SPL. Composite operators provide a convenient way to group related operators.
The Custom operator is the simplest user-defined
operator. Included in the SPL Standard Toolkit, this operator is afforded
special status by the compiler. While many operators in the SPL Standard
Toolkit allow programmers to define their own logic in onTuple
and onPunct
clauses,
the Custom operator is the only operator that allows
developers to explicitly submit tuples or punctuation. The data flow
in other operators is that the onTuple
or onPunct
clause
operates on each incoming tuple or punctuation from that stream, and
is then passed to the output
clause. Invocations
of the Custom operator can have input and output
streams, can access state variables, and call both SPL and native
functions.
While Custom operators themselves cannot be reused, a common practice is to wrap a Custom operator inside of a composite operator so that it can be reused elsewhere. (This practice is similar to the practice in languages with first-class functions to binding an anonymous function to a variable.) Also, there is no need to define an operator model for Custom operators.
Although Custom operators are the easiest way for developers to define their own operators, they cannot be used to define a fully generic operator (the technique of wrapping Custom operators inside composite operators allows type genericity, but the number of input and output ports is fixed). Additionally, expressing some computations directly in SPL can be cumbersome. Custom operators are also not appropriate when the operator must access many functions and data structures that exist only in a native language. In principle, programmers can define native SPL functions to access outside data and functions; yet, if the operator must access a large amount of outside information, the practice can become unwieldy. Finally, Custom operators are also useful as a prototyping tool. You might know that eventually the full flexibility of a primitive operator is needed, but it is easier to test the core ideas in a Custom operator.
A composite operator encapsulates an entire stream subgraph. From the outside, composites look like any other operator; they expose input and output ports, and they can have optional parameters. But on the inside, they are potentially composed of multiple operators that might be connected in a stream graph. Any type of operator can be used inside of a composite operator, including other composite operators. Composite operators are used when developers want to reuse a particular subgraph (also called a topology) in multiple places, or when they want to indicate logical divisions in a graph. Composite operators in SPL are similar to functions in procedural languages. These operators are both helpful for reusing logic and for indicating logical divisions inside applications.