Executing the Join

Examine the results of the join.

Follow these steps to run the project and then examine the results of the join:

  1. Switch the project from Release mode to Debug mode, if it isn't in Debug mode already.
  2. Click TradeInquiries in the Explorer view and then click the View Stream button (which looks like a magnifying glass) in the toolbar to open a stream viewer. Repeat these steps for TradeResults and TradesWindow and then position all the viewers so that they are visible.
  3. Start the project.
  4. Click TradeInquiries in the Explorer view, and then click Send Rows on the Debug menu. The Send Rows dialog box opens:



    In a real-world application, inquiries for a specific stock would probably arrive from some external source through an input adapter. In this activity, you will insert rows into the stream one at a time using the Sybase CEP Studio Send Rows command, which allows you to send rows into a stream immediately. Sending rows into TradeInquiries in this way will allow you to see the join results more clearly. The Send Rows dialog box includes the following elements:

    • Input Stream: Shows the stream URL of the TradeInquiries data stream into which the row will be sent. The URL identifies the stream by the host name of the computer on which the project is running, the port that Sybase CEP Engine is using, and the stream's path within the project.

    • Row Timestamp: Shows the timestamp for the row you are about to send. Since the TradeInquiries stream assigns row timestamps based on the current Sybase CEP Server time, this field displays the current Sybase CEP Server time and cannot be edited.

    • Column Values: Shows all the columns for the stream you selected (in this case, TradeInquiries only has one column) and allows you to enter values into these columns and then send them as a row into the stream.

  5. Enter "EBAY" into the Symbol box and then click Send to send a row with the value EBAY in the Symbol column into the TradeInquiries stream.
  6. Examine the stream and window viewers. (To see the results of the query more clearly, click the Disconnect All Viewers button in one of the viewers.)

    The TradeInquiries stream viewer shows the row that you sent:


    tradeinquiriesfirstactivity PNG

    The TradeResults stream viewer shows the results of the join. Note that the Timestamp column shows the timestamp of the row in the output stream, while TimeOfTrade shows the timestamp of the row in TradesWindow that met the join condition:


    traderesultsfirstactivity PNG

    The join will never produce more than one output row because the window policy only maintains a single row for each symbol, so only one row in the window can possibly match the row in the data stream. Notice that the query only publishes output when a row arrives in TradeInquiries, not when a row arrives in TradesWindow. A query containing a join cannot include more than one data stream, and the query executes only when a row arrives in that stream. Since data streams do not keep state, a row in a data stream exists only at the moment when Sybase CEP Engine processes it. Furthermore, Sybase CEP Engine processes rows sequentially. Even when two rows appear to have identical timestamps, Sybase CEP Engine always processes one of the rows first and the other one second. Therefore, rows in two data streams cannot be joined to each other, because the two data streams never contain rows at exactly the same time. Likewise, stream-to-window joins cannot execute when a row arrives in the window, because the data stream to which the window is joined is always empty at the moment when the window receives the row.

  7. Look in the TradesWindow window viewer for a row where the Symbol column has a value of EBAY and the Timestamp column has the same value as the TimeOfTrade column in the TradeResults stream viewer. This is the window row that was joined to the row you sent into the TradeInquiries stream.
  8. Examine the CCL code in the Queries tab again and note this additional information:
    • A join created with a single JOIN in the FROM clause is called an inner join. This type of join does not publish any rows that do not meet the join condition.

    • The ON clause of an inner join can be any expression that evaluates to true or false.

  9. Click the Reconnect All Viewers button to reconnect the stream and window viewers, and then click Send in the Send Rows dialog box to send another row to the input stream.
  10. Examine the viewers to confirm that the results are as you expect and then stop the project.