Calculating the Approximate Count of Events within a Siddhi Window¶
This application demonstrates how to calculate the approximate count(frequency) of eventS within a Siddhi window.
Before you begin:
- Copy the
<SI_TOOLING_HOME>/samples/artifacts/ApproximateComputingSample/Test-approximate-count.jsonfile and paste it in the
- Copy the
<SI_TOOLING_HOME>/samples/artifacts/ApproximateComputingSample/approximate-count.csvfile and paste it in the
Save the sample Siddhi application.
@App:name("approximate-count-sample") @APP:description("Demonstrates how to calculate the approximate count(frequency) of eventS within a Siddhi window.") define stream transactionStream (userId int, amount double); @sink(type='log') define stream OutputStream(count long, countLowerBound long, countUpperBound long); @info(name = 'query1') from transactionStream#window.length(50)#approximate:count(userId, 0.005, 0.9) select count, countLowerBound, countUpperBound insert into OutputStream;
Executing the Sample¶
To execute the sample, start the
approximate-count-sample Siddhi application by clicking the Start button (shown below) or by clicking by clicking Run => Run.
If the Siddhi application starts successfully, the following message appears in the console.
approximate-count-sample.siddhi - Started Successfully!
Testing the Sample¶
To test the sample Siddhi application, simulate multiple events for it from a CSV file via the Streaming Integrator Tooling as follows:
- To open the Event Simulator, click the Event Simulator icon.
In the Event Simulator panel, click Feed Simulation. Test-approximate-count is available in the Active Feed Simulations list as shown below.
Click the start button next to the Test-approximate-count simulation.
- Select Test-approximate-count under 'Active Feed Simulations'
- Click on the start button (Arrow symbol) next to the simulator
Viewing the Results:¶
e output is logged i the console as shown in the extract below.Top