Merge Operator Sample

This sample uses a Merge operator to interlace trades from a Reuters and a Comstock feed, based on trade time. The input streams contain the fields Symbol, Volume, PricePS (per share), Time, and FeedID.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, click FileLoad StreamBase Sample.

  • Select operator from the Applications list.

  • Click OK.

StreamBase Studio creates a single project for the operator samples.

Sample Location

By default, the sample files are installed in:

  • On Windows: C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\operator

  • On UNIX: /opt/streambase/sample/operator

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace. StreamBase Systems recommends that you use the workspace copy of the sample, especially on UNIX, where you may not have write access to /opt/streambase. In the default installation, the path to this sample in your Studio workspace is:

UNIX:       
  ~/streambase-studio-n.m-workspace/sample_operator
Windows XP:
  C:\Documents and Settings\username\My Documents\StreamBase Studio n.m Workspace\
      sample_operator
Windows Vista:
  C:\Users\username\Documents\StreamBase Studio n.m Workspace\
      sample_operator

Running the Merge Sample

Running Merge.sbapp in StreamBase Studio

  1. In the Package Explorer, double-click to open the Merge.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. In the Application Output view, select the MergeOut output stream. No output is displayed at this point, but the dequeuer is prepared to receive output. This view eventually shows the output of the application.

  4. In the Manual Input view, select the ComstockIn input stream

  5. Enter amat, 100, 23, 10, and 0 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe that no output is displayed yet in the Application Output view.

  6. Enter amat, 23, 10, and 1 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe that no output is displayed yet in the Application Output view.

  7. Select the ReutersIn input stream.

  8. Enter intc, 200, 21, 11, and 0 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe this data appears in the Application Output view:

    Symbol=amat, Volume=100, PricePS=23.0, Time=10, FeedID=0
    
  9. Enter intc, 200, 21, 11, and 1 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe this data appears in the Application Output view.

    Symbol=amat, Volume=100, PricePS=23.0, Time=10, FeedID=1
    
  10. Enter msft, 100, 40, 12, and 0 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe that no further output is displayed yet in the Application Output view.

  11. Enter msft, 100, 40, 12, and 1 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe that no further output is displayed yet in the Application Output view.

  12. Select the ComstockIn input stream.

  13. Enter amat, 300, 24, 15, and 0 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe this data appears in the Application Output view.

    Symbol=intc, Volume=200, PricePS=21.0, Time=11, FeedID=0
    Symbol=msft, Volume=100, PricePS=40.0, Time=12, FeedID=0
    
  14. Enter amat, 300, 24, 15, and 1 in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.

    Click Send Data, and observe this data appears in the Application Output view.

    Symbol=intc, Volume=200, PricePS=21.0, Time=11, FeedID=1
    Symbol=msft, Volume=100, PricePS=40.0, Time=12, FeedID=1
    
  15. When done, press F9 or click the Stop Running Application button.

Running Merge.sbapp in Terminal Windows

This section describes how to run the sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  2. In window 1, type:

    sbd Merge.sbapp

    The window shows notice[StreamBaseServer] listening on port 10000.

  3. In window 2, type:

    sbc dequeue MergeOut

    No output is displayed at this point, but the dequeuer is prepared to receive output. This window eventually shows the output of the application.

  4. In window 3, type:

    sbc enqueue

    The sbc command is now waiting for keyboard input. Type: ComstockIn,amat,100,23,10,0

    No output is displayed yet in the dequeue window.

  5. Type:

    ComstockIn,amat,100,23,10,1.

    No output is displayed yet in the dequeue window.

  6. Type:

    ReutersIn,intc,200,21,11,0.

    Observe this line in the dequeue window:

    amat,100,23.000000,10,0.

  7. Type:

    ReutersIn,intc,200,21,11,1.

    Observe this line in the dequeue window:

    amat,100,23.000000,10,1.

  8. Type:

    ReutersIn,msft,100,40,12,0.

    No further output is displayed yet in the dequeue window.

  9. Type:

    ReutersIn,msft,100,40,12,1.

    No further output is displayed yet in the dequeue window.

  10. Type:

    ComstockIn,amat,300,24,15,0.

    Observe these lines in the dequeue window:

    intc,200,21.000000,11,0
    msft,100,40.000000,12,0
    
  11. Type:

    ComstockIn,amat,300,24,15,1.

    Observe these lines in the dequeue window:

    intc,200,21.000000,11,1
    msft,100,40.000000,12,1
    
  12. In window 2, type: Ctrl-Z (Windows) or Ctrl-D (UNIX) to exit the sbc session.

  13. In window 3, type the following command to terminate the server and dequeuer:

    sbadmin shutdown

Back to Top ^

How We Created the Merge Operator Sample

  1. Launched StreamBase Studio

  2. Created (or subsequently used) the "sample_operator" project.

  3. From the top menu, in the SB Authoring perspective, selected File > New > EventFlow Application. Selected the sample_operator project and entered Merge for the diagram name.

  4. Created an input stream

    • Dragged an input stream from the palette to the canvas.

    • Clicked it on the canvas, which invoked the Input Stream Properties dialog window.

    • On the General tab, Name: ReutersIn

    • On the Edit Schema tab, added:

      • Field Name: Symbol, Type: string, Size: 5

      • Field Name: Volume, Type: int

      • Field Name: PricePS, Type: double

      • Field Name: Time, Type: int

      • Field Name: FeedID, Type: int

  5. Created another input stream

    • Dragged an input stream from the palette to the canvas.

    • Clicked it on the canvas, which invoked the Input Stream Properties dialog window.

    • On the General tab, Name: ComstockIn

    • On the Edit Schema tab, clicked the Copy Schema icon in the upper right corner. On the Copy Schema from Existing Component dialog, we selected:

      Project: sample_operator

      Application: Merge

      Copy schema from: ReutersIn Input Stream

  6. Created a Merge operator:

    • Dragged a Merge operator from the palette to the canvas.

    • On the General tab, Name: myMerge

    • Connected the ReutersIn and ComstockIn input streams to the myMerge operator.

  7. Set up the Merge operator:

    • On the Merge Settings tab, Field by which to merge tuples: Time

    • On the Group Options tab, Expression 1: FeedID

  8. Created an output stream:

    • Dragged an output stream from the palette to the canvas.

    • On the General tab, Name: MergeOut

    • Connected the myMerge operator to the MergeOut output stream.

Back to Top ^