Skip to content

Commit

Permalink
[BUG] fix median.ts to work for scripted field (#1302) (#1325)
Browse files Browse the repository at this point in the history
Fix PR comment to replace unused agg to _
remove write function

Issue Resolved: #1296

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: Anan <79961084+ananzh@users.noreply.github.com>
(cherry picked from commit 48eec83)

Co-authored-by: Anan <79961084+ananzh@users.noreply.github.com>
  • Loading branch information
opensearch-trigger-bot[bot] and ananzh authored Mar 8, 2022
1 parent d6a84ac commit e02179b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/plugins/data/common/search/aggs/metrics/median.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,41 @@ describe('AggTypeMetricMedianProvider class', () => {
})
).toEqual(10);
});

it('supports scripted fields', () => {
const typesRegistry = mockAggTypesRegistry();
const field = {
name: 'bytes',
scripted: true,
language: 'painless',
script: 'return 456',
};
const indexPattern = {
id: '1234',
title: 'logstash-*',
fields: {
getByName: () => field,
filter: () => [field],
},
} as any;

aggConfigs = new AggConfigs(
indexPattern,
[
{
id: METRIC_TYPES.MEDIAN,
type: METRIC_TYPES.MEDIAN,
schema: 'metric',
params: {
field: 'bytes',
},
},
],
{
typesRegistry,
}
);

expect(aggConfigs.toDsl()).toMatchSnapshot();
});
});
8 changes: 4 additions & 4 deletions src/plugins/data/common/search/aggs/metrics/median.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export const getMedianMetricAgg = () => {
name: 'field',
type: 'field',
filterFieldTypes: [OSD_FIELD_TYPES.NUMBER, OSD_FIELD_TYPES.DATE, OSD_FIELD_TYPES.HISTOGRAM],
write(agg, output) {
output.params.field = agg.getParam('field').name;
output.params.percents = [50];
},
},
{
name: 'percents',
default: [50],
},
],
getValue(agg, bucket) {
Expand Down

0 comments on commit e02179b

Please sign in to comment.