Escape characters in string variable for metric


We have a simple metric defined as follows:

      "id": "MyMeasurements_MyType",
      "name": "MyMeasurements",
      "srcType": "MyType",
      "path": "some.path.(id == MY_ID).measurements",
      "expression": "avg(avg(",
      "variables": [{"name": "MY_ID", "dataType": "string"}]

And are trying to evaluate this metric like this:

  ids: ['testId'],
  expressions: ['MyMeasurements'],
  start: '2018-01-01',
  end: '2018-01-10',
  interval: 'HOUR',

However, we end up getting the following errors when using that id:

“Invalid metric … Metric for eval type ‘MyType’ has invalid expression ‘some.path.(id == SOME:ID_WITH.SPECIALCHARS).measurements’ in field ‘path’: Invalid expression “some.path.(id == SOME:ID_WITH.SPECIALCHARS).measurements”: missing ) in parenthetical (#1)”

If we remove the : then we end up with a different error:

“Invalid metric … Typecast ‘SOME:ID_WITH’ for expression ‘some.path.(id == SOME:ID_WITH.SPECIALCHARS).measurements’ in metric … with source type ‘MyType’ not yet supported.”

Once both the colon and period are removed then the metric evaluates without error. Is there a way to escape the special characters in a string field when passed as a metric variable?


This should be handled internally by the engine. For now can you try escaping with a , something like:
“SOME:ID_WITH.SPECIALCHARS” -> I’m not sure if it will work, but worth a shot.


Here’s what I did in v7.9 server version and it works like a charm:

  1. Create weather station with special characters
WeatherStation.upsert({id:"test-1", name:"SOME:ID_WITH.;:.,[]{}-<>?$/'@#!%^&*()_+~|\_+=SPECIALCHARS"})
  1. Create location pointing to the weather station
Location.make({id:"test-1", weatherStation: {id:"test-1"}})
  1. Run evalMetrics
  ids: ['test-1'],
  expressions: ['Foo'],
  start: '2018-01-01',
  end: '2018-01-10',
  interval: 'HOUR',
  bindings: [{VAR: "SOME:ID_WITH.;:.,[]{}-<>?$/'@#!%^&*()_+~|\_+=SPECIALCHARS"}]
}, [SimpleMetric.make({
  "type": "SimpleMetric",
  "srcType": {
    "typeName": "WeatherAware"
  "path": "weatherStation.(name == VAR)",
  "name": "Foo",
  "id": "Foo_WeatherAware",
  "unit": {
    "id": "degrees_fahrenheit"
  "expression": "identity(1)", 
  "variables" : [{"name" : "VAR"}]  

So possibilities are that this bug has been fixed in v7.9 or there is something else that is causing the right information not being able to sent to the server. Start with looking at the Network tab


Looks like this was a result of using a resultKey Lambda function that used the name of the variable with special characters for the name of the metric, which is currently not supported. Thanks for the feedback @rohit.sureka!