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] Calculation operations #83789

Merged
merged 20 commits into from
Nov 25, 2020
Merged

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Nov 19, 2020

Based on #83603

This PR adds some real implementations for reference-based operations:

  • Cumulative sum
  • Derivative
  • Moving average
  • Counter rate

cc @wylieconlon

@flash1293 flash1293 changed the title [Lens] Cumulative sum operation [Lens] Calculation operations Nov 20, 2020
@flash1293
Copy link
Contributor Author

@wylieconlon This should build fine now

Copy link
Contributor

@wylieconlon wylieconlon left a 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! I left some stylistic comments, but this will definitely help develop the UI :)

defaultMessage: 'Window size',
})}
display="columnCompressed"
fullWidth
Copy link
Contributor

Choose a reason for hiding this comment

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

This form input is a good candidate for help text. I would like to explain some of the comments that we've written in the definition of the window, such as how it's trailing and how it deals with missing values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a design for that yet?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no final design, but the idea that @MichaelMarcialis wants to explore is a popover-based help text. Tracking that effort here: #81780

}
return [
i18n.translate('xpack.lens.indexPattern.calculations.dateHistogramErrorMessage', {
defaultMessage: 'Needs a date histogram to work',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this error message would be improved by adding more context, like Cumulative sum requires a date histogram to work. Choose a different function or add a date histogram. This context might need to be passed in as an argument to the function

additionalArgs: Record<string, unknown[]> = {}
): ExpressionFunctionAST[] {
const currentColumn = (layer.columns[columnId] as unknown) as ReferenceBasedIndexPatternColumn;
const buckets = layer.columnOrder.filter((colId) => layer.columns[colId].isBucketed);
Copy link
Contributor

Choose a reason for hiding this comment

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

Small tweak to the code style:

Suggested change
const buckets = layer.columnOrder.filter((colId) => layer.columns[colId].isBucketed);
const buckets = layer.columnOrder.filter((colId) => layer.columns[colId].isBucketed && layer.columns[colId].operationType !== 'date_histogram');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not just a code style change - if there are two date histogram columns in the current table, this will prevent grouping by the second for applying the calculation, producing meaningless data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, hadn't realized.

Comment on lines +45 to +48
const dateColumnIndex = buckets.findIndex(
(colId) => layer.columns[colId].operationType === 'date_histogram'
)!;
buckets.splice(dateColumnIndex, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const dateColumnIndex = buckets.findIndex(
(colId) => layer.columns[colId].operationType === 'date_histogram'
)!;
buckets.splice(dateColumnIndex, 1);
const dateColumnIndex = layer.columnOrder.findIndex(
(colId) => layer.columns[colId].operationType === 'date_histogram'
)!;

@flash1293
Copy link
Contributor Author

Thanks for the review @wylieconlon , I worked through the comments you didn't tackle yourself. There's a code style recommendation I don't get, could you check out that one?

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@flash1293 flash1293 marked this pull request as ready for review November 23, 2020 16:21
@flash1293 flash1293 requested a review from a team November 23, 2020 16:21
@flash1293 flash1293 added Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0 labels Nov 23, 2020
@elasticmachine
Copy link
Contributor

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

@wylieconlon
Copy link
Contributor

@flash1293 I know this isn't related to this code directly, but it looks like the lens_counter_rate expression function isn't actually registered to the expression plugin. Do you want to add that as part of this PR or separately?


const ofName = (name?: string) => {
return i18n.translate('xpack.lens.indexPattern.cumulativeSumOf', {
defaultMessage: 'Cumulative sum rate of {name}',
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we expecting this to be Cumulative sum of <field>? It's currently Cumulative sum of <reference label>?

This is part of my reference UI work, so you might not need to make a change. I'm regenerating the default labels whenever you modify an operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, good point, I'm not sure actually. Let's keep that for now and see whether we want to keep it once transition/UI is in place

@flash1293
Copy link
Contributor Author

@wylieconlon Registered counter rate as part of this PR

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 438 445 +7

Async chunks

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

id before after diff
lens 936.9KB 952.6KB +15.6KB

Page load bundle

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

id before after diff
lens 52.8KB 52.9KB +93.0B

History

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

@flash1293 flash1293 merged commit a763d33 into elastic:master Nov 25, 2020
flash1293 added a commit to flash1293/kibana that referenced this pull request Nov 25, 2020
# Conflicts:
#	x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts
#	x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts
flash1293 added a commit to flash1293/kibana that referenced this pull request Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants