Search in sources :

Example 1 with GroupByResultHolder

use of com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder in project pinot by linkedin.

the class DoubleGroupByResultHolderTest method testTrimResults.

/**
   * Helper method for testing trim results.
   * Sets a max size on the result holder and adds more values than the max size of the result holder.
   * Then asserts that the right results survive after trimming.
   *
   * @param minOrder
   */
void testTrimResults(final boolean minOrder) {
    GroupByResultHolder resultHolder = new DoubleGroupByResultHolder(INITIAL_CAPACITY, MAX_CAPACITY, INITIAL_CAPACITY, DEFAULT_VALUE, minOrder);
    List<IntDoublePair> expected = new ArrayList<>(MAX_CAPACITY);
    for (int i = 0; i < INITIAL_CAPACITY; i++) {
        resultHolder.setValueForKey(i, _expected[i]);
        expected.add(new IntDoublePair(i, _expected[i]));
    }
    // This will trigger the transition from array based to map based storage within the result holder.
    resultHolder.ensureCapacity(MAX_CAPACITY);
    for (int i = INITIAL_CAPACITY; i < MAX_CAPACITY; i++) {
        resultHolder.setValueForKey(i, _expected[i]);
        expected.add(new IntDoublePair(i, _expected[i]));
    }
    // Trim the results.
    resultHolder.trimResults();
    // Sort the input
    Collections.sort(expected, new IntDoubleComparator(!minOrder));
    // Ensure that all the correct group keys survive after trimming.
    for (int i = 0; i < INITIAL_CAPACITY; i++) {
        IntDoublePair pair = expected.get(i);
        Assert.assertEquals(resultHolder.getDoubleResult(pair.getIntValue()), pair.getDoubleValue());
    }
}
Also used : IntDoublePair(com.linkedin.pinot.common.utils.Pairs.IntDoublePair) GroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder) DoubleGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.DoubleGroupByResultHolder) DoubleGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.DoubleGroupByResultHolder) ArrayList(java.util.ArrayList) IntDoubleComparator(com.linkedin.pinot.common.utils.Pairs.IntDoubleComparator)

Example 2 with GroupByResultHolder

use of com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder in project pinot by linkedin.

the class DoubleGroupByResultHolderTest method testSetValueForKey.

/**
   * This test is for the GroupByResultHolder.SetValueForKey() api.
   * - Sets a random set of values in the result holder.
   * - Asserts that the values returned by the result holder are as expected.
   */
@Test
void testSetValueForKey() {
    GroupByResultHolder resultHolder = new DoubleGroupByResultHolder(INITIAL_CAPACITY, MAX_CAPACITY, MAX_CAPACITY, DEFAULT_VALUE);
    for (int i = 0; i < INITIAL_CAPACITY; i++) {
        resultHolder.setValueForKey(i, _expected[i]);
    }
    testValues(resultHolder, _expected, 0, INITIAL_CAPACITY);
}
Also used : GroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder) DoubleGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.DoubleGroupByResultHolder) DoubleGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.DoubleGroupByResultHolder) Test(org.testng.annotations.Test)

Example 3 with GroupByResultHolder

use of com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder in project pinot by linkedin.

the class DoubleGroupByResultHolderTest method testEnsureCapacity.

/**
   * This test is for the GroupByResultHolder.EnsureCapacity api.
   * - Fills the the result holder with a set of values.
   * - Calls ensureCapacity to expand the result holder size.
   * - Checks that the expanded unfilled portion of the result holder contains {@ref #DEFAULT_VALUE}
   * - Fills the rest of the resultHolder, and ensures all values are returned as expected.
   */
@Test
void testEnsureCapacity() {
    GroupByResultHolder resultHolder = new DoubleGroupByResultHolder(INITIAL_CAPACITY, MAX_CAPACITY, MAX_CAPACITY, DEFAULT_VALUE);
    for (int i = 0; i < INITIAL_CAPACITY; i++) {
        resultHolder.setValueForKey(i, _expected[i]);
    }
    resultHolder.ensureCapacity(MAX_CAPACITY);
    for (int i = INITIAL_CAPACITY; i < MAX_CAPACITY; i++) {
        double actual = resultHolder.getDoubleResult(i);
        Assert.assertEquals(actual, DEFAULT_VALUE, "Default Value mis-match: Actual: " + actual + " Expected: " + DEFAULT_VALUE + " Random seed: " + RANDOM_SEED);
        resultHolder.setValueForKey(i, _expected[i]);
    }
    testValues(resultHolder, _expected, 0, MAX_CAPACITY);
}
Also used : GroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder) DoubleGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.DoubleGroupByResultHolder) DoubleGroupByResultHolder(com.linkedin.pinot.core.query.aggregation.groupby.DoubleGroupByResultHolder) Test(org.testng.annotations.Test)

Example 4 with GroupByResultHolder

use of com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder 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

GroupByResultHolder (com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder)4 DoubleGroupByResultHolder (com.linkedin.pinot.core.query.aggregation.groupby.DoubleGroupByResultHolder)3 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 Pairs (com.linkedin.pinot.common.utils.Pairs)1 IntDoubleComparator (com.linkedin.pinot.common.utils.Pairs.IntDoubleComparator)1 IntDoublePair (com.linkedin.pinot.common.utils.Pairs.IntDoublePair)1 IntObjectPair (com.linkedin.pinot.common.utils.Pairs.IntObjectPair)1 AvgPair (com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair)1 ObjectGroupByResultHolder (com.linkedin.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder)1