This topic describes how to use the Pattern operator to define pattern queries in EventFlow applications. In a StreamSQL application use the SELECT Statement.
After adding a Pattern operator to your EventFlow (for example, by dragging a Pattern operator icon from the palette), complete the fields in each of the tabs, as described in the sections that follow.
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.
Use this tab to define your query's template and window, and optionally, a predicate.
- Number of input ports
-
Specify one port for each input stream that you want to match on.
- Template
-
Enter an expression that matches pairs of named streams (or subqueries that evaluate to stream names), using patterns to specify how the pairs are compared.
To identify a stream, use the operator's input port designation in this format:
input
nFor example, if your operator has one port, refer to its input stream as
input1; if it has two ports, the first port (the top one in the EventFlow) isinput1and the second (lower) port isinput2. To verify the name of a stream, toggle the
Expressions Pane button
and open the Streams tab.
See the Patterns section in StreamBase Pattern Matching Language for the available template patterns.
- Window Type
-
Choose the type of window you want to determine the terminating event for the query. One of the following:
- Time
-
The window closes and the query operation terminates when the time specified in the Window Size field has elapsed.
- Value
-
The window closes when a range of values in the specified Order Field exceeds the specified Window Size.
- Order Field
-
For value-based windows only, the field that will be compared across all streams. The order field must be a top-level numeric or timestamp field, as described in StreamBase Pattern Matching Language.
- Window Size
-
-
For time-based windows, specify the time in seconds. For example, a window size of 5 means that the last tuple must arrive within 5 seconds after the first tuple arrives.
-
For value-based windows, enter a value appropriate for the order field. For example, a window size of 5 for an int field means that the window will close when the range of values of that field, across all streams, equals or exceeds 5.
-
- Predicate
-
Optionally, enter a WHERE clause that further constrains the result of your query.
The following screens show an application with a Pattern operator, and the operator's Properties view open at the Pattern Settings tab:
The Output Settings tab allows you to specify the field names from input streams to include in the output, and what to name them. Specify output fields using one of the two Output options:
-
Choose the All input fields option to preload existing fields in the input stream. By default, properties are set to pass all input fields through to the output stream; you only have to specify the changes that you want to make.
-
Choose explicitly specified fields to add the output fields manually. For each field, specify the name that you want to appear in the output field, and an expression, based on the input to the operator, that resolves to the value that you want in the field.
Note
When you reference an input field in an expression, use the input port notation to identify the stream that it comes from. That is, add a prefix using the same notation described for the template in the Pattern Settings tab. For example:
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.
- Run this component in a separate thread
-
This option causes the server to process the component's requests concurrently with other processing in the application. You can distribute the processing of the threads automatically across multiple processors on an SMP machine.
If this is a compute-intensive component and you know that it can run without data dependencies on other components in the StreamBase application, you may be able to improve performance by enabling this option.
Caution
These features are not suitable for every application. For details, see Execution Order, Concurrency, and Parallelism. It includes important guidelines for the use of these features.
- Run in parallel threads
-
If you checked the first option, you can also choose this option, which causes the server to run multiple instances of this component. That is, each instance runs in its own thread. At run time, tuples are dispatched to particular instances based on the Key Expression value (which must evaluate to an int).
A Pattern operator will assign a value of null to a
field whose expression evaluates to null. That is, if the evaluation of the field
results in a NullValueException, then the value of the
field will be null. For more information, see Using Nulls.
