Package com.facebook.presto.spi.block

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


        assertEquals(output.getChannelCount(), 1);

        Block block = output.getBlock(0);
        assertEquals(block.getPositionCount(), 1);

        BlockCursor cursor = block.cursor();
        assertTrue(cursor.advanceNextPosition());
        if (cursor.isNull()) {
            return null;
        }
        else {
            return cursor.getObjectValue(session);
        }
    }
View Full Code Here


        boolean value;
        if (page != null) {
            assertEquals(page.getPositionCount(), 1);
            assertEquals(page.getChannelCount(), 1);

            BlockCursor cursor = page.getBlock(0).cursor();
            assertTrue(cursor.advanceNextPosition());
            assertTrue(cursor.getBoolean());
            value = true;
        }
        else {
            value = false;
        }
View Full Code Here

                Block taxBlock,
                Block shipDateBlock)
        {
            int rows = returnFlagBlock.getPositionCount();

            BlockCursor returnFlagCursor = returnFlagBlock.cursor();
            BlockCursor lineStatusCursor = lineStatusBlock.cursor();
            BlockCursor quantityCursor = quantityBlock.cursor();
            BlockCursor extendedPriceCursor = extendedPriceBlock.cursor();
            BlockCursor discountCursor = discountBlock.cursor();
            BlockCursor taxCursor = taxBlock.cursor();
            BlockCursor shipDateCursor = shipDateBlock.cursor();

            for (int position = 0; position < rows; position++) {
                checkState(returnFlagCursor.advanceNextPosition());
                checkState(lineStatusCursor.advanceNextPosition());
                checkState(quantityCursor.advanceNextPosition());
                checkState(extendedPriceCursor.advanceNextPosition());
                checkState(discountCursor.advanceNextPosition());
                checkState(taxCursor.advanceNextPosition());
                checkState(shipDateCursor.advanceNextPosition());

                if (shipDateCursor.isNull()) {
                    continue;
                }

                Slice shipDate = shipDateCursor.getSlice();

                // where
                //     shipdate <= '1998-09-02'
                if (shipDate.compareTo(MAX_SHIP_DATE) <= 0) {
                    //     returnflag,
                    //     linestatus
                    //     quantity
                    //     extendedprice
                    //     extendedprice * (1 - discount)
                    //     extendedprice * (1 - discount) * (1 + tax)
                    //     discount

                    if (returnFlagCursor.isNull()) {
                        pageBuilder.getBlockBuilder(0).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(0).appendSlice(returnFlagCursor.getSlice());
                    }
                    if (lineStatusCursor.isNull()) {
                        pageBuilder.getBlockBuilder(1).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(1).appendSlice(lineStatusCursor.getSlice());
                    }

                    long quantity = quantityCursor.getLong();
                    double extendedPrice = extendedPriceCursor.getDouble();
                    double discount = discountCursor.getDouble();
                    double tax = taxCursor.getDouble();

                    boolean quantityIsNull = quantityCursor.isNull();
                    boolean extendedPriceIsNull = extendedPriceCursor.isNull();
                    boolean discountIsNull = discountCursor.isNull();
                    boolean taxIsNull = taxCursor.isNull();

                    if (quantityIsNull) {
                        pageBuilder.getBlockBuilder(2).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(2).appendLong(quantity);
                    }

                    if (extendedPriceIsNull) {
                        pageBuilder.getBlockBuilder(3).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(3).appendDouble(extendedPrice);
                    }

                    if (extendedPriceIsNull || discountIsNull) {
                        pageBuilder.getBlockBuilder(4).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(4).appendDouble(extendedPrice * (1 - discount));
                    }

                    if (extendedPriceIsNull || discountIsNull || taxIsNull) {
                        pageBuilder.getBlockBuilder(5).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(5).appendDouble(extendedPrice * (1 - discount) * (1 + tax));
                    }

                    if (discountIsNull) {
                        pageBuilder.getBlockBuilder(6).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(6).appendDouble(discount);
                    }
                }
            }

            checkState(!returnFlagCursor.advanceNextPosition());
            checkState(!lineStatusCursor.advanceNextPosition());
            checkState(!quantityCursor.advanceNextPosition());
            checkState(!extendedPriceCursor.advanceNextPosition());
            checkState(!discountCursor.advanceNextPosition());
            checkState(!taxCursor.advanceNextPosition());
            checkState(!shipDateCursor.advanceNextPosition());
        }
View Full Code Here

        JoinProbe joinProbe = probeFactory.createJoinProbe(lookupSource, page);

        // 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));
View Full Code Here

        private void filterAndProjectRowOriented(PageBuilder pageBuilder, Block extendedPriceBlock, Block discountBlock, Block shipDateBlock, Block quantityBlock)
        {
            int rows = extendedPriceBlock.getPositionCount();

            BlockCursor extendedPriceCursor = extendedPriceBlock.cursor();
            BlockCursor discountCursor = discountBlock.cursor();
            BlockCursor shipDateCursor = shipDateBlock.cursor();
            BlockCursor quantityCursor = quantityBlock.cursor();

            for (int position = 0; position < rows; position++) {
                checkState(extendedPriceCursor.advanceNextPosition());
                checkState(discountCursor.advanceNextPosition());
                checkState(shipDateCursor.advanceNextPosition());
                checkState(quantityCursor.advanceNextPosition());

                // where shipdate >= '1994-01-01'
                //    and shipdate < '1995-01-01'
                //    and discount >= 0.05
                //    and discount <= 0.07
                //    and quantity < 24;
                if (filter(discountCursor, shipDateCursor, quantityCursor)) {
                    project(pageBuilder, extendedPriceCursor, discountCursor);
                }
            }

            checkState(!extendedPriceCursor.advanceNextPosition());
            checkState(!discountCursor.advanceNextPosition());
            checkState(!shipDateCursor.advanceNextPosition());
            checkState(!quantityCursor.advanceNextPosition());
        }
