Package com.facebook.presto.operator

Examples of com.facebook.presto.operator.PageBuilder


    @Test
    public void testSum()
            throws Exception
    {
        int sum = 1_000;
        PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, BIGINT));
        Random rand = new Random(0);
        for (int i = 0; i < sum; i++) {
            if (rand.nextDouble() < 0.5) {
                builder.getBlockBuilder(0).appendLong(1);
                builder.getBlockBuilder(1).appendLong(2);
            }
        }

        AggregationFunction function = new DeterministicBootstrappedAggregation(createTestingBlockEncodingManager(), LONG_SUM);

        assertApproximateAggregation(function, 1, 0.99, (double) sum, builder.build());
    }
View Full Code Here


        int successes = 0;
        Random rand = new Random(0);
        for (int i = 0; i < trials; i++) {
            int sum = 1_000;
            PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, BIGINT));
            for (int j = 0; j < sum; j++) {
                if (rand.nextDouble() < 0.5) {
                    builder.getBlockBuilder(0).appendLong(1);
                    builder.getBlockBuilder(1).appendLong(2);
                }
            }

            AggregationFunction function = new DeterministicBootstrappedAggregation(createTestingBlockEncodingManager(), LONG_SUM);

            successes += approximateAggregationWithinErrorBound(function, 1, 0.5, (double) sum, builder.build()) ? 1 : 0;
        }

        // Since we used a confidence of 0.5, successes should have a binomial distribution B(n=20, p=0.5)
        assertTrue(binomial.inverseCumulativeProbability(0.01) < successes && successes < binomial.inverseCumulativeProbability(0.99));
    }
View Full Code Here

        // verify hashStrategy is consistent with equals and hash code from block
        for (int leftBlockIndex = 0; leftBlockIndex < channel.size(); leftBlockIndex++) {
            Block leftBlock = channel.get(leftBlockIndex);

            PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR));

            for (int leftBlockPosition = 0; leftBlockPosition < leftBlock.getPositionCount(); leftBlockPosition++) {
                // hash code of position must match block hash
                assertEquals(hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition), leftBlock.hash(leftBlockPosition));

                // position must be equal to itself
                assertTrue(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));

                // check equality of every position against every other position in the block
                for (int rightBlockIndex = 0; rightBlockIndex < channel.size(); rightBlockIndex++) {
                    Block rightBlock = channel.get(rightBlockIndex);
                    for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                        assertEquals(
                                hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition),
                                leftBlock.equalTo(leftBlockPosition, rightBlock, rightBlockPosition));
                    }
                }

                // check equality of every position against every other position in the block cursor
                for (Block rightBlock : channel) {
                    for (int position = 0; position < rightBlock.getPositionCount(); position++) {
                        assertEquals(
                                hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, position, rightBlock),
                                leftBlock.equalTo(leftBlockPosition, rightBlock, position));
                    }
                }

                // write position to output block
                hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);
            }

            // verify output block matches
            assertBlockEquals(pageBuilder.build().getBlock(0), leftBlock);
        }
    }
View Full Code Here

        PagesHashStrategy expectedHashStrategy = new SimplePagesHashStrategy(channels, Ints.asList(1, 2, 3, 4));

        // verify hashStrategy is consistent with equals and hash code from block
        for (int leftBlockIndex = 0; leftBlockIndex < varcharChannel.size(); leftBlockIndex++) {
            PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, DOUBLE, BOOLEAN));

            int leftPositionCount = varcharChannel.get(leftBlockIndex).getPositionCount();
            for (int leftBlockPosition = 0; leftBlockPosition < leftPositionCount; leftBlockPosition++) {
                // hash code of position must match block hash
                assertEquals(
                        hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition),
                        expectedHashStrategy.hashPosition(leftBlockIndex, leftBlockPosition));

                // position must be equal to itself
                assertTrue(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));

                // check equality of every position against every other position in the block
                for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                    Block rightBlock = varcharChannel.get(rightBlockIndex);
                    for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                        assertEquals(
                                hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition),
                                expectedHashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
                    }
                }

                // check equality of every position against every other position in the block cursor
                for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                    Block[] rightBlocks = new Block[4];
                    rightBlocks[0] = varcharChannel.get(rightBlockIndex);
                    rightBlocks[1] = longChannel.get(rightBlockIndex);
                    rightBlocks[2] = doubleChannel.get(rightBlockIndex);
                    rightBlocks[3] = booleanChannel.get(rightBlockIndex);

                    int rightPositionCount = varcharChannel.get(rightBlockIndex).getPositionCount();
                    for (int rightPosition = 0; rightPosition < rightPositionCount; rightPosition++) {
                        assertEquals(
                                hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightPosition, rightBlocks),
                                expectedHashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightPosition, rightBlocks));
                    }
                }

                // write position to output block
                hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);
            }

            // verify output block matches
            Page page = pageBuilder.build();
            assertPageEquals(page, new Page(
                    extraChannel.get(leftBlockIndex),
                    varcharChannel.get(leftBlockIndex),
                    longChannel.get(leftBlockIndex),
                    doubleChannel.get(leftBlockIndex),
View Full Code Here

        // verify channel count
        assertEquals(joinProbe.getChannelCount(), 1);

        Block probeBlock = page.getBlock(0);
        PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR));
        for (int position = 0; position < page.getPositionCount(); position++) {
            assertTrue(joinProbe.advanceNextPosition());

            joinProbe.appendTo(pageBuilder);

            assertEquals(joinProbe.getCurrentJoinPosition(), lookupSource.getJoinPosition(position, probeBlock));
        }
        assertFalse(joinProbe.advanceNextPosition());
        assertBlockEquals(pageBuilder.build().getBlock(0), page.getBlock(0));
    }
View Full Code Here

    public void testSum()
            throws Exception
    {
        int sum = 1_000;
        List<TupleInfo> tupleInfos = ImmutableList.of(TupleInfo.SINGLE_LONG, TupleInfo.SINGLE_LONG);
        PageBuilder builder = new PageBuilder(tupleInfos);
        Random rand = new Random(0);
        for (int i = 0; i < sum; i++) {
            if (rand.nextDouble() < 0.5) {
                builder.getBlockBuilder(0).append(1);
                builder.getBlockBuilder(1).append(2);
            }
        }

        BootstrappedAggregation function = new BootstrappedAggregation(LONG_SUM);

        assertApproximateAggregation(function, 1, 0.99, sum, 0, builder.build());
    }
View Full Code Here

        int successes = 0;
        Random rand = new Random(0);
        for (int i = 0; i < trials; i++) {
            int sum = 1_000;
            List<TupleInfo> tupleInfos = ImmutableList.of(TupleInfo.SINGLE_LONG, TupleInfo.SINGLE_LONG);
            PageBuilder builder = new PageBuilder(tupleInfos);
            for (int j = 0; j < sum; j++) {
                if (rand.nextDouble() < 0.5) {
                    builder.getBlockBuilder(0).append(1);
                    builder.getBlockBuilder(1).append(2);
                }
            }

            BootstrappedAggregation function = new BootstrappedAggregation(LONG_SUM);

            successes += approximateAggregationWithinErrorBound(function, 1, 0.5, sum, 0, builder.build()) ? 1 : 0;
        }

        // Since we used a confidence of 0.5, successes should have a binomial distribution B(n=20, p=0.5)
        assertTrue(binomial.inverseCumulativeProbability(0.01) < successes && successes < binomial.inverseCumulativeProbability(0.99));
    }
