Search in sources :

Example 1 with ObjectGroupByResultHolder

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);
    }
}
Also used : ObjectGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder) IntObjectPair(com.linkedin.pinot.common.utils.Pairs.IntObjectPair) ObjectGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder) GroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder) ArrayList(java.util.ArrayList) Pairs(com.linkedin.pinot.common.utils.Pairs) AvgPair(com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair)

Aggregations

Pairs (com.linkedin.pinot.common.utils.Pairs)1 IntObjectPair (com.linkedin.pinot.common.utils.Pairs.IntObjectPair)1 AvgPair (com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair)1 GroupByResultHolder (com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder)1 ObjectGroupByResultHolder (com.linkedin.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder)1 ArrayList (java.util.ArrayList)1