Search in sources :

Example 1 with NoDictionarySingleColumnGroupKeyGenerator

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

the class NoDictionaryGroupKeyGeneratorTest method testGroupKeyGenerator.

private void testGroupKeyGenerator(String[] groupByColumns, FieldSpec.DataType[] dataTypes) throws Exception {
    // Build the projection operator.
    MatchEntireSegmentOperator matchEntireSegmentOperator = new MatchEntireSegmentOperator(NUM_ROWS);
    BReusableFilteredDocIdSetOperator docIdSetOperator = new BReusableFilteredDocIdSetOperator(matchEntireSegmentOperator, NUM_ROWS, 10000);
    MProjectionOperator projectionOperator = new MProjectionOperator(_dataSourceMap, docIdSetOperator);
    TransformExpressionOperator transformOperator = new TransformExpressionOperator(projectionOperator, new ArrayList<TransformExpressionTree>());
    // Iterator over all projection blocks and generate group keys.
    TransformBlock transformBlock;
    int[] docIdToGroupKeys = new int[DocIdSetPlanNode.MAX_DOC_PER_CALL];
    GroupKeyGenerator groupKeyGenerator = null;
    while ((transformBlock = (TransformBlock) transformOperator.nextBlock()) != null) {
        if (groupKeyGenerator == null) {
            // Build the group key generator.
            groupKeyGenerator = (groupByColumns.length == 1) ? new NoDictionarySingleColumnGroupKeyGenerator(groupByColumns[0], dataTypes[0]) : new NoDictionaryMultiColumnGroupKeyGenerator(transformBlock, groupByColumns);
        }
        groupKeyGenerator.generateKeysForBlock(transformBlock, docIdToGroupKeys);
    }
    // Assert total number of group keys is as expected
    Assert.assertTrue(groupKeyGenerator != null);
    Set<String> expectedGroupKeys = getExpectedGroupKeys(_recordReader, groupByColumns);
    Assert.assertEquals(groupKeyGenerator.getCurrentGroupKeyUpperBound(), expectedGroupKeys.size(), "Number of group keys mis-match.");
    // Assert all group key values are as expected
    Iterator<GroupKeyGenerator.GroupKey> uniqueGroupKeys = groupKeyGenerator.getUniqueGroupKeys();
    while (uniqueGroupKeys.hasNext()) {
        GroupKeyGenerator.GroupKey groupKey = uniqueGroupKeys.next();
        String actual = groupKey.getStringKey();
        Assert.assertTrue(expectedGroupKeys.contains(actual), "Unexpected group key: " + actual);
    }
}
Also used : TransformExpressionOperator(com.linkedin.pinot.core.operator.transform.TransformExpressionOperator) MProjectionOperator(com.linkedin.pinot.core.operator.MProjectionOperator) MatchEntireSegmentOperator(com.linkedin.pinot.core.operator.filter.MatchEntireSegmentOperator) TransformBlock(com.linkedin.pinot.core.operator.blocks.TransformBlock) NoDictionarySingleColumnGroupKeyGenerator(com.linkedin.pinot.core.query.aggregation.groupby.NoDictionarySingleColumnGroupKeyGenerator) BReusableFilteredDocIdSetOperator(com.linkedin.pinot.core.operator.BReusableFilteredDocIdSetOperator) TransformExpressionTree(com.linkedin.pinot.common.request.transform.TransformExpressionTree) NoDictionaryMultiColumnGroupKeyGenerator(com.linkedin.pinot.core.query.aggregation.groupby.NoDictionaryMultiColumnGroupKeyGenerator) NoDictionarySingleColumnGroupKeyGenerator(com.linkedin.pinot.core.query.aggregation.groupby.NoDictionarySingleColumnGroupKeyGenerator) NoDictionaryMultiColumnGroupKeyGenerator(com.linkedin.pinot.core.query.aggregation.groupby.NoDictionaryMultiColumnGroupKeyGenerator) GroupKeyGenerator(com.linkedin.pinot.core.query.aggregation.groupby.GroupKeyGenerator)

Aggregations

TransformExpressionTree (com.linkedin.pinot.common.request.transform.TransformExpressionTree)1 BReusableFilteredDocIdSetOperator (com.linkedin.pinot.core.operator.BReusableFilteredDocIdSetOperator)1 MProjectionOperator (com.linkedin.pinot.core.operator.MProjectionOperator)1 TransformBlock (com.linkedin.pinot.core.operator.blocks.TransformBlock)1 MatchEntireSegmentOperator (com.linkedin.pinot.core.operator.filter.MatchEntireSegmentOperator)1 TransformExpressionOperator (com.linkedin.pinot.core.operator.transform.TransformExpressionOperator)1 GroupKeyGenerator (com.linkedin.pinot.core.query.aggregation.groupby.GroupKeyGenerator)1 NoDictionaryMultiColumnGroupKeyGenerator (com.linkedin.pinot.core.query.aggregation.groupby.NoDictionaryMultiColumnGroupKeyGenerator)1 NoDictionarySingleColumnGroupKeyGenerator (com.linkedin.pinot.core.query.aggregation.groupby.NoDictionarySingleColumnGroupKeyGenerator)1