Skip to content

Commit

Permalink
Add test for edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Feb 11, 2021
1 parent c40eedf commit cfad77d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
7 changes: 6 additions & 1 deletion x-pack/plugins/lens/server/routes/field_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ export async function getNumberHistogram(
sampledValues: minMaxResult.aggregations!.sample.sample_count.value!,
sampledDocuments: minMaxResult.aggregations!.sample.doc_count,
topValues: topValuesBuckets,
histogram: { buckets: [] },
histogram: useTopHits
? { buckets: [] }
: {
// Insert a fake bucket for a single-value histogram
buckets: [{ count: minMaxResult.aggregations!.sample.doc_count, key: minValue }],
},
};
}

Expand Down
34 changes: 29 additions & 5 deletions x-pack/test/api_integration/apis/lens/field_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export default ({ getService }: FtrProviderContext) => {
key: 0.47000000000000003,
},
{
count: 556,
count: 454,
key: 0.9400000000000001,
},
{
Expand All @@ -396,7 +396,7 @@ export default ({ getService }: FtrProviderContext) => {
key: 2.8200000000000003,
},
{
count: 596,
count: 391,
key: 3.29,
},
{
Expand All @@ -408,15 +408,39 @@ export default ({ getService }: FtrProviderContext) => {
key: 4.23,
},
{
count: 639,
count: 628,
key: 4.7,
},
],
},
sampledDocuments: 7,
sampledValues: 4151,
sampledValues: 3833,
totalDocuments: 7,
topValues: [],
topValues: { buckets: [] },
});
});

it('should return a single-value histogram when filtering a precalculated histogram', async () => {
const { body } = await supertest
.post('/api/lens/index_stats/histogram-test/field')
.set(COMMON_HEADERS)
.send({
dslQuery: { match: { 'histogram-title': 'single value' } },
fromDate: TEST_START_TIME,
toDate: TEST_END_TIME,
field: {
name: 'histogram-content',
type: 'histogram',
},
})
.expect(200);

expect(body).to.eql({
histogram: { buckets: [{ count: 1, key: 1 }] },
sampledDocuments: 1,
sampledValues: 1,
totalDocuments: 1,
topValues: { buckets: [] },
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

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

it('with median aggregation', async () => {
Expand All @@ -79,7 +79,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('with sum aggregation', async () => {
const data = await renderTableForAggregation('Sum');
expect(data).to.eql([['11834.800000000001']]);
expect(data).to.eql([['10983']]);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,23 @@
}
}
}
}
}

{
"type": "doc",
"value": {
"id": "5e694159d909d9d99b5e12d1",
"index": "histogram-test",
"source": {
"histogram-title": "single value",
"histogram-content": {
"values": [
1
],
"counts": [
1
]
}
}
}
}

0 comments on commit cfad77d

Please sign in to comment.