View Full Code Here

        // verify hashStrategy is consistent with equals and hash code from block
        for (int leftBlockIndex = 0; leftBlockIndex < channel.size(); leftBlockIndex++) {
            Block leftBlock = channel.get(leftBlockIndex);

            PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR));

            for (int leftBlockPosition = 0; leftBlockPosition < leftBlock.getPositionCount(); leftBlockPosition++) {
                // hash code of position must match block hash
                assertEquals(hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition), leftBlock.hash(leftBlockPosition));

                // position must be equal to itself
                assertTrue(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));

                // check equality of every position against every other position in the block
                for (int rightBlockIndex = 0; rightBlockIndex < channel.size(); rightBlockIndex++) {
                    Block rightBlock = channel.get(rightBlockIndex);
                    for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                        assertEquals(
                                hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition),
                                leftBlock.equalTo(leftBlockPosition, rightBlock, rightBlockPosition));
                    }
                }

                // check equality of every position against every other position in the block cursor
                for (Block rightBlock : channel) {
                    BlockCursor rightCursor = rightBlock.cursor();
                    BlockCursor[] rightCursors = new BlockCursor[]{rightCursor};
                    while (rightCursor.advanceNextPosition()) {
                        assertEquals(
                                hashStrategy.positionEqualsCursors(leftBlockIndex, leftBlockPosition, rightCursors),
                                leftBlock.equalTo(leftBlockPosition, rightCursor));
                    }
                }

                // write position to output block
                hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);
            }

            // verify output block matches
            assertBlockEquals(pageBuilder.build().getBlock(0), leftBlock);
        }
    }
View Full Code Here

        PagesHashStrategy expectedHashStrategy = new SimplePagesHashStrategy(channels, Ints.asList(1, 2, 3, 4));

        // verify hashStrategy is consistent with equals and hash code from block
        for (int leftBlockIndex = 0; leftBlockIndex < varcharChannel.size(); leftBlockIndex++) {
            PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, DOUBLE, BOOLEAN));

            int leftPositionCount = varcharChannel.get(leftBlockIndex).getPositionCount();
            for (int leftBlockPosition = 0; leftBlockPosition < leftPositionCount; leftBlockPosition++) {
                // hash code of position must match block hash
                assertEquals(
                        hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition),
                        expectedHashStrategy.hashPosition(leftBlockIndex, leftBlockPosition));

                // position must be equal to itself
                assertTrue(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));

                // check equality of every position against every other position in the block
                for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                    Block rightBlock = varcharChannel.get(rightBlockIndex);
                    for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                        assertEquals(
                                hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition),
                                expectedHashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
                    }
                }

                // check equality of every position against every other position in the block cursor
                for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                    BlockCursor[] rightCursors = new BlockCursor[4];
                    rightCursors[0] = varcharChannel.get(rightBlockIndex).cursor();
                    rightCursors[1] = longChannel.get(rightBlockIndex).cursor();
                    rightCursors[2] = doubleChannel.get(rightBlockIndex).cursor();
                    rightCursors[3] = booleanChannel.get(rightBlockIndex).cursor();

                    int rightPositionCount = varcharChannel.get(rightBlockIndex).getPositionCount();
                    for (int rightPosition = 0; rightPosition < rightPositionCount; rightPosition++) {
                        for (BlockCursor rightCursor : rightCursors) {
                            assertTrue(rightCursor.advanceNextPosition());
                        }

                        assertEquals(
                                hashStrategy.positionEqualsCursors(leftBlockIndex, leftBlockPosition, rightCursors),
                                expectedHashStrategy.positionEqualsCursors(leftBlockIndex, leftBlockPosition, rightCursors));
                    }
                }

                // write position to output block
                hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);
            }

            // verify output block matches
            Page page = pageBuilder.build();
            assertPageEquals(page, new Page(
                    extraChannel.get(leftBlockIndex),
                    varcharChannel.get(leftBlockIndex),
                    longChannel.get(leftBlockIndex),
                    doubleChannel.get(leftBlockIndex),
View Full Code Here

        // verify channel count
        assertEquals(joinProbe.getChannelCount(), 1);

        BlockCursor probeCursor = page.getBlock(0).cursor();
        PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR));
        for (int position = 0; position < page.getPositionCount(); position++) {
            assertTrue(probeCursor.advanceNextPosition());
            assertTrue(joinProbe.advanceNextPosition());

            joinProbe.appendTo(pageBuilder);

            assertEquals(joinProbe.getCurrentJoinPosition(), lookupSource.getJoinPosition(probeCursor));
        }
        assertFalse(joinProbe.advanceNextPosition());
        assertBlockEquals(pageBuilder.build().getBlock(0), page.getBlock(0));
    }
View Full Code Here

TOP

Related Classes of com.facebook.presto.operator.PageBuilder

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.