Package com.facebook.presto.operator.AggregationOperator

Examples of com.facebook.presto.operator.AggregationOperator.Aggregator


        assertEquals(estimateCountPartial(values, field), expectedCount);
    }

    private long estimateCount(List<Object> values, int field)
    {
        Aggregator aggregator = createAggregator(aggregation(getAggregationFunction(), new Input(0, field)), AggregationNode.Step.SINGLE);

        if (!values.isEmpty()) {
            BlockCursor cursor = createBlock(values, field + 1).cursor();
            while (cursor.advanceNextPosition()) {
                aggregator.addValue(cursor);
            }
        }

        return (long) BlockAssertions.toValues(aggregator.getResult()).get(0).get(0);
    }
View Full Code Here


        return (long) BlockAssertions.toValues(aggregator.getResult()).get(0).get(0);
    }

    private long estimateCountVectorized(List<Object> values, int field)
    {
        Aggregator aggregator = createAggregator(aggregation(getAggregationFunction(), new Input(0, field)), AggregationNode.Step.SINGLE);

        if (!values.isEmpty()) {
            aggregator.addValue(new Page(createBlock(values, field + 1)));
        }

        return (long) BlockAssertions.toValues(aggregator.getResult()).get(0).get(0);
    }
View Full Code Here

        int size = Math.min(values.size(), Math.max(values.size() / 2, 1));

        Block first = aggregatePartial(values.subList(0, size), field);
        Block second = aggregatePartial(values.subList(size, values.size()), field);

        Aggregator aggregator = createAggregator(aggregation(getAggregationFunction(), new Input(0, field)), AggregationNode.Step.FINAL);

        BlockCursor cursor = first.cursor();
        while (cursor.advanceNextPosition()) {
            aggregator.addValue(cursor);
        }

        cursor = second.cursor();
        while (cursor.advanceNextPosition()) {
            aggregator.addValue(cursor);
        }

        return (long) BlockAssertions.toValues(aggregator.getResult()).get(0).get(0);
    }
View Full Code Here

        return (long) BlockAssertions.toValues(aggregator.getResult()).get(0).get(0);
    }

    private Block aggregatePartial(List<Object> values, int field)
    {
        Aggregator aggregator = createAggregator(aggregation(getAggregationFunction(), new Input(0, field)), AggregationNode.Step.PARTIAL);

        if (!values.isEmpty()) {
            BlockCursor cursor = createBlock(values, field + 1).cursor();
            while (cursor.advanceNextPosition()) {
                aggregator.addValue(cursor);
            }
        }

        return aggregator.getResult();
    }
View Full Code Here

    }

    private void testMultiplePositions(Block block, Object expectedValue, int positions, int field)
    {
        BlockCursor cursor = createCompositeTupleBlock(block, field).cursor();
        Aggregator function = createAggregator(aggregation(getFunction(), new Input(0, field)), Step.SINGLE);

        for (int i = 0; i < positions; i++) {
            assertTrue(cursor.advanceNextPosition());
            function.addValue(cursor);
        }

        Object actualValue = getActualValue(function);
        assertEquals(actualValue, expectedValue);
        if (positions > 0) {
View Full Code Here

        testVectorMultiplePositions(block, expectedValue, 1);
    }

    private void testVectorMultiplePositions(Block block, Object expectedValue, int field)
    {
        Aggregator function = createAggregator(aggregation(getFunction(), new Input(0, field)), Step.SINGLE);

        function.addValue(new Page(createCompositeTupleBlock(block, field)));
        assertEquals(getActualValue(function), expectedValue);
    }
View Full Code Here

    }

    protected void testPartialWithMultiplePositions(Block block, Object expectedValue)
    {
        UncompressedBlock partialsBlock = performPartialAggregation(block);
        Aggregator function = createAggregator(aggregation(getFunction(), new Input(0, 0)), Step.FINAL);
        BlockCursor partialsCursor = partialsBlock.cursor();
        while (partialsCursor.advanceNextPosition()) {
            function.addValue(partialsCursor);
        }

        assertEquals(getActualValue(function), expectedValue);
    }
View Full Code Here

    }

    protected void testVectorPartialWithMultiplePositions(Block block, Object expectedValue)
    {
        UncompressedBlock partialsBlock = performPartialAggregation(block);
        Aggregator function = createAggregator(aggregation(getFunction(), new Input(0, 0)), Step.FINAL);

        BlockCursor blockCursor = partialsBlock.cursor();
        while (blockCursor.advanceNextPosition()) {
            function.addValue(blockCursor);
        }
        assertEquals(getActualValue(function), expectedValue);
    }
View Full Code Here

    private UncompressedBlock performPartialAggregation(Block block)
    {
        BlockBuilder blockBuilder = new BlockBuilder(getFunction().getIntermediateTupleInfo());
        BlockCursor cursor = block.cursor();
        while (cursor.advanceNextPosition()) {
            Aggregator function = createAggregator(aggregation(getFunction(), new Input(0, 0)), Step.PARTIAL);
            function.addValue(cursor);
            BlockCursor result = function.getResult().cursor();
            assertTrue(result.advanceNextPosition());
            Tuple tuple = result.getTuple();
            blockBuilder.append(tuple);
        }
        return blockBuilder.build();
View Full Code Here

        MaterializedResult expected = MaterializedResult.resultBuilder(function.getFinalTupleInfo())
                .row(expectedValue)
                .build();

        // verify addValue(Page)
        Aggregator aggregator1 = createAggregator(definition, Step.FINAL);
        for (Page input : inputs) {
            aggregator1.addValue(computePartial(function, input));
        }

        assertEquals(getResult(function.getFinalTupleInfo(), aggregator1), expected);

        // verify addValue(BlockCursor...)
        Aggregator aggregator2 = createAggregator(definition, Step.FINAL);
        for (Page input : inputs) {
            Page partial = computePartial(function, input);

            BlockCursor[] cursors = new BlockCursor[partial.getBlocks().length];
            for (int i = 0; i < cursors.length; i++) {
                cursors[i] = partial.getBlock(i).cursor();
            }

            while (BlockAssertions.advanceAllCursorsToNextPosition(cursors)) {
                aggregator2.addValue(cursors);
            }
        }

        assertEquals(getResult(function.getFinalTupleInfo(), aggregator2), expected);
    }
View Full Code Here

TOP

Related Classes of com.facebook.presto.operator.AggregationOperator.Aggregator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.