View Full Code Here

                Block taxBlock,
                Block shipDateBlock)
        {
            int rows = returnFlagBlock.getPositionCount();

            BlockCursor returnFlagCursor = returnFlagBlock.cursor();
            BlockCursor lineStatusCursor = lineStatusBlock.cursor();
            BlockCursor quantityCursor = quantityBlock.cursor();
            BlockCursor extendedPriceCursor = extendedPriceBlock.cursor();
            BlockCursor discountCursor = discountBlock.cursor();
            BlockCursor taxCursor = taxBlock.cursor();
            BlockCursor shipDateCursor = shipDateBlock.cursor();

            for (int position = 0; position < rows; position++) {
                checkState(returnFlagCursor.advanceNextPosition());
                checkState(lineStatusCursor.advanceNextPosition());
                checkState(quantityCursor.advanceNextPosition());
                checkState(extendedPriceCursor.advanceNextPosition());
                checkState(discountCursor.advanceNextPosition());
                checkState(taxCursor.advanceNextPosition());
                checkState(shipDateCursor.advanceNextPosition());

                if (shipDateCursor.isNull()) {
                    continue;
                }

                Slice shipDate = shipDateCursor.getSlice();

                // where
                //     shipdate <= '1998-09-02'
                if (shipDate.compareTo(MAX_SHIP_DATE) <= 0) {
                    //     returnflag,
                    //     linestatus
                    //     quantity
                    //     extendedprice
                    //     extendedprice * (1 - discount)
                    //     extendedprice * (1 - discount) * (1 + tax)
                    //     discount

                    if (returnFlagCursor.isNull()) {
                        pageBuilder.getBlockBuilder(0).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(0).appendSlice(returnFlagCursor.getSlice());
                    }
                    if (lineStatusCursor.isNull()) {
                        pageBuilder.getBlockBuilder(1).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(1).appendSlice(lineStatusCursor.getSlice());
                    }

                    long quantity = quantityCursor.getLong();
                    double extendedPrice = extendedPriceCursor.getDouble();
                    double discount = discountCursor.getDouble();
                    double tax = taxCursor.getDouble();

                    boolean quantityIsNull = quantityCursor.isNull();
                    boolean extendedPriceIsNull = extendedPriceCursor.isNull();
                    boolean discountIsNull = discountCursor.isNull();
                    boolean taxIsNull = taxCursor.isNull();

                    if (quantityIsNull) {
                        pageBuilder.getBlockBuilder(2).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(2).appendLong(quantity);
                    }

                    if (extendedPriceIsNull) {
                        pageBuilder.getBlockBuilder(3).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(3).appendDouble(extendedPrice);
                    }

                    if (extendedPriceIsNull || discountIsNull) {
                        pageBuilder.getBlockBuilder(4).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(4).appendDouble(extendedPrice * (1 - discount));
                    }

                    if (extendedPriceIsNull || discountIsNull || taxIsNull) {
                        pageBuilder.getBlockBuilder(5).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(5).appendDouble(extendedPrice * (1 - discount) * (1 + tax));
                    }

                    if (discountIsNull) {
                        pageBuilder.getBlockBuilder(6).appendNull();
                    }
                    else {
                        pageBuilder.getBlockBuilder(6).appendDouble(discount);
                    }
                }
            }

            checkState(!returnFlagCursor.advanceNextPosition());
            checkState(!lineStatusCursor.advanceNextPosition());
            checkState(!quantityCursor.advanceNextPosition());
            checkState(!extendedPriceCursor.advanceNextPosition());
            checkState(!discountCursor.advanceNextPosition());
            checkState(!taxCursor.advanceNextPosition());
            checkState(!shipDateCursor.advanceNextPosition());
        }
View Full Code Here

        assertEquals(output.getChannelCount(), 1);

        Block block = output.getBlock(0);
        assertEquals(block.getPositionCount(), 1);

        BlockCursor cursor = block.cursor();
        assertTrue(cursor.advanceNextPosition());
        if (cursor.isNull()) {
            return null;
        }
        else {
            return cursor.getObjectValue(session);
        }
    }
View Full Code Here

    private static BlockCursor createCursor(Type type, Object value)
    {
        BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus());
        BlockUtils.appendObject(blockBuilder, value);
        BlockCursor cursor = blockBuilder.build().cursor();
        assertTrue(cursor.advanceNextPosition());
        return cursor;
    }
View Full Code Here

        extends AbstractTestBlockCursor
{
    @Test
    public void testNullValues()
    {
        BlockCursor cursor = createTestCursor();

        for (Entry<Integer, Object> entry : getExpectedValues().entrySet()) {
            assertNextPosition(cursor, entry.getKey(), entry.getValue());
            if (cursor.getPosition() % 2 == 0) {
                assertTrue(cursor.isNull());
                assertTrue(entry.getValue() == null);
            }
        }

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

        boolean value;
        if (page != null) {
            assertEquals(page.getPositionCount(), 1);
            assertEquals(page.getChannelCount(), 1);

            BlockCursor cursor = page.getBlock(0).cursor();
            assertTrue(cursor.advanceNextPosition());
            assertTrue(cursor.getBoolean());
            value = true;
        }
        else {
            value = false;
        }
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.