mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[TSVB2Lens] Supports positive only as clamp (#125771)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
077b4e0de0
commit
53c5a42d60
4 changed files with 55 additions and 5 deletions
|
@ -84,6 +84,32 @@ describe('getSeries', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('should return the correct formula config for a positive only function', () => {
|
||||
const metric = [
|
||||
{
|
||||
field: 'day_of_week_i',
|
||||
id: '123456',
|
||||
type: 'max',
|
||||
},
|
||||
{
|
||||
id: '891011',
|
||||
type: 'positive_only',
|
||||
field: '123456',
|
||||
},
|
||||
] as Metric[];
|
||||
const config = getSeries(metric);
|
||||
expect(config).toStrictEqual([
|
||||
{
|
||||
agg: 'formula',
|
||||
fieldName: 'document',
|
||||
isFullReference: true,
|
||||
params: {
|
||||
formula: 'clamp(max(day_of_week_i), 0, max(day_of_week_i))',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('should return the correct config for the cumulative sum on count', () => {
|
||||
const metric = [
|
||||
{
|
||||
|
|
|
@ -125,6 +125,14 @@ export const getSeries = (metrics: Metric[]): VisualizeEditorLayersContext['metr
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'positive_only': {
|
||||
const formula = getSiblingPipelineSeriesFormula(aggregation, metrics[metricIdx], metrics);
|
||||
if (!formula) {
|
||||
return null;
|
||||
}
|
||||
metricsArray = getFormulaSeries(formula) as VisualizeEditorLayersContext['metrics'];
|
||||
break;
|
||||
}
|
||||
case 'avg_bucket':
|
||||
case 'max_bucket':
|
||||
case 'min_bucket':
|
||||
|
|
|
@ -192,20 +192,31 @@ export const getSiblingPipelineSeriesFormula = (
|
|||
return null;
|
||||
}
|
||||
const aggregationMap = SUPPORTED_METRICS[aggregation];
|
||||
const subMetricField = subFunctionMetric.field;
|
||||
const subMetricField = subFunctionMetric.type !== 'count' ? subFunctionMetric.field : '';
|
||||
// support nested aggs with formula
|
||||
const additionalSubFunction = metrics.find((metric) => metric.id === subMetricField);
|
||||
let formula = `${aggregationMap.name}(`;
|
||||
let minMax = '';
|
||||
if (additionalSubFunction) {
|
||||
const additionalPipelineAggMap = SUPPORTED_METRICS[additionalSubFunction.type];
|
||||
if (!additionalPipelineAggMap) {
|
||||
return null;
|
||||
}
|
||||
const additionalSubFunctionField =
|
||||
additionalSubFunction.type !== 'count' ? additionalSubFunction.field : '';
|
||||
if (currentMetric.type === 'positive_only') {
|
||||
minMax = `, 0, ${pipelineAggMap.name}(${additionalPipelineAggMap.name}(${
|
||||
additionalSubFunctionField ?? ''
|
||||
}))`;
|
||||
}
|
||||
formula += `${pipelineAggMap.name}(${additionalPipelineAggMap.name}(${
|
||||
additionalSubFunction.field ?? ''
|
||||
})))`;
|
||||
additionalSubFunctionField ?? ''
|
||||
}))${minMax})`;
|
||||
} else {
|
||||
formula += `${pipelineAggMap.name}(${subFunctionMetric.field ?? ''}))`;
|
||||
if (currentMetric.type === 'positive_only') {
|
||||
minMax = `, 0, ${pipelineAggMap.name}(${subMetricField ?? ''})`;
|
||||
}
|
||||
formula += `${pipelineAggMap.name}(${subMetricField ?? ''})${minMax})`;
|
||||
}
|
||||
return formula;
|
||||
};
|
||||
|
@ -262,7 +273,8 @@ export const getFormulaEquivalent = (
|
|||
case 'avg_bucket':
|
||||
case 'max_bucket':
|
||||
case 'min_bucket':
|
||||
case 'sum_bucket': {
|
||||
case 'sum_bucket':
|
||||
case 'positive_only': {
|
||||
return getSiblingPipelineSeriesFormula(currentMetric.type, currentMetric, metrics);
|
||||
}
|
||||
case 'count': {
|
||||
|
|
|
@ -84,4 +84,8 @@ export const SUPPORTED_METRICS: { [key: string]: AggOptions } = {
|
|||
name: 'formula',
|
||||
isFullReference: true,
|
||||
},
|
||||
positive_only: {
|
||||
name: 'clamp',
|
||||
isFullReference: true,
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue