Skip to content
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

[7.x] Allow histogram fields in average and sum aggregations (#66891) #67077

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/aggs/metrics/avg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getAvgMetricAgg = ({ getInternalStartServices }: AvgMetricAggDepend
{
name: 'field',
type: 'field',
filterFieldTypes: KBN_FIELD_TYPES.NUMBER,
filterFieldTypes: [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.HISTOGRAM],
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/aggs/metrics/sum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const getSumMetricAgg = ({ getInternalStartServices }: SumMetricAggDepend
{
name: 'field',
type: 'field',
filterFieldTypes: KBN_FIELD_TYPES.NUMBER,
filterFieldTypes: [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.HISTOGRAM],
},
],
},
Expand Down
1 change: 1 addition & 0 deletions test/functional/page_objects/visualize_chart_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export function VisualizeChartPageProvider({ getService, getPageObjects }: FtrPr

/**
* If you are writing new tests, you should rather look into getTableVisContent method instead.
* @deprecated Use getTableVisContent instead.
*/
public async getTableVisData() {
return await testSubjects.getVisibleText('paginated-table-body');
Expand Down
73 changes: 49 additions & 24 deletions x-pack/test/functional/apps/visualize/precalculated_histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,62 @@ export default function({ getService, getPageObjects }: FtrProviderContext) {
return esArchiver.unload('pre_calculated_histogram');
});

const initHistogramBarChart = async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVerticalBarChart();
await PageObjects.visualize.clickNewSearch('histogram-test');
await PageObjects.visChart.waitForVisualization();
};

const getFieldOptionsForAggregation = async (aggregation: string): Promise<string[]> => {
await PageObjects.visEditor.clickBucket('Y-axis', 'metrics');
await PageObjects.visEditor.selectAggregation(aggregation, 'metrics');
const fieldValues = await PageObjects.visEditor.getField();
return fieldValues;
};

it('appears correctly in discover', async function() {
await PageObjects.common.navigateToApp('discover');
const rowData = await PageObjects.discover.getDocTableIndex(1);
expect(rowData.includes('"values": [ 0.3, 1, 3, 4.2, 4.8 ]')).to.be.ok();
});

it('appears in the field options of a Percentiles aggregation', async function() {
await initHistogramBarChart();
const fieldValues: string[] = await getFieldOptionsForAggregation('Percentiles');
log.debug('Percentiles Fields = ' + fieldValues);
expect(fieldValues[0]).to.be('histogram-content');
});
describe('works in visualizations', () => {
before(async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch('histogram-test');
await PageObjects.visChart.waitForVisualization();
await PageObjects.visEditor.clickMetricEditor();
});

const renderTableForAggregation = async (aggregation: string) => {
await PageObjects.visEditor.selectAggregation(aggregation, 'metrics');
await PageObjects.visEditor.selectField('histogram-content', 'metrics');
await PageObjects.visEditor.clickGo();

return await PageObjects.visChart.getTableVisContent();
};

it('with percentiles aggregation', async () => {
const data = (await renderTableForAggregation('Percentiles')) as string[][];
expect(data[0]).to.have.property('length', 7);
// Percentile values are not deterministic, so we can't check for the exact values here,
// but just check they are all within the given range
// see https://github.com/elastic/elasticsearch/issues/49225
expect(data[0].every((p: string) => Number(p) >= 0.3 && Number(p) <= 5)).to.be(true);
});

it('with percentile ranks aggregation', async () => {
const data = await renderTableForAggregation('Percentile Ranks');
expect(data).to.eql([['0%']]);
});

it('with average aggregation', async () => {
const data = await renderTableForAggregation('Average');
expect(data).to.eql([['2.8510720308359434']]);
});

it('with median aggregation', async () => {
// Percentile values (which are used by median behind the scenes) are not deterministic,
// so we can't check for the exact values here, but just check they are all within the given range
// see https://github.com/elastic/elasticsearch/issues/49225
const data = await renderTableForAggregation('Median');
const value = Number(data[0][0]);
expect(value).to.be.above(3.0);
expect(value).to.be.below(3.3);
});

it('appears in the field options of a Percentile Ranks aggregation', async function() {
const fieldValues: string[] = await getFieldOptionsForAggregation('Percentile Ranks');
log.debug('Percentile Ranks Fields = ' + fieldValues);
expect(fieldValues[0]).to.be('histogram-content');
it('with sum aggregation', async () => {
const data = await renderTableForAggregation('Sum');
expect(data).to.eql([['11834.800000000001']]);
});
});
});
}