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] Allow date functions in formula #143632

Merged
merged 15 commits into from Nov 3, 2022

Conversation

flash1293
Copy link
Contributor

Fixes #112851

  • Keep functions that produce dates when generating formula out of quick function
  • Show date fields in suggestions in the editor
  • Extend mathColumn expression function to cast values that are not numbers.

@flash1293 flash1293 added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens backport:skip This commit does not require backporting labels Oct 19, 2022
@flash1293 flash1293 marked this pull request as ready for review October 20, 2022 09:11
@flash1293 flash1293 requested review from a team as code owners October 20, 2022 09:11
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review in progress, will update...

Lonely timestamp

When using a simple last_value(timestamp) the chart result is 0, I guess it's still a string as the casting didn't kick in yet:
Screenshot 2022-10-20 at 16 01 52

When adding any math operation to it will trigger the casting:
Screenshot 2022-10-20 at 16 01 59

Date ranges error

Fields of type date_range should be excluded:

Screenshot 2022-10-20 at 16 14 58

@botelastic botelastic bot added the Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) label Oct 20, 2022
@flash1293
Copy link
Contributor Author

Good catch @dej611 , I think it's because there is no inner math operation. I know how to fix it.

Merge branch 'lens-formula-dates' of github.com:flash1293/kibana into lens-formula-dates
@flash1293
Copy link
Contributor Author

Should be fixed

@dej611
Copy link
Contributor

dej611 commented Oct 24, 2022

Forgot to push?

@flash1293
Copy link
Contributor Author

Yes, sorry

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked latest version and could not find any new issue! 🎉

@@ -327,7 +327,7 @@ describe('last_value', () => {
).toEqual({
dataType: 'ip',
isBucketed: false,
scale: 'ratio',
scale: 'ordinal',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically fixing a bug

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
expressions 1734 1739 +5

Any counts in public APIs

Total count of every any typed public API. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats any for more detailed information.

id before after diff
expressions 73 74 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.3MB 1.3MB +193.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
expressions 98.1KB 98.5KB +447.0B
Unknown metric groups

API count

id before after diff
expressions 2191 2196 +5

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 57 63 +6
osquery 103 108 +5
securitySolution 439 445 +6
total +19

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 65 71 +6
osquery 104 110 +6
securitySolution 516 522 +6
total +20

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@dokmic dokmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM👍

@flash1293 flash1293 merged commit cc4be7e into elastic:main Nov 3, 2022
@probance-antoine
Copy link

hello @flash1293 , thanks for this PR !

If I understand correctly, in 8.6.0 I will be able to calculate the delta between 2 dates, for example last_value(@timestamp) - now() in a lens formula ? What will be the result, an integer or a date ?

@dej611
Copy link
Contributor

dej611 commented Jan 9, 2023

@probance-antoine the last_value(@timestamp) formula will output an integer value as milliseconds since the Unix Epoch.

As for the now() function, there's currently nothing like that yet. You can open a feature request for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Formula: Date math
7 participants