@spl.filter

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

Decorator to create a stateful or stateless SPL filter operator from a Python callable class or function. A filter operator has a single input port and one mandatory output port and one optional output port. For each SPL tuple arriving on the input port the decorated Python callable is called passing the tuple. If the return value evaluates to true (as defined by Python) then the same tuple is submitted to the first (mandatory) output port. If the return value evaluates to false then the same tuple is submitted to the second (optional) output port if it exists otherwise it is discarded.

A filter operator is punctuation preserving.

Decorated callable class

When a Python callable class is decorated with @spl.filter a stateful SPL filter operator is created.

When the SPL operator is initialized __init__ is called to create an instance of the class. For each tuple arriving at the input port __call__ is called and its return value is used to filter the tuple.

If the class has instance fields then they are the state of the operator and are private to each invocation of the operator and maintained across calls to its __call__ function.

Decorated function

When a Python function is decorated with @spl.filter a stateless SPL filter operator is created.

For each tuple arriving at the input port the decorated function is called and its return value is used to filter the tuple.