Package com.facebook.presto.spi.block

Examples of com.facebook.presto.spi.block.RandomAccessBlock


        extends AbstractTestBlockCursor
{
    @Override
    protected RunLengthEncodedBlockCursor createTestCursor()
    {
        RandomAccessBlock value = VARCHAR.createBlockBuilder(new BlockBuilderStatus())
                .appendNull()
                .build()
                .toRandomAccessBlock();

        return new RunLengthEncodedBlock(value, 11).cursor();
View Full Code Here


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

        // verify hashStrategy is consistent with equals and hash code from block
        for (int leftBlockIndex = 0; leftBlockIndex < channel.size(); leftBlockIndex++) {
            RandomAccessBlock 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++) {
                    RandomAccessBlock 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 (RandomAccessBlock rightBlock : channel) {
                    BlockCursor rightCursor = rightBlock.cursor();
                    BlockCursor[] rightCursors = new BlockCursor[]{rightCursor};
                    while (rightCursor.advanceNextPosition()) {
                        assertEquals(
                                hashStrategy.positionEqualsCursors(leftBlockIndex, leftBlockPosition, rightCursors),
                                leftBlock.equalTo(leftBlockPosition, rightCursor));
View Full Code Here

                // 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++) {
                    RandomAccessBlock 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));
                    }
                }
View Full Code Here

public class TestRunLengthEncodedBlockSerde
{
    @Test
    public void testRoundTrip()
    {
        RandomAccessBlock value = VARCHAR.createBlockBuilder(new BlockBuilderStatus())
                .appendSlice(Slices.utf8Slice("alice"))
                .build()
                .toRandomAccessBlock();

        RunLengthEncodedBlock expectedBlock = new RunLengthEncodedBlock(value, 11);
View Full Code Here

    }

    @Test
    public void testCreateBlockWriter()
    {
        RandomAccessBlock expectedBlock = VARCHAR.createBlockBuilder(new BlockBuilderStatus())
                .appendSlice(Slices.utf8Slice("alice"))
                .appendSlice(Slices.utf8Slice("alice"))
                .appendSlice(Slices.utf8Slice("bob"))
                .appendSlice(Slices.utf8Slice("bob"))
                .appendSlice(Slices.utf8Slice("bob"))
View Full Code Here

                BlockAssertions.createStringSequenceBlock(10, 20).toRandomAccessBlock(),
                BlockAssertions.createStringSequenceBlock(20, 30).toRandomAccessBlock(),
                BlockAssertions.createStringSequenceBlock(15, 25).toRandomAccessBlock());
        LongArrayList addresses = new LongArrayList();
        for (int blockIndex = 0; blockIndex < channel.size(); blockIndex++) {
            RandomAccessBlock block = channel.get(blockIndex);
            for (int positionIndex = 0; positionIndex < block.getPositionCount(); positionIndex++) {
                addresses.add(encodeSyntheticAddress(blockIndex, positionIndex));
            }
        }
        LookupSource lookupSource = lookupSourceFactoryFactory.createLookupSource(addresses, ImmutableList.of(channel), operatorContext);
View Full Code Here

    }

    @Test
    public void testLotsOfStuff()
    {
        RandomAccessBlock block = VARCHAR.createBlockBuilder(new BlockBuilderStatus())
                .appendSlice(Slices.utf8Slice("alice"))
                .appendSlice(Slices.utf8Slice("bob"))
                .appendSlice(Slices.utf8Slice("charlie"))
                .appendSlice(Slices.utf8Slice("dave"))
                .build()
                .toRandomAccessBlock();

        DynamicSliceOutput encoderOutput = new DynamicSliceOutput(1024);
        Encoder encoder = BlocksFileEncoding.SNAPPY.createBlocksWriter(encoderOutput);

        BlockBuilder expectedBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus());

        int count = 1000;
        for (int i = 0; i < count; i++) {
            // select a random position
            int position = ThreadLocalRandom.current().nextInt(block.getPositionCount());

            // add to expected block
            block.appendTo(position, expectedBlockBuilder);

            // create block with single value and add to encoder
            encoder.append(block.getSingleValueBlock(position));
        }

        Block expectedBlock = expectedBlockBuilder.build();

        BlockEncoding snappyEncoding = encoder.finish();
View Full Code Here

    @Test
    public void testAllPositionsNull()
            throws Exception
    {
        Type type = getSequenceBlock(0, 10).getType();
        RandomAccessBlock nullValueBlock = type.createBlockBuilder(new BlockBuilderStatus())
                .appendNull()
                .build()
                .toRandomAccessBlock();

        Block block = new RunLengthEncodedBlock(nullValueBlock, 10);
View Full Code Here

        return newPages;
    }

    private static RunLengthEncodedBlock createNullRLEBlock(int positionCount)
    {
        RandomAccessBlock value = BOOLEAN.createBlockBuilder(new BlockBuilderStatus())
                .appendNull()
                .build()
                .toRandomAccessBlock();

        return new RunLengthEncodedBlock(value, positionCount);
View Full Code Here

        return new Page(valuesBlock, weightsBlock, percentilesBlock);
    }

    private static RunLengthEncodedBlock createRLEBlock(double percentile, int positionCount)
    {
        RandomAccessBlock value = DOUBLE.createBlockBuilder(new BlockBuilderStatus())
                .appendDouble(percentile)
                .build()
                .toRandomAccessBlock();

        return new RunLengthEncodedBlock(value, positionCount);
View Full Code Here

TOP

Related Classes of com.facebook.presto.spi.block.RandomAccessBlock

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.