This example merges three event streams of stock market trades together. A Union window unites two or more event streams using a strict policy or a loose policy. Input windows that stream events to a Union window must have the same schema.
This example also demonstrates the use of connector orchestration.
For more information about how to install and use example projects, see Using the Examples.
The stockpricelist1.csv, stockpricelist2.csv, and stockpricelist3.csv files contain lists of stock prices.
The following figure shows the diagram of the project:
- The sourceWindow_01 window is a Source window. This is where a list of stock prices from the
stockpricelist1.csv
file and a list of stock prices thestockpricelist2.csv
file enter the model. - The sourceWindow_01 window is a Source window. This is where a list of stock prices from the
stockpricelist3.csv
file enters the model. - The unionWindow window is a Union window. This is where the multiple lists of stock prices are merged into one list. This window also writes the results of the merge to the
output.csv
file.
Explore the settings for the sourceWindow_01 window:
- Open the project in SAS Event Stream Processing Studio and select the sourceWindow_01 window.
- To examine the window's output schema, on the right toolbar, click . Observe the following fields:
ID
: This field is the stock trade's ID, which is also selected as the key field.symbol
: This field is the stock symbol. A stock symbol is a series of letters that are assigned to a security for trading purposes.price
: This field is the stock price.
- Click .
- Expand Input Data (Publisher) Connectors. Observe that there are two publisher connectors, connected to stockpricelist1.csv and stockpricelist2.csv.
Later in these steps you observe how connector orchestration affects the order in which connectors are executed.
Explore the settings for the sourceWindow_02 window:
- Select the sourceWindow_02 window in the workspace.
- Click . Observe that the output schema is the same as for the sourceWindow_01 window. Input windows that stream events to a Union window must have the same schema.
- Click .
- Expand Input Data (Publisher) Connectors. Observe that there is a publisher connector, connected to stockpricelist3.csv.
The unionWindow window merges multiple lists of stock prices into one list.
Explore the settings for the unionWindow window:
- Select the unionWindow window.
- In the right pane, expand State. Observe that the window is stateful.
- Expand Union. Observe that the strict policy is used for key merging. Because this window is stateful and the strict policy is used, Inserts with duplicated keys and Deletes with non-existing keys generate an error and are processed as bad records. The input files in this example do not contain such events. For more information about how different combinations of settings in the State and Union sections affect events, see SAS Help Center: Using Union Windows.
- Expand Subscriber Connectors. Observe that there is a subscriber connector that writes output to a file called
output.csv
.
- Click on the main toolbar to view project properties.
- In the right pane, expand Connector Orchestration.
- In the Connector groups table, observe that four connector groups are present. Open each connector group to view the connectors related to that group. For example, the
CG_sub
group relates to a subscriber connector in the unionWindow window and its target state isRunning
. - In the Dependency rules table, observe the dependency settings. For example, observe that publisher connectors are executed in the following order:
- The first publisher connector in sourceWindow_01. This connector relates to stockpricelist1.csv.
- The publisher connector in sourceWindow_02. This connector relates to stockpricelist3.csv.
- The second publisher in sourceWindow_01. This connector relates to stockpricelist2.csv.
If you do not use the Install example button in SAS Event Stream Processing Studio, note that this project includes connector orchestration and as a result, it is recommended that you do not use the Publish button in SAS Event Stream Processing Studio's test mode to publish events from CSV files to the Source windows. Instead, adjust the connectors in the project:
- Edit the publisher connectors in the sourceWindow_01 and sourceWindow_02 windows so that they refer to the location in your system where you placed the CSV files. For more information, see SAS Help Center: Configure a File and Socket Connector.
- Edit the subscriber connector in the unionWindow window so that it refers to a location where the output file can be written. Ensure that the user who tests the project has Write access to that directory.
When you test the project, the results for each window appear on separate tabs:
- The sourceWindow_01 tab displays the first event stream.
- The sourceWindow_02 tab displays the second event stream.
- The unionWindow tab displays the unified event stream.
The following figure shows the results for the unionWindow tab:
For more information, see SAS Help Center: Using Union Windows.