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

Math on expression improvements #90423

Closed
flash1293 opened this issue Feb 5, 2021 · 2 comments · Fixed by #90481
Closed

Math on expression improvements #90423

flash1293 opened this issue Feb 5, 2021 · 2 comments · Fixed by #90481
Assignees
Labels
Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure

Comments

@flash1293
Copy link
Contributor

For the upcoming Lens formula features some minor things have to be adjusted about how the math and mapColumn expression functions work.

math

The math function is pretty strict because it always tries to return a number and fails the expression execution otherwise. In the case of Lens, it's very easy to run into this case and a better behavior is to just return null as result (which will handled correctly by the chart)

  • Move into expressions plugin
  • Remove explicit return type of number (replaced by ['boolean', 'number', 'null'])
  • Add optional onError argument. Valid values are "null", "zero", "false" and "throw", defaulting to "throw". In case the tinymath evaluation fails or returns NaN, the return value is specified by onError. If it's set to throw, it will throw an exception, terminating expression execution (in the same way it happens now)
// b is null in the current context
math "a + b" onError="null" | // it's null here
math "a + b" onError="zero" | // it's 0 here
math "a + b" onError="false" | // it's false here
math "a + b" onError="throw" | // expression aborts
math "a + b" | // expression aborts

mapColumn

The mapColumn function creates a new column for the current datatable context. However, it only allows to specify the id without a different name and meta information from other columns can't be copied over.

  • Move into expressions plugin
  • Add optional string id attribute - if set, it's used for the id of the resulting column. If not specified defaults to the value of name/column
  • Add optional string copyMetaFrom attribute - if set, the meta object from the specified column id is copied over to the specified target column. Throws an exception of the column doesn't exist
// creates new column `newCol` (visible name `User facing name`) which contains the duplicate of `oldCol`, with all meta info like field formatters copied over
mapColumn copyMetaFrom="oldCol" name="User facing name" id="newCol" fn={math "oldCol * 2" onError="zero"}
@flash1293 flash1293 added Team:Visualizations Visualization editors, elastic-charts and infrastructure Team:AppServices Feature:Lens labels Feb 5, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@elasticmachine
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
3 participants