@spl.pipe

Toolkits > com.ibm.streamsx.topology 2.1.0 > com.ibm.streamsx.topology.python > Creating SPL Operators from Python code > @spl.pipe

Decorator to create a stateless SPL map operator from a Python function. When a Python function is decorated with @spl.pipe a stateless SPL operator is created with a single input port and single output port. For each input tuple the function is called, and its return value is used to submit zero or more tuples on the output port.

When the function returns a tuple containing less values than attributes in the SPL output schema then the remaining attributes are copied from the input tuple if a matching attribute is found, otherwise they are set to the SPL default value.

A pipe operator is punctuation preserving.

@spl.map is preferred to @spl.pipe.

Examples

Simple Noop pipe operator that passes the input SPL tuple onto its output using a variable argument.

@spl.pipe
def Noop(*tuple):
  "Pass the tuple along without any change"
  return tuple
Simple filter, note that no return statement is equivalent to returning None:
@spl.pipe
def SimpleFilter(a,b):
  "Filter tuples only allowing output if the first attribute is less than the second. Returns the sum of the first two attributes."
  if (a < b):
     return a+b,
Demonstration of returning multiple tuples as a list.
@spl.pipe
def ReturnList(a,b,c):
  "Demonstrate returning a list of values, each value is submitted as an SPL tuple" 
  return [(a+1,b+1,c+1),(a+2,b+2,c+2),(a+3,b+3,c+3),(a+4,b+4,c+4)]