How to populate optional field in metric expression

I am trying to evaluate expression function contains two optional fields.

c3Viz(OilGasWell.evalMetric({
    "id": "deleteMe",
    "start": "2019-04-22",
    "end": "2019-05-06",
    "interval": "DAY",
    "expression": "expressionFunc(required1, optional1, optional2)"
}))

I was wondering if there is a way for me to set a value for optional2 and set the optional1 NULL. Right now, it seems to me that expression function parses the arguments based on the position. If I do things below, I will meet some error.

c3Viz(OilGasWell.evalMetric({
    "id": "deleteMe",
    "start": "2019-04-22",
    "end": "2019-05-06",
    "interval": "DAY",
    "expression": "expressionFunc(required1, optional2)"
}))

FYI, all these code below work well.

c3Viz(OilGasWell.evalMetric({
    "id": "deleteMe",
    "start": "2019-04-22",
    "end": "2019-05-06",
    "interval": "DAY",
    "expression": "expressionFunc(required1, optional1)"
}))
c3Viz(OilGasWell.evalMetric({
    "id": "deleteMe",
    "start": "2019-04-22",
    "end": "2019-05-06",
    "interval": "DAY",
    "expression": "expressionFunc(required1)"
}))

Did you try null?

"expression": "expressionFunc(required1, null, optional2)"

I tried that, it did not work. Here is the error message I got.

C3RuntimeException: CustomFunctionLibrary error : parameter optional1 must be of type ReferenceType

I would create a spec type instead so that you can do “expressionFunc(spec)”
and in the spec type you can define required1, optional1, optional2 fields with appropriate initializer values if needed.

It will also be much cleaner, order of fields won’t matter, and refactoring will be much easier when you need to add / remove fields from the spec.

1 Like

The expression that @matt mentioned should work. If it doesn’t then i would say its a bug and a ticket should be filed:

"expression": "expressionFunc(required1, null, optional2)"