-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Expressions] [Lens] Add id and copyMetaFrom arg to mapColumn fn + add configurable onError argument to math fn #90481
Conversation
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
Pinging @elastic/kibana-app (Team:KibanaApp) |
|=== | ||
|
||
*Returns:* `number` | ||
*Returns:* `number` | `boolean` | `null` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to extends the return type to cover the onError
returning values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LGTM
Renamed PR for changelog |
types: ['string'], | ||
help: i18n.translate('expressions.functions.math.args.onErrorHelpText', { | ||
defaultMessage: | ||
"In case the {TINYMATH} evaluation fails or returns NaN, the return value is specified by onError. When `'throw'`, it will throw an exception, terminating expression execution (default).", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should specify valid values instead of just being of type string (to allow auto-complete)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that as first option, but could not find a way to map a string union to a specific type for expressions. All the examples I check in the documentation have the string
type assigned and documenting the valid values on the documentation side.
} | ||
return result; | ||
} catch (e) { | ||
if (isDatatable(input) && input.rows.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onError
logic has to happen in the catch handler as well to catch things like divide by zero
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks almost good to me, just found one bug
|
||
return Promise.all(rowPromises).then((rows) => { | ||
const existingColumnIndex = columns.findIndex(({ name }) => name === args.name); | ||
const type = rows.length ? getType(rows[0][args.name]) : 'null'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If id and name are both used, this lookup won't work (same issue with the row above). It should use columnId
as well (probably worth a functional test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the issue. I did misinterpret it initially. There's a test already to cover this specific case.
…nto expression/mapColumn-ext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, otherwise looks good
types: ['string', 'null'], | ||
help: i18n.translate('expressions.functions.mapColumn.args.copyMetaFromHelpText', { | ||
defaultMessage: | ||
"If set, the meta object from the specified column id is copied over to the specified target column. Throws an exception if the column doesn't exist", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It says the meta object is copied by specified column id, but it is actually using the name. I think we should use the id in line 107 as it's more stable)
It also says "Throws an exception if the column doesn't exist", but it will actually just silently not copy over meta. I think this behavior is OK, but we should adjust documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, except I agree with Joe's comment that metadata should be copied by ID instead of by name.
aliases: ['exp', 'fn', 'function'], | ||
help: i18n.translate('expressions.functions.mapColumn.args.expressionHelpText', { | ||
defaultMessage: | ||
'A {CANVAS} expression that is passed to each row as a single row {DATATABLE}.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that you didn't write this text, but maybe if you're making changes you can correct it. Two things to correct:
- The row is passed into the expression, but the text has it backwards
- Canvas expression vs expression
'A {CANVAS} expression that is passed to each row as a single row {DATATABLE}.', | |
'An expression that is executed on every row, provided with a single-row {DATATABLE} context and returning the cell value.', |
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left two nits about extending the unit tests a little
{ | ||
id: 'myId', | ||
name: 'myName', | ||
meta: { type: 'date' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we extends this test a little with more meta information?
expect(result.columns).toHaveLength(1); | ||
expect(result.columns[0]).toHaveProperty('name', 'name'); | ||
expect(result.columns[0]).toHaveProperty('id', 'name'); | ||
expect(result.columns[0].meta).toHaveProperty('type', 'null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test here that still infers the type correctly from the first row if the meta information transfer fails?
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thanks for updating the function reference docs
…d configurable onError argument to math fn (elastic#90481) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
* master: (38 commits) Fixes Cypress flake by adding pipe, click, and should (elastic#92762) [Discover] Fix filtering selected sidebar fields (elastic#91828) [ML] Fixes positions of calendar arrow buttons in start datafeed modal (elastic#92625) [dev/build_ts_refs] check that commit in outDirs matches mergeBase (elastic#92513) add dep on `@kbn/config` so it is built first [Expressions] [Lens] Add id and copyMetaFrom arg to mapColumn fn + add configurable onError argument to math fn (elastic#90481) [Lens] Fix Workspace hidden when using Safari (elastic#92616) [Lens] Fixes vertical alignment validation messages (elastic#91878) forbid x-elastic-product-origin header in elasticsearch configuration (elastic#92359) [Security Solution][Detections] Set default indicator path to reduce friction with new filebeat modules (elastic#92081) [ILM][Accessibility] Added A11y test for ILM new policy form. (elastic#92570) [Security Solution][Exceptions] - Fixes exceptions builder UI where invalid values can cause overwrites of other values (elastic#90634) Automatically generated Api documentation (elastic#86232) Increase index pattern select limit to 1000 (elastic#92093) [core.logging] Add RewriteAppender for filtering LogMeta. (elastic#91492) [Security Solution][Detection Rules] Update prebuilt rule threats to match schema (elastic#92281) [Security Solutions][Detection Engine] Fixes bug with not being able to duplicate indicator matches (elastic#92565) [Dashboard] Export appropriate references from byValue panels (elastic#91567) [Upgrade Assistant] Align code between branches (elastic#91862) [Security Solution][Case] Fix alerts push (elastic#91638) ...
Summary
Fixes #90423
This PR moves the
mapColumn
andmath
expressions to the sharedexpressions
plugin in order to enable Lens to use them for the "Formula" features (see issue for more details).mapColumn
id
argument (feature + help + tests)copyMetaFrom
argument (feature + help + tests)math
onError
argument (feature + help + tests)Checklist
Delete any items that are not applicable to this PR.