Skip to content

Commit

Permalink
[TSVB2Lens] Use pick_max instead of clamp for positive only (#133460)
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula authored Jun 3, 2022
1 parent 14ba9b3 commit cf02fe8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('getSeries', () => {
fieldName: 'document',
isFullReference: true,
params: {
formula: 'clamp(max(day_of_week_i), 0, max(day_of_week_i))',
formula: 'pick_max(max(day_of_week_i), 0)',
},
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,20 @@ export const getSiblingPipelineSeriesFormula = (
// support nested aggs with formula
const additionalSubFunction = metrics.find((metric) => metric.id === subMetricField);
let formula = `${aggregationMap.name}(`;
let minMax = '';
let minimumValue = '';
if (currentMetric.type === 'positive_only') {
minimumValue = `, 0`;
}
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}(${
additionalSubFunctionField ?? ''
}))${minMax})`;
}))${minimumValue})`;
} else {
let additionalFunctionArgs;
// handle percentile and percentile_rank
Expand All @@ -246,14 +244,9 @@ export const getSiblingPipelineSeriesFormula = (
if (pipelineAggMap.name === 'percentile_rank' && nestedMetaValue) {
additionalFunctionArgs = `, value=${nestedMetaValue}`;
}
if (currentMetric.type === 'positive_only') {
minMax = `, 0, ${pipelineAggMap.name}(${subMetricField ?? ''}${
additionalFunctionArgs ? `${additionalFunctionArgs}` : ''
})`;
}
formula += `${pipelineAggMap.name}(${subMetricField ?? ''}${
additionalFunctionArgs ? `${additionalFunctionArgs}` : ''
})${minMax})`;
})${minimumValue})`;
}
return formula;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const SUPPORTED_METRICS: { [key: string]: AggOptions } = {
isFullReference: true,
},
positive_only: {
name: 'clamp',
name: 'pick_max',
isFullReference: true,
},
static: {
Expand Down

0 comments on commit cf02fe8

Please sign in to comment.