Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting to float: document how to do it #345

Open
manucarrace opened this issue Jul 12, 2019 · 6 comments
Open

Casting to float: document how to do it #345

manucarrace opened this issue Jul 12, 2019 · 6 comments
Labels

Comments

@manucarrace
Copy link
Collaborator

manucarrace commented Jul 12, 2019

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.

@AlvaroVega
Copy link
Member

In (cast(battery?, float) is there a missed ) ?

@fgalan
Copy link
Member

fgalan commented Jul 17, 2019

Is this actually a problem with Perseo? Or just a consequence of how EPL works?

@AlvaroVega
Copy link
Member

AlvaroVega commented Sep 30, 2019

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

@AlvaroVega
Copy link
Member

AlvaroVega commented Oct 2, 2019

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)]

@mrutid
Copy link
Member

mrutid commented Jul 7, 2023

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.
image

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):
image

If we resolve the Object to String (which works almost every time) then we can safety cast to float:
image

In this case if filling level contains a value uncasteable to float ("PATATA") an exception occurs, so rule doesn't get fired.

@mrutid mrutid closed this as completed Jul 7, 2023
@AlvaroVega AlvaroVega changed the title Casting to float Casting to float: document how to do it Jul 7, 2023
@AlvaroVega AlvaroVega reopened this Jul 7, 2023
@AlvaroVega
Copy link
Member

It would be nice document that explanation #345 (comment) into doc about EPL usage https://github.com/telefonicaid/perseo-fe/blob/master/docs/API/plain_rules.md#epl-text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants