Skip to content

Commit 13c663b

Browse files
committed
Updated tests
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
1 parent e124eb1 commit 13c663b

File tree

2 files changed

+7
-51
lines changed

2 files changed

+7
-51
lines changed

server/src/main/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ private InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws
277277
spare = ordered.insertWithOverflow(spare);
278278
}
279279
// Get the top buckets
280-
B[] bucketsForOrd = buildBuckets(ordered.size());
281-
topBucketsPerOrd[ordIdx] = bucketsForOrd;
280+
topBucketsPerOrd[ordIdx] = buildBuckets(ordered.size());
282281
if (isKeyOrder(order)) {
283282
for (int b = ordered.size() - 1; b >= 0; --b) {
284283
topBucketsPerOrd[ordIdx][b] = ordered.pop();

server/src/test/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregatorTests.java

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ private void testSearchCase(
196196
}
197197
}
198198

199-
public void testBuildAggregationsForHeapSort() throws IOException {
199+
public void testBuildAggregationAlgorithmSelection() throws IOException {
200200
List<Long> dataSet = new ArrayList<>();
201-
for (long i = 0; i < 150; i++) {
201+
for (long i = 0; i < 100; i++) {
202202
dataSet.add(i);
203203
}
204204

205+
// HeapSort
205206
testSearchCase(new MatchAllDocsQuery(), dataSet, aggregation -> aggregation.field(LONG_FIELD).size(2), agg -> {
206207
assertEquals(2, agg.getBuckets().size());
207208
for (int i = 0; i < 2; i++) {
@@ -210,59 +211,15 @@ public void testBuildAggregationsForHeapSort() throws IOException {
210211
assertThat(bucket.getDocCount(), equalTo(1L));
211212
}
212213
}, ValueType.NUMERIC);
213-
}
214-
215-
public void testBuildAggregationsForQuickSelect() throws IOException {
216-
List<Long> dataSet = new ArrayList<>();
217-
for (long i = 0; i < 150; i++) {
218-
dataSet.add(i);
219-
}
220214

221-
testSearchCase(new MatchAllDocsQuery(), dataSet, aggregation -> aggregation.field(LONG_FIELD).size(50), agg -> {
222-
assertEquals(50, agg.getBuckets().size());
215+
// QuickSelect
216+
testSearchCase(new MatchAllDocsQuery(), dataSet, aggregation -> aggregation.field(LONG_FIELD).size(20), agg -> {
217+
assertEquals(20, agg.getBuckets().size());
223218
for (int i = 0; i < agg.getBuckets().size(); i++) {
224219
LongTerms.Bucket bucket = (LongTerms.Bucket) agg.getBuckets().get(i);
225220
assertThat(bucket.getKey(), equalTo((long) i));
226221
assertThat(bucket.getDocCount(), equalTo(1L));
227222
}
228223
}, ValueType.NUMERIC);
229224
}
230-
231-
public void testKeyOrderingAlgorithmSelection() throws IOException {
232-
List<Long> dataset = new ArrayList<>();
233-
for (long i = 100; i > 0; i--) {
234-
dataset.add(i);
235-
}
236-
237-
testSearchCase(
238-
new MatchAllDocsQuery(),
239-
dataset,
240-
aggregation -> aggregation.field(LONG_FIELD).size(50).order(org.opensearch.search.aggregations.BucketOrder.key(true)),
241-
agg -> {
242-
assertEquals(50, agg.getBuckets().size());
243-
for (int i = 0; i < 50; i++) {
244-
LongTerms.Bucket bucket = (LongTerms.Bucket) agg.getBuckets().get(i);
245-
assertThat(bucket.getKey(), equalTo(i + 1L));
246-
assertThat(bucket.getDocCount(), equalTo(1L));
247-
}
248-
},
249-
ValueType.NUMERIC
250-
);
251-
252-
testSearchCase(
253-
new MatchAllDocsQuery(),
254-
dataset,
255-
aggregation -> aggregation.field(LONG_FIELD).size(5).order(org.opensearch.search.aggregations.BucketOrder.key(false)),
256-
agg -> {
257-
assertEquals(5, agg.getBuckets().size());
258-
for (int i = 0; i < agg.getBuckets().size(); i++) {
259-
LongTerms.Bucket bucket = (LongTerms.Bucket) agg.getBuckets().get(i);
260-
assertThat(bucket.getKey(), equalTo(100L - i));
261-
assertThat(bucket.getDocCount(), equalTo(1L));
262-
}
263-
},
264-
ValueType.NUMERIC
265-
);
266-
}
267-
268225
}

0 commit comments

Comments
 (0)