Package com.facebook.presto.spi.block

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


        }

        @Override
        public Block evaluateIntermediate()
        {
            BlockBuilder out = intermediateType.createBlockBuilder(new BlockBuilderStatus());
            getStateSerializer().serialize(state, out);
            return out.build();
        }
View Full Code Here


        }

        @Override
        public Block evaluateFinal()
        {
            BlockBuilder out = finalType.createBlockBuilder(new BlockBuilderStatus());
            AbstractAggregationFunction.this.evaluateFinal(state, confidence, out);
            return out.build();
        }
View Full Code Here

                    while (!pageBuilder.isFull() && groupId < groupCount) {
                        groupByHash.appendValuesTo(groupId, groupByBlockBuilders);

                        for (int i = 0; i < aggregators.size(); i++) {
                            Aggregator aggregator = aggregators.get(i);
                            BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
                            aggregator.evaluate(groupId, output);
                        }

                        groupId++;
                    }
View Full Code Here

        checkState(channelSet != null, "Set has not been built yet");
        checkState(outputPage == null, "Operator still has pending output");

        // create the block builder for the new boolean column
        // we know the exact size required for the block
        BlockBuilder blockBuilder = BOOLEAN.createFixedSizeBlockBuilder(page.getPositionCount());

        Block probeJoinBlock = page.getBlock(probeJoinChannel);

        // update hashing strategy to use probe cursor
        for (int position = 0; position < page.getPositionCount(); position++) {
            if (probeJoinBlock.isNull(position)) {
                blockBuilder.appendNull();
            }
            else {
                boolean contains = channelSet.contains(position, probeJoinBlock);
                if (!contains && channelSet.containsNull()) {
                    blockBuilder.appendNull();
                }
                else {
                    blockBuilder.appendBoolean(contains);
                }
            }
        }

        // add the new boolean column to the page
        Block[] sourceBlocks = page.getBlocks();
        Block[] outputBlocks = new Block[sourceBlocks.length + 1]; // +1 for the single boolean output channel

        System.arraycopy(sourceBlocks, 0, outputBlocks, 0, sourceBlocks.length);
        outputBlocks[sourceBlocks.length] = blockBuilder.build();

        outputPage = new Page(outputBlocks);
    }
View Full Code Here

    }

    private void addInputWithSampling(Page page, int sampleWeightChannel)
    {
        Block sampleWeightBlock = page.getBlock(sampleWeightChannel);
        BlockBuilder builder = BIGINT.createBlockBuilder(new BlockBuilderStatus());

        int rowsToCopy = 0;
        // Build the sample weight block, and count how many rows of data to copy
        for (int position = 0; position < sampleWeightBlock.getPositionCount() && remainingLimit > 0; position++) {
            rowsToCopy++;
            long sampleWeight = sampleWeightBlock.getLong(position);
            if (sampleWeight <= remainingLimit) {
                builder.appendLong(sampleWeight);
            }
            else {
                builder.appendLong(remainingLimit);
            }
            remainingLimit -= sampleWeight;
        }

        if (remainingLimit >= 0 && rowsToCopy == page.getPositionCount()) {
            nextPage = page;
        }
        else {
            Block[] blocks = new Block[page.getChannelCount()];
            blocks[sampleWeightChannel] = builder.build();
            for (int channel = 0; channel < page.getChannelCount(); channel++) {
                if (channel == sampleWeightChannel) {
                    continue;
                }
                Block block = page.getBlock(channel);
View Full Code Here

    public Page getOutput()
    {
        // Build the weight block, giving all distinct rows a weight of one. advance() handles splitting rows with weight > 1, if they're distinct
        while (!pageBuilder.isFull() && advance()) {
            for (int i = 0; i < blocks.length; i++) {
                BlockBuilder builder = pageBuilder.getBlockBuilder(i);
                if (i == sampleWeightChannel) {
                    if (distinct) {
                        builder.appendLong(1);
                    }
                    else {
                        builder.appendLong(sampleWeight);
                    }
                }
                else {
                    blocks[i].appendTo(position, builder);
                }
View Full Code Here

    public GroupByIdBlock getGroupIds(Page page)
    {
        int positionCount = page.getPositionCount();

        // we know the exact size required for the block
        BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(positionCount);

        // index pages
        Block[] blocks = page.getBlocks();
        for (int position = 0; position < page.getPositionCount(); position++) {
            // get the group for the current row
            int groupId = putIfAbsent(position, blocks);

            // output the group id for this row
            blockBuilder.appendLong(groupId);
        }

        Block block = blockBuilder.build();
        return new GroupByIdBlock(nextGroupId, block);
    }
View Full Code Here

        }

        public void appendValuesTo(int position, BlockBuilder... builders)
        {
            for (int i = 0; i < blockBuilders.size(); i++) {
                BlockBuilder channel = blockBuilders.get(i);
                channel.appendTo(position, builders[i]);
            }
        }
View Full Code Here

        private void addValue(int hashPosition, int position, Block block)
        {
            // add the row to the open page
            int pageIndex = blocks.size() - 1;
            BlockBuilder blockBuilder = blocks.get(pageIndex);
            block.appendTo(position, blockBuilder);

            // record new value
            long address = encodeSyntheticAddress(pageIndex, blockBuilder.getPositionCount() - 1);
            key[hashPosition] = address;

            // create new block builder if this block is full
            if (blockBuilder.isFull()) {
                completedBlocksMemorySize += blockBuilder.getSizeInBytes();

                blockBuilder = type.createBlockBuilder(new BlockBuilderStatus());
                this.blocks.add(blockBuilder);
            }
View Full Code Here

                    finishing = true;
                    break;
                }

                for (int column = 0; column < types.size(); column++) {
                    BlockBuilder output = pageBuilder.getBlockBuilder(column);
                    if (cursor.isNull(column)) {
                        output.appendNull();
                    }
                    else {
                        Type type = getTypes().get(column);
                        Class<?> javaType = type.getJavaType();
                        if (javaType == boolean.class) {
                            output.appendBoolean(cursor.getBoolean(column));
                        }
                        else if (javaType == long.class) {
                            output.appendLong(cursor.getLong(column));
                        }
                        else if (javaType == double.class) {
                            output.appendDouble(cursor.getDouble(column));
                        }
                        else if (javaType == Slice.class) {
                            output.appendSlice(cursor.getSlice(column));
                        }
                        else {
                            throw new AssertionError("Unimplemented type: " + javaType.getName());
                        }
                    }
View Full Code Here

TOP

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

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.