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. |
The Query operator sample shares the same Studio project folder as the samples for other operators. The files for the Query
operator sample are Query.sbapp
and the NASDAQ100.csv
data file in the ResourceFiles
subdirectory.
-
In the Package Explorer, double-click to open the
Query.sbapp
application. 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. On startup, the application uses a CSV File Reader adapter to automatically load the Query Table from the
NASDAQ100.csv
file. -
In the Application Output 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 Application Output view, observe the symbol, name, price, color and description of the Intel stock. This stock has been successfully read from the table.
. In the -
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 Application Output 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 Application Output 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 Application Output 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 Application Output 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 Application Output 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 Application Output 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 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, start StreamBase Server running the Query sample application. You must specify the provided server configuration file so that the application can locate the
nasdaq100.tab
file in theResourceFiles
folder. Enter:sbd -f op-samples.sbconf Query.sbapp
-
In window 2, start the dequeuer. Enter:
sbc dequeue
No output is displayed at this point, but the dequeuer is prepared to receive output. This window eventually shows the output of the all the query operations.
-
In window 3, enqueue data to your application. Enter the following command:
sbc enqueue SymbolStream
-
Window 3 now waits for manual input. Type:
INTC
In window 2, observe the symbol, name, and description of the Intel stock. This stock has been successfully read from the table.
-
In window 3, type:
GE
Observe a message containing the following string in window 2:
Not a member of the NASDAQ-100.
-
In window 3, type:
Ctrl+C sbc enq PriceStream 15,10
In window 2, observe the symbol, name, price, color and description of five different stocks whose price range is between $10.00 to $15.00. The stock entries are sent in descending order of the secondary key (Price,Color).
-
In window 3, type:
Ctrl+C sbc enq PriceColorStream 17,blue
In window 2, observe the symbol, name, price, color and description of three stocks whose color field is
blue
and whose price is less than $17.00. The stock entries are sent in ascending order of the secondary key (Price,Color). -
In window 3, type:
Ctrl+C sbc enq SymbolStream ADBE
In window 2, observe that the table's current price for ADBE stock is $28.43.
-
In window 3, type:
Ctrl+C sbc enq UpdatePriceStream ADBE, 32.75
In window 2, notice that the table's new price for ADBE stock is $32.75.
-
In window 3, type:
Ctrl+C sbc enq DeleteSymbolStream ADBE
In window 2, observe that the Adobe entry in the table is emitted to confirm the row that was deleted.
-
In window 3, type:
Ctrl+C sbc enq SymbolStream ADBE
In window 2, notice that this time the emitted entry for ADBE reports "Not a member of the NASDAQ-100."
-
Experiment with further entries on any of the five input streams.
-
In window 3, type: Ctrl+C to exit the sbc session.
-
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
In the search field, type
operator
to narrow the list of samples. -
Select
Operator sample group
from the Data Constructs and Operators category. -
Click OK.
StreamBase Studio creates a single project for the operator sample group.
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.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir
/sample/operator
See Default Installation Directories for the default location of studio-workspace
on your system.
For another use of the Query operator, see the Query TopN Sample, which tracks a sorted range of values, such as the highest (or lowest) prices.