Aggregate Operator Tuple Dimension Sample

About This Sample

This topic explains AggregateByTup.sbapp, the Aggregate operator tuple dimension sample.

This sample demonstrates two uses of the tuple-based Aggregate operator. The first uses a tuple-based Aggregate operator to calculate a moving average of price for each of four successive trades of a given stock. It also ensures that the aggregation works for intermixed tuples for different stocks. The second provides a sequence number for input tuples, using a window which does not close and the emit feature to emit an output tuple for every input tuple.

Importing This Sample into StreamBase Studio

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

  • From the top-level menu, click File>Import Samples and Community Content.

  • Enter sample group to narrow the list of options.

  • Select Operator sample group from the Data Constructs and Operators category.

  • Click Import Now.

StreamBase Studio creates a single project for the operator samples.

Running This Sample in StreamBase Studio

  1. 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 Maven>Update Project from the context menu.

  2. Open the src/main/eventflow/com.tibco.sb.sample.operator folder.

  3. Open the AggregateByTup.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

  4. In the Output Streams view, select the AvgPricePSOut output 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.

  5. In the Manual Input view, select the TradesIn input stream.

  6. Enter AMAT and 23 in the Symbol, and PricePerShare fields, respectively.

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

  8. Enter AMAT and 24 in the Symbol, and PricePerShare fields, respectively.

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

  10. Again enter AMAT and 24 in the Symbol, and PricePerShare fields, respectively.

  11. Click Send Data. There is still no output in the Output Streams view.

  12. Enter AMAT and 25 in the Symbol, and PricePerShare fields, respectively.

  13. Click Send Data, and observe this line in the Output Streams view:

    Symbol=AMAT, MovingAverage=24.0

    Tip

    If output data is too long to easily see in the Output Streams grid, click a row to display its field data in the Display Fields pane below the table.

  14. Enter AMAT and 20 in the Symbol, and PricePerShare fields, respectively.

  15. Click Send Data, and observe this line in the Output Streams view:

    Symbol=AMAT, MovingAverage=23.25

  16. Enter AMAT and 21 in the Symbol, and PricePerShare fields, respectively.

  17. Click Send Data, and observe this line in the Output Streams view:

    Symbol=AMAT, MovingAverage=22.5

  18. Enter AMAT and 21 in the Symbol, and PricePerShare fields, respectively.

  19. Click Send Data, and observe this line in the Output Streams view:

    Symbol=AMAT, MovingAverage=21.75

  20. Enter AMAT and 22 in the Symbol, and PricePerShare fields, respectively.

  21. Click Send Data, and observe this line in the Output Streams view:

    Symbol=AMAT, MovingAverage=21.0

  22. Enter INTC and 27 in the Symbol, and PricePerShare fields, respectively.

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

  24. Enter INTC and 28 in the Symbol, and PricePerShare fields, respectively.

  25. Click Send Data, and observe no further output is displayed yet in the Output Streams view:

  26. Enter AMAT and 22 in the Symbol, and PricePerShare fields, respectively.

  27. Click Send Data, and observe this line in the Output Streams view:

    Symbol=AMAT, MovingAverage=21.5

  28. Enter INTC and 27 in the Symbol, and PricePerShare fields, respectively.

  29. Click Send Data, and observe no further output is displayed yet in the Output Streams view:

  30. Enter AMAT and 23 in the Symbol, and PricePerShare fields, respectively.

  31. Click Send Data, and observe this line in the Output Streams view:

    Symbol=AMAT, MovingAverage=22.0

  32. Enter INTC and 28 in the Symbol, and PricePerShare fields, respectively.

  33. Click Send Data, and observe this line in the Output Streams view:

    Symbol=INTC, MovingAverage=27.5

  34. Next, view the sequence number.

  35. In the Output Streams view, select the SeqOut output stream. No output is displayed at this point, but the dequeuer is prepared to receive output.

  36. Change from Manual Input to the Feed Simulations view.

  37. Right click on SeqFeed.sbfs and select Run Feed Simulation.

  38. Notice on output how sequence_number increases by 1.

  39. When done, press F9 or click the Terminate EventFlow Fragment button.

Sample Location

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.