Contents
This sample contains a Query Table data construct that stores information about member companies comprising the NASDAQ-100 stock index. Each company was assigned an arbitrary color value from the choices {red, yellow, blue}, stored in the table's Color field.
Also see the Sequence operator sample, which illustrates how to use unique IDs generated by a Sequence operator as a Query Table's primary index.
This sample includes the following Query operators:
Query Operator Name | Description |
---|---|
LoadNasdaq100Table | Accepts input from a CSV File Reader adapter that reads from a CSV data file. The adapter runs automatically when the sample starts to automatically load the Query Table. |
ReadNasdaq100Table | Accepts a stream with a single string field named Symbol; the Symbol field can be entered with any case letters. Enter a stock symbol to return that symbol's entry in the Query Table, if the symbol is a member of the NASDAQ-100, or an error message if not. |
QueryPriceColor | Accepts a stream with fields MaxPrice (double) and Color (string). Enter values to return one tuple for each stock that matches the specified color and whose price is less than or equal to the specified price. |
QueryPrice | Accepts a stream with maximum and minimum price values. Enter a stock price range to return a tuple for each stock whose price falls within the specified range. |
UpdatePriceQuery | Accepts a stream with Symbol and Price values; the Symbol field can be entered with any case letters. If a row matching the specified Symbol is found in the Query Table, its Price field is updated with the specified Price. If no row with that Symbol is found, no rows are updated or inserted. |
DeleteSymbolQuery | Accepts a stream with a single Symbol field. Symbols entered must exactly match an entry in the table in spelling and case. The row in the Query Table with the specified Symbol is deleted from the table. If no such row exists, the Query Table is left unchanged. |
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, click
> . -
Enter
sample group
to narrow the list of options. -
Select Operator sample group from the Data Constructs and Operators category.
-
Click
.
StreamBase Studio creates a single project for the operator sample group.
-
In the Project Explorer view, open the sample you just loaded.
If you see red marks on a project folder, wait a moment for the project to load its features.
If the red marks do not resolve themselves after a minute, select the project, right-click, and select
> from the context menu. -
Open the
src/main/eventflow/com.tibco.sb.sample.operator
folder. -
Open the
Query.sbapp
file and click the Run button. This opens the SB Test/Debug perspective and starts the module. On startup, the application uses a CSV File Reader adapter to automatically load the Query Table from theNASDAQ100.csv
file. -
In the Output Streams view, select
All Output Streams
in the Stream drop-down control. The view initially shows the results of automatically loading the Query Table. -
In the Manual Input view, select
SymbolStream
in the Stream control. -
Enter
INTC
in the Symbol field. -
Click
. In the Output Streams view, observe the symbol, name, price, color and description of the Intel stock. This stock has been successfully read from the table. -
Try another stock symbol that you know is not in the NASDAQ 100 list. For example, enter
GE
, and observe the entry added to the Output Streams view. The Description field contains a string such as:Not a member of the NASDAQ-100.
-
In the Manual Input view, select the
PriceStream
input stream. -
Enter
15
in the MaxPrice and
in the MinPrice field.10
-
Click Send Data. In the Output Streams view, observe the symbol, name, price, color, and description of five different stocks ranging in price from $12.71 to $14.98. Notice that the stock entries are output in descending order of the secondary key (Price,Color).
-
In the Manual Input view, select the
PriceColorStream
input stream. -
Enter
in the17
MaxPrice
andblue
in theColor
field. -
Click Send Data. In the Output Streams view, observe the symbol, name, price, color, and description of three
blue
stocks whose price is less than $17.00. Notice that the stock entries are output in ascending order of the secondary key (Price,Color). -
In the Manual Input view, re-select the
SymbolStream
input stream. -
Enter
ADBE
in the Symbol field and click Send Data. -
Select the row this adds to the Output Streams view. Notice that the current price of ADBE stock is $28.43.
-
In the Manual Input view, select the
UpdatePriceStream
input stream. -
Enter
ADBE
in the Symbol field and32.75
in the Price field. -
Select the row this adds to the Output Streams view. Notice that the price of ADBE stock in the table is now $32.75.
-
In the Manual Input view, select the DeleteSymbolStream input stream.
-
Enter
ADBE
in the Symbol field. This time, you must use uppercase letters as shown. -
Click Send Data. In the Output Streams view, observe the Adobe row emitted from the
DeleteSymbolOutput
stream to confirm the row that was deleted. -
Once again select the
SymbolStream
input stream and enterADBE
. This time, the resulting row shows "Not a member of the NASDAQ-100." -
Experiment with further entries on any of the five input streams.
-
When done, press F9 or click the Terminate EventFlow Fragment button.
The Query operator sample includes the following files:
- Query.sbapp
-
Sample application file.
- NASDAQ100.csv
-
Data simulation file.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Important
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:
studio-workspace
/sample_operator
See Default Installation
Directories for the default location of studio-workspace
on your system.