-
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] Calculation operations #83789
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
eb4b573
[Lens] Implement types for reference-based operations
wylieconlon b4fb6ea
Merge remote-tracking branch 'origin/master' into lens/reference-types
wylieconlon 6024a31
Merge remote-tracking branch 'origin/master' into lens/reference-types
wylieconlon 104595f
Update from review feedback
wylieconlon 963cfc1
wip
flash1293 6cea768
Merge remote-tracking branch 'upstream/master' into lens/cumsum_opera…
flash1293 ad6f522
fix problem
flash1293 1c1f69d
fix types
flash1293 cf94d0c
Merge remote-tracking branch 'upstream/master' into lens/cumsum_opera…
flash1293 7ef2558
add other operations
flash1293 724e7c3
add window param
flash1293 cc902e2
fix circular import
flash1293 c0a16e4
Merge remote-tracking branch 'origin/master' into HEAD
wylieconlon 26db7b8
Change types in test
wylieconlon c208fde
Fix labeling
wylieconlon 1e42fcd
Merge remote-tracking branch 'upstream/master' into lens/cumsum_opera…
flash1293 4751e99
fix stuff
flash1293 0271146
Merge branch 'master' into lens/cumsum_operation
kibanamachine 620f095
Merge remote-tracking branch 'upstream/master' into lens/cumsum_opera…
flash1293 3f9fb7d
register counter rate function
flash1293 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
.../lens/public/indexpattern_datasource/operations/definitions/calculations/counter_rate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types'; | ||
import { IndexPatternLayer } from '../../../types'; | ||
import { checkForDateHistogram, dateBasedOperationToExpression, hasDateField } from './utils'; | ||
import { OperationDefinition } from '..'; | ||
|
||
const ofName = (name?: string) => { | ||
return i18n.translate('xpack.lens.indexPattern.CounterRateOf', { | ||
defaultMessage: 'Counter rate of {name}', | ||
values: { | ||
name: | ||
name ?? | ||
i18n.translate('xpack.lens.indexPattern.incompleteOperation', { | ||
defaultMessage: '(incomplete)', | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export type CounterRateIndexPatternColumn = FormattedIndexPatternColumn & | ||
ReferenceBasedIndexPatternColumn & { | ||
operationType: 'counter_rate'; | ||
}; | ||
|
||
export const counterRateOperation: OperationDefinition< | ||
CounterRateIndexPatternColumn, | ||
'fullReference' | ||
> = { | ||
type: 'counter_rate', | ||
priority: 1, | ||
displayName: i18n.translate('xpack.lens.indexPattern.counterRate', { | ||
defaultMessage: 'Counter rate', | ||
}), | ||
input: 'fullReference', | ||
selectionStyle: 'field', | ||
requiredReferences: [ | ||
{ | ||
input: ['field'], | ||
specificOperations: ['max'], | ||
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed, | ||
}, | ||
], | ||
getPossibleOperation: () => { | ||
return { | ||
dataType: 'number', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
}; | ||
}, | ||
getDefaultLabel: (column, indexPattern, columns) => { | ||
return ofName(columns[column.references[0]]?.label); | ||
}, | ||
toExpression: (layer, columnId) => { | ||
return dateBasedOperationToExpression(layer, columnId, 'lens_counter_rate'); | ||
}, | ||
buildColumn: ({ referenceIds, previousColumn, layer }) => { | ||
const metric = layer.columns[referenceIds[0]]; | ||
return { | ||
label: ofName(metric?.label), | ||
dataType: 'number', | ||
operationType: 'counter_rate', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
references: referenceIds, | ||
params: | ||
previousColumn?.dataType === 'number' && | ||
previousColumn.params && | ||
'format' in previousColumn.params && | ||
previousColumn.params.format | ||
? { format: previousColumn.params.format } | ||
: undefined, | ||
}; | ||
}, | ||
isTransferable: (column, newIndexPattern) => { | ||
return hasDateField(newIndexPattern); | ||
}, | ||
getErrorMessage: (layer: IndexPatternLayer) => { | ||
return checkForDateHistogram( | ||
layer, | ||
i18n.translate('xpack.lens.indexPattern.counterRate', { | ||
defaultMessage: 'Counter rate', | ||
}) | ||
); | ||
}, | ||
}; |
91 changes: 91 additions & 0 deletions
91
...ens/public/indexpattern_datasource/operations/definitions/calculations/cumulative_sum.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types'; | ||
import { IndexPatternLayer } from '../../../types'; | ||
import { checkForDateHistogram, dateBasedOperationToExpression } from './utils'; | ||
import { OperationDefinition } from '..'; | ||
|
||
const ofName = (name?: string) => { | ||
return i18n.translate('xpack.lens.indexPattern.cumulativeSumOf', { | ||
defaultMessage: 'Cumulative sum rate of {name}', | ||
values: { | ||
name: | ||
name ?? | ||
i18n.translate('xpack.lens.indexPattern.incompleteOperation', { | ||
defaultMessage: '(incomplete)', | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export type CumulativeSumIndexPatternColumn = FormattedIndexPatternColumn & | ||
ReferenceBasedIndexPatternColumn & { | ||
operationType: 'cumulative_sum'; | ||
}; | ||
|
||
export const cumulativeSumOperation: OperationDefinition< | ||
CumulativeSumIndexPatternColumn, | ||
'fullReference' | ||
> = { | ||
type: 'cumulative_sum', | ||
priority: 1, | ||
displayName: i18n.translate('xpack.lens.indexPattern.cumulativeSum', { | ||
defaultMessage: 'Cumulative sum', | ||
}), | ||
input: 'fullReference', | ||
selectionStyle: 'field', | ||
requiredReferences: [ | ||
{ | ||
input: ['field'], | ||
specificOperations: ['count', 'sum'], | ||
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed, | ||
}, | ||
], | ||
getPossibleOperation: () => { | ||
return { | ||
dataType: 'number', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
}; | ||
}, | ||
getDefaultLabel: (column, indexPattern, columns) => { | ||
return ofName(columns[column.references[0]]?.label); | ||
}, | ||
toExpression: (layer, columnId) => { | ||
return dateBasedOperationToExpression(layer, columnId, 'cumulative_sum'); | ||
}, | ||
buildColumn: ({ referenceIds, previousColumn, layer }) => { | ||
const metric = layer.columns[referenceIds[0]]; | ||
return { | ||
label: ofName(metric?.label), | ||
dataType: 'number', | ||
operationType: 'cumulative_sum', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
references: referenceIds, | ||
params: | ||
previousColumn?.dataType === 'number' && | ||
previousColumn.params && | ||
'format' in previousColumn.params && | ||
previousColumn.params.format | ||
? { format: previousColumn.params.format } | ||
: undefined, | ||
}; | ||
}, | ||
isTransferable: () => { | ||
return true; | ||
}, | ||
getErrorMessage: (layer: IndexPatternLayer) => { | ||
return checkForDateHistogram( | ||
layer, | ||
i18n.translate('xpack.lens.indexPattern.cumulativeSum', { | ||
defaultMessage: 'Cumulative sum', | ||
}) | ||
); | ||
}, | ||
}; |
90 changes: 90 additions & 0 deletions
90
...ns/lens/public/indexpattern_datasource/operations/definitions/calculations/derivative.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedIndexPatternColumn, ReferenceBasedIndexPatternColumn } from '../column_types'; | ||
import { IndexPatternLayer } from '../../../types'; | ||
import { checkForDateHistogram, dateBasedOperationToExpression, hasDateField } from './utils'; | ||
import { OperationDefinition } from '..'; | ||
|
||
const ofName = (name?: string) => { | ||
return i18n.translate('xpack.lens.indexPattern.derivativeOf', { | ||
defaultMessage: 'Differences of {name}', | ||
values: { | ||
name: | ||
name ?? | ||
i18n.translate('xpack.lens.indexPattern.incompleteOperation', { | ||
defaultMessage: '(incomplete)', | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export type DerivativeIndexPatternColumn = FormattedIndexPatternColumn & | ||
ReferenceBasedIndexPatternColumn & { | ||
operationType: 'derivative'; | ||
}; | ||
|
||
export const derivativeOperation: OperationDefinition< | ||
DerivativeIndexPatternColumn, | ||
'fullReference' | ||
> = { | ||
type: 'derivative', | ||
priority: 1, | ||
displayName: i18n.translate('xpack.lens.indexPattern.derivative', { | ||
defaultMessage: 'Differences', | ||
}), | ||
input: 'fullReference', | ||
selectionStyle: 'full', | ||
requiredReferences: [ | ||
{ | ||
input: ['field'], | ||
validateMetadata: (meta) => meta.dataType === 'number' && !meta.isBucketed, | ||
}, | ||
], | ||
getPossibleOperation: () => { | ||
return { | ||
dataType: 'number', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
}; | ||
}, | ||
getDefaultLabel: (column, indexPattern, columns) => { | ||
return ofName(columns[column.references[0]]?.label); | ||
}, | ||
toExpression: (layer, columnId) => { | ||
return dateBasedOperationToExpression(layer, columnId, 'derivative'); | ||
}, | ||
buildColumn: ({ referenceIds, previousColumn, layer }) => { | ||
const metric = layer.columns[referenceIds[0]]; | ||
return { | ||
label: ofName(metric?.label), | ||
dataType: 'number', | ||
operationType: 'derivative', | ||
isBucketed: false, | ||
scale: 'ratio', | ||
references: referenceIds, | ||
params: | ||
previousColumn?.dataType === 'number' && | ||
previousColumn.params && | ||
'format' in previousColumn.params && | ||
previousColumn.params.format | ||
? { format: previousColumn.params.format } | ||
: undefined, | ||
}; | ||
}, | ||
isTransferable: (column, newIndexPattern) => { | ||
return hasDateField(newIndexPattern); | ||
}, | ||
getErrorMessage: (layer: IndexPatternLayer) => { | ||
return checkForDateHistogram( | ||
layer, | ||
i18n.translate('xpack.lens.indexPattern.derivative', { | ||
defaultMessage: 'Differences', | ||
}) | ||
); | ||
}, | ||
}; |
10 changes: 10 additions & 0 deletions
10
.../plugins/lens/public/indexpattern_datasource/operations/definitions/calculations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { counterRateOperation, CounterRateIndexPatternColumn } from './counter_rate'; | ||
export { cumulativeSumOperation, CumulativeSumIndexPatternColumn } from './cumulative_sum'; | ||
export { derivativeOperation, DerivativeIndexPatternColumn } from './derivative'; | ||
export { movingAverageOperation, MovingAverageIndexPatternColumn } from './moving_average'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are we expecting this to be
Cumulative sum of <field>
? It's currentlyCumulative 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.
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.
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