use of com.linkedin.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder in project pinot by linkedin.
the class ObjectGroupByResultHolderTest method testTrimResults.
/**
* Helper method for testing trimming of results.
* @param minOrder Min ordering if true, max ordering else.
*/
private void testTrimResults(boolean minOrder) {
GroupByResultHolder resultHolder = new ObjectGroupByResultHolder(INITIAL_CAPACITY, MAX_CAPACITY, INITIAL_CAPACITY, minOrder);
List<IntObjectPair<AvgPair>> expectedIntObjectPairs = new ArrayList<>(MAX_CAPACITY);
for (int i = 0; i < INITIAL_CAPACITY; i++) {
AvgPair avgPair = new AvgPair(RANDOM.nextDouble(), (long) RANDOM.nextInt(100));
IntObjectPair<AvgPair> intObjectPair = new IntObjectPair<>(i, avgPair);
expectedIntObjectPairs.add(intObjectPair);
resultHolder.setValueForKey(i, avgPair);
}
// This will trigger switch from array based storage to map based storage.
resultHolder.ensureCapacity(MAX_CAPACITY);
for (int i = INITIAL_CAPACITY; i < MAX_CAPACITY; i++) {
AvgPair avgPair = new AvgPair(RANDOM.nextDouble(), (long) RANDOM.nextInt(100));
IntObjectPair<AvgPair> intObjectPair = new IntObjectPair<>(i, avgPair);
expectedIntObjectPairs.add(intObjectPair);
resultHolder.setValueForKey(i, avgPair);
}
Collections.sort(expectedIntObjectPairs, new Pairs.IntObjectComparator(!minOrder));
// Trim the results.
Assert.assertEquals(resultHolder.trimResults().length, MAX_CAPACITY - INITIAL_CAPACITY, ERROR_MESSAGE);
// Ensure that all the correct group keys survive after trimming.
for (int i = 0; i < INITIAL_CAPACITY; i++) {
IntObjectPair intObjectPair = expectedIntObjectPairs.get(i);
AvgPair actualAvgPair = resultHolder.getResult(intObjectPair.getIntValue());
AvgPair expectedAvgPair = (AvgPair) intObjectPair.getObjectValue();
Assert.assertEquals(actualAvgPair.getSum(), expectedAvgPair.getSum(), ERROR_MESSAGE);
Assert.assertEquals(actualAvgPair.getCount(), expectedAvgPair.getCount(), ERROR_MESSAGE);
}
}
Aggregations