It is common to do transformations on the events in the stream. In our case, before we
alert on the speeding driver, we want to convert the average speed we calculated in the
aggregate processor into a integer from a double so it is easier to display in the alert. The
projection processor allows you to do these transformations.
-
Drag the Projection processor onto the canvas and connect to it to the
IsDriverSpeeding Rule processor:
-
When you double-click on the projection processor, you see a number of
out-of-the-box functions, however a Round function does not exist.
-
Adding UDFs (User Defined Functions) is easy to do within SAM. Follow the below
steps to add Round UDF function to SAM.
- From the left-hand menu, click Configuration, then
Application Resources.
- Select the UDF tab and click the + sign to create the ROUND UDF. The
jar for this UDF can be downloaded from here, located in the
custom-udf folder. The simple java class used to
implement this Round function using the SAM SDK can be found here. Unzip the downloaded artifact
and use the jar called sam-custom-udf-0.0.5.jar.
Configure the UDF with the following values:
- After uploading the UDF, you should see the new Round UDF created.
-
After creating the UDF, go back to your Application and double-click Projection
Processor you added to the canvas. You will see ROUND_AUTOCREATE in the FUNCTION drop down list.
-
Configure the ROUND_AUTOCREATE function as the following: