telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://fiware-orion.rtfd.io/
GNU Affero General Public License v3.0
212 stars 264 forks source link

JEXL. Expression evaluation on query results #4579

Open fgalan opened 2 months ago

fgalan commented 2 months ago

Is your feature request related to a problem / use case? Please describe.

Use JEXL in queries so an expression can be evaluated on the query results to define virtual attributes.

Describe the solution you'd like

Let's consider an operation like this:

POST /v2/op/query

{
  "entities": [
    {
      "idPattern": ".*",
      "type": "Sensor"
    }
  ],
  "attrs": [
    "temperature"
  ],
  "virtualAttrs": {
      "tempRatio": {
        "value": "${temperature/100}",
        "type": "Number"
      }
  }
}

So assuming we have the following entities:

The response to that operation is:

Describe alternatives you've considered

Alternative syntax:

  "virtualAttrs": {
      "tempRatio": {
        "value": "temperature/100",
        "type": "Number"
      }
  }

Pros: simplified sintax avoiding ${...} Const: lack of homogenity compared with httpCustom.ngsi in subscriptions

We have REST-style query ops (GET /v2/entities or GET /v2/entities/{id}) but it would be more complicated defining virtualAttrs on them (they don't use payload in the request).

Describe why you need this feature

mapedraza commented 2 months ago

Probably related: https://github.com/telefonicaid/fiware-orion/issues/3815