Package com.facebook.presto.spi.block

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


public class TestBlockBuilder
{
    @Test
    public void testMultipleValuesWithNull()
    {
        BlockCursor cursor = BIGINT.createBlockBuilder(new BlockBuilderStatus())
                .appendNull()
                .appendLong(42)
                .appendNull()
                .appendLong(42)
                .build()
                .cursor();

        assertTrue(cursor.advanceNextPosition());
        assertTrue(cursor.isNull());

        assertTrue(cursor.advanceNextPosition());
        assertEquals(cursor.getLong(), 42L);

        assertTrue(cursor.advanceNextPosition());
        assertTrue(cursor.isNull());

        assertTrue(cursor.advanceNextPosition());
        assertEquals(cursor.getLong(), 42L);
    }
View Full Code Here


        // Note this code will more effective if the values are laid out as follows:
        //
        //   A, A, A, B, B, B, B, B, C, C, D
        //

        BlockCursor cursor = createTestCursor();

        // advance to first position
        assertAdvanceToPosition(cursor, 0);
        assertCurrentValue(cursor, 0, getExpectedValue(0));

        // skip to position in first value
        assertAdvanceToPosition(cursor, 2);
        assertCurrentValue(cursor, 2, getExpectedValue(2));

        // advance to same position
        assertAdvanceToPosition(cursor, 2);
        assertCurrentValue(cursor, 2, getExpectedValue(2));

        // skip to position in next value
        assertAdvanceToPosition(cursor, 4);
        assertCurrentValue(cursor, 4, getExpectedValue(4));

        // skip to position in third value
        assertAdvanceToPosition(cursor, 8);
        assertCurrentValue(cursor, 8, getExpectedValue(8));

        // skip to last position
        assertAdvanceToPosition(cursor, 10);
        assertCurrentValue(cursor, 10, getExpectedValue(10));

        // skip backwards
        try {
            cursor.advanceToPosition(2);
            fail("Expected IllegalArgumentException");
        }
        catch (IllegalArgumentException e) {
            assertCurrentValue(cursor, 10, getExpectedValue(10));
        }

        // skip past end
        assertFalse(cursor.advanceToPosition(100));
        assertTrue(cursor.isFinished());
        assertFalse(cursor.isValid());
    }
View Full Code Here

    }

    @Test
    public void testStates()
    {
        BlockCursor cursor = createTestCursor();

        //
        // We are before the first position, so the cursor is not valid and all get current methods should throw an IllegalStateException
        //
        assertFalse(cursor.isValid());
        assertFalse(cursor.isFinished());

        try {
            cursor.getSingleValueBlock();
            fail("Expected IllegalStateException");
        }
        catch (IllegalStateException expected) {
        }

        //
        // advance to end
        //
        while (cursor.advanceNextPosition()) {
            assertTrue(cursor.isValid());
            assertFalse(cursor.isFinished());
        }

        //
        // We are beyond the last position, so the cursor is not valid, finished and all get next methods should return false
        //

        assertFalse(cursor.isValid());
        assertTrue(cursor.isFinished());

        assertFalse(cursor.advanceNextPosition());

        assertFalse(cursor.isValid());
        assertTrue(cursor.isFinished());
    }
View Full Code Here

    }

    @Test
    public void testFirstPosition()
    {
        BlockCursor cursor = createTestCursor();
        assertNextPosition(cursor, 0, getExpectedValue(0));
    }
View Full Code Here

    }

    @Test
    public void testAdvanceNextPosition()
    {
        BlockCursor cursor = createTestCursor();

        for (Entry<Integer, Object> entry : getExpectedValues().entrySet()) {
            assertNextPosition(cursor, entry.getKey(), entry.getValue());
        }

        assertFalse(cursor.advanceNextPosition());
    }
View Full Code Here

    public static Object getOnlyValue(Block block)
    {
        assertEquals(block.getPositionCount(), 1, "Block positions");

        BlockCursor cursor = block.cursor();
        assertTrue(cursor.advanceNextPosition());
        Object value = cursor.getObjectValue(SESSION);
        assertFalse(cursor.advanceNextPosition());

        return value;
    }
View Full Code Here

    public static List<Object> toValues(BlockIterable blocks)
    {
        List<Object> values = new ArrayList<>();
        for (Block block : blocks) {
            BlockCursor cursor = block.cursor();
            while (cursor.advanceNextPosition()) {
                values.add(cursor.getObjectValue(SESSION));
            }
        }
        return Collections.unmodifiableList(values);
    }
View Full Code Here

        return Collections.unmodifiableList(values);
    }

    public static List<Object> toValues(Block block)
    {
        BlockCursor cursor = block.cursor();
        return toValues(cursor);
    }
View Full Code Here

        {
            for (int i = 0; i < sortChannels.size(); i++) {
                int sortChannel = sortChannels.get(i);
                SortOrder sortOrder = sortOrders.get(i);

                BlockCursor cursor = cursors[sortChannel];
                RandomAccessBlock currentMaxValue = currentMax[sortChannel];

                // compare the right value to the left cursor but negate the result since we are evaluating in the opposite order
                int compare = -currentMaxValue.compareTo(sortOrder, 0, cursor);
                if (compare != 0) {
View Full Code Here

        @Override
        protected void processInput(GroupByIdBlock groupIdsBlock, Block valuesBlock, Optional<Block> maskBlock, Optional<Block> sampleWeightBlock)
        {
            maxValues.ensureCapacity(groupIdsBlock.getGroupCount());

            BlockCursor values = valuesBlock.cursor();

            for (int position = 0; position < groupIdsBlock.getPositionCount(); position++) {
                checkState(values.advanceNextPosition());

                // skip null values
                if (!values.isNull()) {
                    long groupId = groupIdsBlock.getGroupId(position);

                    // if value is true, update the max to true
                    if (values.getBoolean()) {
                        maxValues.set(groupId, TRUE_VALUE);
                    }
                    else {
                        // if the current value is null, set the max to false
                        if (maxValues.get(groupId) == NULL_VALUE) {
View Full Code Here

TOP

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

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.