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

[Lens] Formula: String / boolean literals #94613

Closed
Tracked by #184648
flash1293 opened this issue Mar 15, 2021 · 4 comments
Closed
Tracked by #184648

[Lens] Formula: String / boolean literals #94613

flash1293 opened this issue Mar 15, 2021 · 4 comments
Labels
enhancement New value added to drive a business result Feature:Lens 🧊 iceboxed Team:Visualizations Visualization editors, elastic-charts and infrastructure

Comments

@flash1293
Copy link
Contributor

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 and false 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 literal true value during evaluation
  • const(false) becomes a literal false value during evaluation
  • const(abc) becomes a literal "abc" string value during evaluation
  • const("quoted string") becomes a literal "quoted string" string value during evaluation
  • For consistency: const(123) becomes a literal 123 number value during evaluation
  • const(add(1,2)) is a syntax error and fails during parsing - the argument of const can only be a literal

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

@flash1293 flash1293 added discuss enhancement New value added to drive a business result Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens labels Mar 15, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@wylieconlon
Copy link
Contributor

I agree that option 2 is cleaner, and I think we can build this into the validation.

We should also add a null or undefined value, since that matters a lot in some chart types.

@ghudgins
Copy link

ghudgins commented Oct 5, 2021

@markov00
Copy link
Member

markov00 commented Jun 3, 2024

In order to provide better transparency of priorities, issues that will not be prioritized within the next 24 months are being closed.

Tracking request in Lens general improvements ice box, solvable possibly with ESQL #184648

@markov00 markov00 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Lens 🧊 iceboxed Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
Development

No branches or pull requests

5 participants