Contents
This sample uses a Join operator to combine trades from a Reuters and a Comstock feed,
where the stocks are the same and the price per share is greater than or equal to $1,
over a period of 60 seconds. The input streams contain the fields Symbol, PricePS_R (per share), and
Time.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click → .
-
Select operator from the Applications list.
-
Click OK.
StreamBase Studio creates a single project for the operator samples.
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 Studion.mWorkspace\ sample_operator Windows Vista: C:\Users\username\Documents\StreamBase Studion.mWorkspace\ sample_operator
-
In the Package Explorer, double-click to open the
Join.sbappapplication. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run button. This opens the SB
Test/Debug perspective and starts the application.
-
In the Application Output view, select the
JoinOutoutput stream. No output is displayed at this point, but the dequeuer is prepared to receive output. This view will eventually show the output of the application. -
In the Manual Input view, select the
ReutersIninput stream. -
Enter
intc,23.0, and10in the Symbol_R, PricePS_R, and Time_R fields, respectively. -
Click , and observe that no output is displayed yet in the Application Output view.
-
Select the
ComstockIninput stream. -
Enter
intc,23.5, and20in the Symbol_C, PricePS_C, and Time_C fields, respectively. -
Click , and observe that no output is displayed yet in the Application Output view.
-
Select the
ReutersIninput stream. -
Enter
intc,24.5, and30in the Symbol_R, PricePS_R, and Time_R fields, respectively. -
Click , and observe this data appears in the Application Output view
DeltaPricePS=1.0, PricePS_R=24.5, PricePS_C=23.5, Time_R=30
-
Select the
ComstockIninput stream. -
Enter
amat,34.5, and40in the Symbol_C, PricePS_C, and Time_C fields, respectively. -
Click , and observe that no further output is displayed yet in the Application Output view.
-
Enter
intc,26.5, and50in the Symbol_C, PricePS_C, and Time_C fields, respectively. -
Click , and observe this data appears in the Application Output view
DeltaPricePS=-3.5, PricePS_R=23.0, PricePS_C=26.5, Time_R=10 DeltaPricePS=-2.0, PricePS_R=24.5, PricePS_C=26.5, Time_R=30
-
Select the
ReutersIninput stream. -
Enter
amat,32.5, and60in the Symbol_R, PricePS_R, and Time_R fields, respectively -
Click , and observe this data appears in the Application Output view
DeltaPricePS=-2.0, PricePS_R=32.5, PricePS_C=34.5, Time_R=60
-
Select the
ComstockIninput stream. -
Enter
intc,27.5, and100in the Symbol_C, PricePS_C, and Time_C fields, respectively. -
Click , and observe that no further output is displayed yet in the Application Output view.
-
When done, press F9 or click the
Stop Running Application button.
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.
-
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.
-
In window 1, enter:
sbd Join.sbappA message indicates that the StreamBase Server is listening and waiting for tuples.
-
In window 2, enter:
sbc dequeue JoinOutNo output is displayed at this point, but the dequeuer is prepared to receive output. This window will eventually show the output of the application.
-
In window 3, enter:
sbc enqueue ReutersInThe sbc command is now awaiting keyboard input in window 3.
-
Enter these two lines, pressing Enter after each:
intc, 23.0, 10intc, 23.5, 20No output is displayed yet in the dequeue window.
-
Enter a new line:
intc, 24.5, 30Observe this output in the dequeue window:
1,24.5,23.5,30
-
Enter:
amat, 34.5, 40No further output is displayed yet in the dequeue window.
-
Enter:
intc, 26.5, 50Observe this output in the dequeue window:
-3.5,23,26.5,10 -2,24.5,26.5,30
-
Enter:
amat, 32.5, 60Observe this output in the dequeue window:
-2,32.5,34.5,60
-
Enter:
intc, 27.5, 100No output is displayed yet in the dequeue window.
-
In window 2, type: Ctrl-Z (Windows) or Ctrl-D (UNIX) to exit the sbc session.
-
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
-
Launched StreamBase Studio.
-
Created (or subsequently used) the sample_operator project.
-
From the top menu, in the SB Authoring perspective, selected → → . Selected the
sample_operatorproject, enteredJoinfor the file name. -
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 view.
-
On the General tab, Name:
ReutersIn -
On the Edit Schema tab, added
-
Field Name:
Symbol_R, Type:string, Size:5 -
Field Name:
PricePS_R, Type:double -
Field Name:
Time_R, Type:int
-
-
-
Created a second input stream:
-
Dragged an input stream from the palette to the canvas.
-
Clicked it on the canvas, which invoked the Input Stream Properties view.
-
On the General tab, Name:
ComstockIn -
On the Edit Schema tab, added
-
Field Name:
Symbol_C, Type:string, Size:5 -
Field Name:
PricePS_C, Type:double -
Field Name:
Time_C, Type:int
-
-
-
Created a Join operator:
-
Dragged a Join operator from the palette to the canvas.
-
On the General tab, Name:
Join -
Connected the
ReutersIninput stream to the top input port of theJoinoperator and theComstockIninput stream to the bottom input port.
-
-
Set up the
Joinoperator:-
On the Join Settings tab:
-
Join by: values
-
Tuple timeout: We did not enter a value in this sample. The default is no timeout.
The tuple timeout is the maximum time that a tuple can stay in the window. When the time expires, the tuple is flushed from the buffer.
-
Predict:
Symbol_R ==Symbol_C && abs(PricePS_R - PricePS_C) >= 1.0
-
-
On the Value-based Settings tab:
-
Ordering field:
-
First Stream:
Time_R -
Second Stream:
Time_CEach input stream has one window that contains a set of tuples based on the values of the two "Ordering" fields. When a tuple arrives in either buffer with a value that is within the range of one of the tuples in the other window (as reflected in the "Ordering field"), any desired calculations will take place, and a tuple containing the results and other fields of interest will be emitted. Note that a tuple may be matched more than once. Tuples are dropped from their respective windows when there can be no more tuples that will join with them on the other input stream, or when a tuple from the opposite stream goes into the matching window that is beyond the Ordering field value. (The other option is Join by: tuples.)
-
-
Join Range:
-
First Stream Ordering Field -
60 -
First Stream Ordering Field +
60
In this sample, we set the range values to 60 seconds. That is, tuples are considered matched when their "Ordering" fields are within 60 seconds of each other.
-
-
-
On the Output Settings tab, selected the explicitly specified fields option, and added:
Output Field Name:
DeltaPricePSExpression:PricePS_R - PricePS_COutput Field Name:
PricePS_RExpression:PricePS_ROutput Field Name:
PricePS_CExpression:PricePS_COutput Field Name:
Time_RExpression:Time_RThis operator outputs the four fields above. Note that new fields may be added as functions of the other fields (as done, for example, by
DeltaPricePS)
-
-
Created an output stream:
-
Dragged an output stream from the palette to the canvas.
-
On the General tab, Name:
JoinOut -
Connected the
Joinoperator to theJoinOutoutput stream.
-
