-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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: Conditionals #94603
Comments
Pinging @elastic/kibana-app (Team:KibanaApp) |
These examples seem great, but I think they are missing the most common case that I know of: hiding "small" values of series, like the ones described in #86190, by converting them into null values. This would require us to add a
Another example that I would have liked to see is a range of values, if the upper and lower boundary matters:
For both of these use cases, I would prefer a helper function which is a nicer syntax. Maybe something like |
Agreed, that's a relevant use case @wylieconlon . I like the This can be a separate issue, but I think for categorical axes we should provide some way to hide the null rows in the chart, otherwise nulling them doesn't help much. Like this: This will show the following table:
What I want to see
Maybe this can be a setting on the bucket dimension (a switch for "hide if |
Another great example that I want to implement right now, but can't is:
E.g.
|
@MarianAlexandruAlecu you might be able to solve this case with the new "Collapse by" feature that will be released with 8.3: #131748 |
How does the condition formula work after all ? I can't find any documentation on this |
@probance-antoine this issue is still |
editorialized quote: "solves 100+ use cases for us...very hard to get approval to add conditionals to ingest processing so this feature would really help" |
Right now formula is limited to math operations. However, having conditionals (branching logic) is also often helpful.
Implementation
a < b
- compiles tolt(a,b)
a <= b
- compiles tolte(a,b)
a > b
- compiles togt(a,b)
a >= b
- compiles togte(a,b)
a == b
- compiles toeq(a,b)
if
function in the regular tinymath lib:if(<cond>,<then>, <else>)
- if the value of cond is truthy, return then, otherwise return elseThis requires to extend the parsing logic in Lens to consider the data type of an AST node and check the integrity and report errors. The type can be inferred by walking the tree in a depth first search and return type information for all functions.
Use cases
In some cases, it's possible to do the conditional in a runtime field, but it's easier/more straight forward to do it in a formula, because we don't have to split the logic
Examples:
sum(total)/(cardinality(customer_id) + if(count() > count(filter=customer_id:*), 1, 0)
if(customer_id) customer_id else 'UNKNOWN_CUSTOMER_ID'
count() / if(last_value(day_of_week) < 5, 1000 /* weekday quota */, 500 /* weekend quota */)
if(day_of_week < 5) 1/1000 else 1/500
In some cases, it's not possible to calculate in a runtime field:
Examples:
if(count(order_id:*) > 10000, /* calculation for large customers */, /* calculations for small customers */)
if(last_value(load) > 0, average(memory), 0)
There are other separate use cases which require string handling (returning a string literal or compare against a string literal (separate issue for this)
The text was updated successfully, but these errors were encountered: