Search in sources :

Example 11 with AvgPair

use of com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair in project pinot by linkedin.

the class InnerSegmentAggregationSingleValueQueriesTest method testLargeAggregationGroupBy.

@Test
public void testLargeAggregationGroupBy() {
    String query = "SELECT" + AGGREGATION + " FROM testTable" + LARGE_GROUP_BY;
    // NOTE: here we assume the first group key returned from the iterator is constant.
    // Test query without filter.
    AggregationGroupByOperator aggregationGroupByOperator = getOperatorForQuery(query);
    IntermediateResultsBlock resultsBlock = (IntermediateResultsBlock) aggregationGroupByOperator.nextBlock();
    ExecutionStatistics executionStatistics = aggregationGroupByOperator.getExecutionStatistics();
    Assert.assertEquals(executionStatistics.getNumDocsScanned(), 30000L);
    Assert.assertEquals(executionStatistics.getNumEntriesScannedInFilter(), 0L);
    Assert.assertEquals(executionStatistics.getNumEntriesScannedPostFilter(), 270000L);
    Assert.assertEquals(executionStatistics.getNumTotalRawDocs(), 30000L);
    AggregationGroupByResult aggregationGroupByResult = resultsBlock.getAggregationGroupByResult();
    GroupKeyGenerator.GroupKey firstGroupKey = aggregationGroupByResult.getGroupKeyIterator().next();
    Assert.assertEquals(firstGroupKey.getStringKey(), "1784773968\t204243323\t628170461\t1985159279\t296467636\tP\tHEuxNvH\t402773817\t2047180536");
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 0)).longValue(), 1L);
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 1)).longValue(), 1784773968L);
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 2)).intValue(), 204243323);
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 3)).intValue(), 628170461);
    AvgPair avgResult = (AvgPair) aggregationGroupByResult.getResultForKey(firstGroupKey, 4);
    Assert.assertEquals((long) avgResult.getSum(), 1985159279L);
    Assert.assertEquals(avgResult.getCount(), 1L);
    // Test query with filter.
    aggregationGroupByOperator = getOperatorForQueryWithFilter(query);
    resultsBlock = (IntermediateResultsBlock) aggregationGroupByOperator.nextBlock();
    executionStatistics = aggregationGroupByOperator.getExecutionStatistics();
    Assert.assertEquals(executionStatistics.getNumDocsScanned(), 6129L);
    Assert.assertEquals(executionStatistics.getNumEntriesScannedInFilter(), 84134L);
    Assert.assertEquals(executionStatistics.getNumEntriesScannedPostFilter(), 55161L);
    Assert.assertEquals(executionStatistics.getNumTotalRawDocs(), 30000L);
    aggregationGroupByResult = resultsBlock.getAggregationGroupByResult();
    firstGroupKey = aggregationGroupByResult.getGroupKeyIterator().next();
    Assert.assertEquals(firstGroupKey.getStringKey(), "1361199163\t178133991\t296467636\t788414092\t1719301234\tP\tMaztCmmxxgguBUxPti\t1284373442\t752388855");
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 0)).longValue(), 1L);
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 1)).longValue(), 1361199163L);
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 2)).intValue(), 178133991);
    Assert.assertEquals(((Number) aggregationGroupByResult.getResultForKey(firstGroupKey, 3)).intValue(), 296467636);
    avgResult = (AvgPair) aggregationGroupByResult.getResultForKey(firstGroupKey, 4);
    Assert.assertEquals((long) avgResult.getSum(), 788414092L);
    Assert.assertEquals(avgResult.getCount(), 1L);
}
Also used : ExecutionStatistics(com.linkedin.pinot.core.operator.ExecutionStatistics) AggregationGroupByOperator(com.linkedin.pinot.core.operator.query.AggregationGroupByOperator) IntermediateResultsBlock(com.linkedin.pinot.core.operator.blocks.IntermediateResultsBlock) GroupKeyGenerator(com.linkedin.pinot.core.query.aggregation.groupby.GroupKeyGenerator) AvgPair(com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair) AggregationGroupByResult(com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByResult) Test(org.testng.annotations.Test)

Example 12 with AvgPair

use of com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair in project pinot by linkedin.

the class IntObjectIndexedPriorityQueueTest method test.

/**
   * Helper method builds the priority queue, randomly updates elements and
   * then asserts the following:
   * <ul>
   *   <li> Elements are popped from the priority queue in the expected order. </li>
   *   <li> Size of the priority queue is as expected (after elements are updated). </li>
   * </ul>
   * @param minHeap Min mode
   */
public void test(boolean minHeap) {
    Random random = new Random(0);
    IntObjectIndexedPriorityQueue<AvgPair> pq = new IntObjectIndexedPriorityQueue<>(NUM_RECORDS, minHeap);
    Map<Integer, AvgPair> map = new HashMap<>(NUM_RECORDS);
    // Initialize the priority queue.
    for (int i = 0; i < NUM_RECORDS; i++) {
        // Avoid zeros
        double first = 1 + random.nextInt(INT_VALUE_BOUND);
        Long second = (long) 1 + random.nextInt(INT_VALUE_BOUND);
        AvgPair value = new AvgPair(first, second);
        pq.put(i, value);
        map.put(i, value);
    }
    // Update some records randomly
    for (int i = 0; i < NUM_RECORDS; i++) {
        int key = random.nextInt(NUM_RECORDS);
        // Avoid zeros
        double first = 1 + random.nextInt(INT_VALUE_BOUND);
        Long second = (long) 1 + random.nextInt(INT_VALUE_BOUND);
        AvgPair value = new AvgPair(first, second);
        pq.put(key, value);
        map.put(key, value);
    }
    // Transfer the map into list so it can be sorted.
    List<Pairs.IntObjectPair<AvgPair>> list = new ArrayList<>(NUM_RECORDS);
    for (Map.Entry<Integer, AvgPair> entry : map.entrySet()) {
        list.add(new Pairs.IntObjectPair<>(entry.getKey(), entry.getValue()));
    }
    // Comparison for min heap is the same as that for ascending order.
    boolean descendingOrder = !minHeap;
    Collections.sort(list, new Pairs.IntObjectComparator(descendingOrder));
    // Ensure that elements are popped from priority queue in the expected order.
    int i = 0;
    while (!pq.isEmpty()) {
        Pairs.IntObjectPair<AvgPair> actual = pq.poll();
        Pairs.IntObjectPair<AvgPair> expected = list.get(i++);
        Assert.assertEquals(actual.getIntValue(), expected.getIntValue());
        Assert.assertEquals(actual.getObjectValue(), expected.getObjectValue());
    }
    // Assert that priority queue had expected number of elements.
    Assert.assertEquals(i, list.size());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pairs(com.linkedin.pinot.common.utils.Pairs) AvgPair(com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair) Random(java.util.Random) IntObjectIndexedPriorityQueue(com.linkedin.pinot.core.util.IntObjectIndexedPriorityQueue) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AvgPair (com.linkedin.pinot.core.query.aggregation.function.customobject.AvgPair)12 Test (org.testng.annotations.Test)10 ExecutionStatistics (com.linkedin.pinot.core.operator.ExecutionStatistics)9 IntermediateResultsBlock (com.linkedin.pinot.core.operator.blocks.IntermediateResultsBlock)9 AggregationGroupByOperator (com.linkedin.pinot.core.operator.query.AggregationGroupByOperator)6 AggregationGroupByResult (com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByResult)6 GroupKeyGenerator (com.linkedin.pinot.core.query.aggregation.groupby.GroupKeyGenerator)6 AggregationOperator (com.linkedin.pinot.core.operator.query.AggregationOperator)3 Pairs (com.linkedin.pinot.common.utils.Pairs)2 ArrayList (java.util.ArrayList)2 IntObjectPair (com.linkedin.pinot.common.utils.Pairs.IntObjectPair)1 GroupByResultHolder (com.linkedin.pinot.core.query.aggregation.groupby.GroupByResultHolder)1 ObjectGroupByResultHolder (com.linkedin.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder)1 IntObjectIndexedPriorityQueue (com.linkedin.pinot.core.util.IntObjectIndexedPriorityQueue)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1