[Lens] Formula: String / boolean literals #94613
Labels
enhancement
New value added to drive a business result
Feature:Lens
🧊 iceboxed
Team:Visualizations
Visualization editors, elastic-charts and infrastructure
Currently Lens formula is limited to number values only. However, there are some use cases where working with strings, dates or booleans would be helpful. One part of this is described in #94603 and consists out of checking the return types of the AST nodes, but it would also be necessary to specify literals in some way.
Implementation
This is difficult because in tinymath quoted strings can be variable names as well. Also,
true
andfalse
are not reserved and might be variables as well.Option 1
Introduce an espace-hatch for the grammar, for example
const(<constant value here>)
. This is on tiny-math side, not Lens:const(true)
becomes a literaltrue
value during evaluationconst(false)
becomes a literalfalse
value during evaluationconst(abc)
becomes a literal"abc"
string value during evaluationconst("quoted string")
becomes a literal"quoted string"
string value during evaluationconst(123)
becomes a literal123
number value during evaluationconst(add(1,2))
is a syntax error and fails during parsing - the argument of const can only be a literalThis is a breaking change for tiny-math, but a very minor one.
Option 2
Work around this on Lens side - for each variable name which is not a field name, a variable with its name as value is created for the evaluation context. E.g. for
if(last_value(status) == "ONLINE", average(memory), 0)
- the math execution has the following variables:{ ONLINE: ONLINE }
This would work without changing anything in tinymath, result in a cleaner syntax but it makes it harder to provide a good error message because we don't know whether the user is typing a string literal or a field name.
Use case
Only doing a calculation if an entity is currently in a certain state, e.g. average used memory of servers which are online right now:
if(last_value(status) == "ONLINE", average(memory), 0)
The text was updated successfully, but these errors were encountered: