IBM Streams 4.2.1
Adding the @view annotation to SPL operators
In order to be able to analyze streaming data in external programs such as Microsoft Excel, you must add the @view annotation to at least one operator in your SPL application.
Procedure
- In IBM® Streams Studio, you can add the @view annotation by right clicking a primitive operator in the SPL Graphical Editor and selecting Add View.
- In the SPL Editor that ships with Streams Studio or in any other text-based editor, you add the annotation directly in your SPL application code. The @view annotation can be added to any composite or primitive operator other than an Import or Export operator. It must appear in the set of annotations immediately preceding an operator invocation.
Example
- A simple application that creates a view when the SPL application is run:
- The following example application specifies a Beacon operator that outputs a
tuple with a single count attribute x every second. The
Custom operator passes data through, and the
FileSink operator stores the output. The @view
annotation is applied to the Custom operator and creates
a view called analyticsview, with a sample rate (sampleSize)
of five tuples per second and containing (bufferSize) up to the last 10
tuples sampled. The output port is Analytics.
namespace application ; composite Mycomp { graph stream<int32 x> Input = Beacon(){ param period : 1.0 ; // generate 1 per second output Input : x =(int32) IterationCount() ; } @view(name = "analyticsview", port = Analytics, sampleSize = 5, bufferSize = 10) stream<Input> Analytics = Custom(Input){ logic onTuple Input : { // pretend analytics submit(Input, Analytics) ; } } () as Output = FileSink(Analytics){ param file : "output.dat" ; writePunctuations : true ; writeStateHandlerCallbacks : true; truncateOnReset : false; flush : 1u ; } }
What to do next
After you submit the SPL application as a job, you are now ready to access streaming data in external programs such as Microsoft Excel 2010 or 2013. You do not have to start the view. The view is either started after the Excel user makes the first data request or it is started automatically, depending on how you specified the view elements.
