-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lens should register expression functions in setup contract (#110639)
* lens should register expression functions in setup contract Closes: #106510 * fix CI * build optimization * build optimizations - step 3 * fix CI * try to optimize bundle * Update x-pack/plugins/lens/common/expressions/time_scale/types.ts Co-authored-by: Marta Bondyra <[email protected]> * Update types.ts Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Marta Bondyra <[email protected]>
- Loading branch information
1 parent
b7014c9
commit 0ca1c89
Showing
60 changed files
with
883 additions
and
758 deletions.
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
54 changes: 54 additions & 0 deletions
54
x-pack/plugins/lens/common/expressions/counter_rate/counter_rate_fn.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,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
buildResultColumns, | ||
getBucketIdentifier, | ||
} from '../../../../../../src/plugins/expressions/common'; | ||
import type { CounterRateExpressionFunction } from './types'; | ||
|
||
export const counterRateFn: CounterRateExpressionFunction['fn'] = ( | ||
input, | ||
{ by, inputColumnId, outputColumnId, outputColumnName } | ||
) => { | ||
const resultColumns = buildResultColumns(input, outputColumnId, inputColumnId, outputColumnName); | ||
|
||
if (!resultColumns) { | ||
return input; | ||
} | ||
const previousValues: Partial<Record<string, number>> = {}; | ||
|
||
return { | ||
...input, | ||
columns: resultColumns, | ||
rows: input.rows.map((row) => { | ||
const newRow = { ...row }; | ||
|
||
const bucketIdentifier = getBucketIdentifier(row, by); | ||
const previousValue = previousValues[bucketIdentifier]; | ||
const currentValue = newRow[inputColumnId]; | ||
if (currentValue != null && previousValue != null) { | ||
const currentValueAsNumber = Number(currentValue); | ||
if (currentValueAsNumber >= previousValue) { | ||
newRow[outputColumnId] = currentValueAsNumber - previousValue; | ||
} else { | ||
newRow[outputColumnId] = currentValueAsNumber; | ||
} | ||
} else { | ||
newRow[outputColumnId] = undefined; | ||
} | ||
|
||
if (currentValue != null) { | ||
previousValues[bucketIdentifier] = Number(currentValue); | ||
} else { | ||
previousValues[bucketIdentifier] = undefined; | ||
} | ||
|
||
return newRow; | ||
}), | ||
}; | ||
}; |
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
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/lens/common/expressions/counter_rate/types.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,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { Datatable, ExpressionFunctionDefinition } from '../../../../../../src/plugins/expressions'; | ||
import { CounterRateArgs } from './index'; | ||
|
||
export type CounterRateExpressionFunction = ExpressionFunctionDefinition< | ||
'lens_counter_rate', | ||
Datatable, | ||
CounterRateArgs, | ||
Datatable | Promise<Datatable> | ||
>; |
Oops, something went wrong.