Open manucarrace opened 5 years ago
In (cast(battery?, float)
is there a missed )
?
Is this actually a problem with Perseo? Or just a consequence of how EPL works?
Could you provide a full example (rule, action, data, expected data) ?
In general if you use version 2 of NGSI for updateAction then float cast is done automatically: https://github.com/telefonicaid/perseo-fe/blob/master/lib/models/updateAction.js#L280
if there is a temperature
attribute of type Number, or inserted in ContextBroker as a real numerical type then you don't need to cast to string, just cast to float:
select *, *, ev.temperature? as Temperature, ev.id? as Meter from pattern [every ev=iotEvent(cast(temperature?,float)>1.5)]
Two nested cast expression are needed if you expect to receive Strings representing Numbers is your context stream.
Examples and explanation:
Every Dinamic Property (fillingLevel?) has Object type in Esper, therefore casting is needed to use fillingLevel in float expressions.
If we do the float cast it works when fillingLevel is a number (int or float). But fails if it's a String containing a number (in fact an Object containing a String "containing" a number):
If we resolve the Object to String (which works almost every time) then we can safety cast to float:
In this case if filling level contains a value uncasteable to float ("PATATA") an exception occurs, so rule doesn't get fired.
It would be nice document that explanation https://github.com/telefonicaid/perseo-fe/issues/345#issuecomment-1625123336 into doc about EPL usage https://github.com/telefonicaid/perseo-fe/blob/master/docs/API/plain_rules.md#epl-text
In order to make a casting to float it is needed to make the following
(cast(cast(
battery?, String), float)
If we make
(cast(
battery?, float)
the rule does not work as expected.