Search in sources :

Example 26 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class TestJsonType method createTestBlock.

public static Block createTestBlock() {
    BlockBuilder blockBuilder = JSON.createBlockBuilder(new BlockBuilderStatus(), 1);
    Slice slice = Slices.utf8Slice("{\"x\":1, \"y\":2}");
    JSON.writeSlice(blockBuilder, slice);
    return blockBuilder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 27 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class MLFunctions method featuresHelper.

private static Block featuresHelper(double... features) {
    BlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(BigintType.BIGINT, DoubleType.DOUBLE), new BlockBuilderStatus(), features.length);
    for (int i = 0; i < features.length; i++) {
        BigintType.BIGINT.writeLong(blockBuilder, i);
        DoubleType.DOUBLE.writeDouble(blockBuilder, features[i]);
    }
    return blockBuilder.build();
}
Also used : InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 28 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class DecimalStreamReader method readBlock.

@Override
public Block readBlock(Type type) throws IOException {
    DecimalType decimalType = (DecimalType) type;
    if (!rowGroupOpen) {
        openRowGroup();
    }
    seekToOffset();
    allocateVectors();
    BlockBuilder builder = decimalType.createBlockBuilder(new BlockBuilderStatus(), nextBatchSize);
    if (presentStream == null) {
        if (decimalStream == null) {
            throw new OrcCorruptionException("Value is not null but decimal stream is not present");
        }
        if (scaleStream == null) {
            throw new OrcCorruptionException("Value is not null but scale stream is not present");
        }
        Arrays.fill(nullVector, false);
        scaleStream.nextLongVector(nextBatchSize, scaleVector);
        if (decimalType.isShort()) {
            decimalStream.nextShortDecimalVector(nextBatchSize, builder, decimalType, scaleVector);
        } else {
            decimalStream.nextLongDecimalVector(nextBatchSize, builder, decimalType, scaleVector);
        }
    } else {
        int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
        if (nullValues != nextBatchSize) {
            if (decimalStream == null) {
                throw new OrcCorruptionException("Value is not null but decimal stream is not present");
            }
            if (scaleStream == null) {
                throw new OrcCorruptionException("Value is not null but scale stream is not present");
            }
            scaleStream.nextLongVector(nextBatchSize, scaleVector, nullVector);
            if (decimalType.isShort()) {
                decimalStream.nextShortDecimalVector(nextBatchSize, builder, decimalType, scaleVector, nullVector);
            } else {
                decimalStream.nextLongDecimalVector(nextBatchSize, builder, decimalType, scaleVector, nullVector);
            }
        } else {
            for (int i = 0; i < nextBatchSize; i++) {
                builder.appendNull();
            }
        }
    }
    readOffset = 0;
    nextBatchSize = 0;
    return builder.build();
}
Also used : DecimalType(com.facebook.presto.spi.type.DecimalType) OrcCorruptionException(com.facebook.presto.orc.OrcCorruptionException) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 29 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class DoubleStreamReader method readBlock.

@Override
public Block readBlock(Type type) throws IOException {
    if (!rowGroupOpen) {
        openRowGroup();
    }
    if (readOffset > 0) {
        if (presentStream != null) {
            // skip ahead the present bit reader, but count the set bits
            // and use this as the skip size for the data reader
            readOffset = presentStream.countBitsSet(readOffset);
        }
        if (readOffset > 0) {
            if (dataStream == null) {
                throw new OrcCorruptionException("Value is not null but data stream is not present");
            }
            dataStream.skip(readOffset);
        }
    }
    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), nextBatchSize);
    if (presentStream == null) {
        if (dataStream == null) {
            throw new OrcCorruptionException("Value is not null but data stream is not present");
        }
        dataStream.nextVector(type, nextBatchSize, builder);
    } else {
        if (nullVector.length < nextBatchSize) {
            nullVector = new boolean[nextBatchSize];
        }
        int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
        if (nullValues != nextBatchSize) {
            if (dataStream == null) {
                throw new OrcCorruptionException("Value is not null but data stream is not present");
            }
            dataStream.nextVector(type, nextBatchSize, builder, nullVector);
        } else {
            for (int i = 0; i < nextBatchSize; i++) {
                builder.appendNull();
            }
        }
    }
    readOffset = 0;
    nextBatchSize = 0;
    return builder.build();
}
Also used : OrcCorruptionException(com.facebook.presto.orc.OrcCorruptionException) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 30 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class ListStreamReader method readBlock.

@Override
public Block readBlock(Type type) throws IOException {
    if (!rowGroupOpen) {
        openRowGroup();
    }
    if (readOffset > 0) {
        if (presentStream != null) {
            // skip ahead the present bit reader, but count the set bits
            // and use this as the skip size for the data reader
            readOffset = presentStream.countBitsSet(readOffset);
        }
        if (readOffset > 0) {
            if (lengthStream == null) {
                throw new OrcCorruptionException("Value is not null but data stream is not present");
            }
            long elementSkipSize = lengthStream.sum(readOffset);
            elementStreamReader.prepareNextRead(toIntExact(elementSkipSize));
        }
    }
    // The length vector could be reused, but this simplifies the code below by
    // taking advantage of null entries being initialized to zero.  The vector
    // could be reinitialized for each loop, but that is likely just as expensive
    // as allocating a new array
    int[] lengthVector = new int[nextBatchSize];
    boolean[] nullVector = new boolean[nextBatchSize];
    if (presentStream == null) {
        if (lengthStream == null) {
            throw new OrcCorruptionException("Value is not null but data stream is not present");
        }
        lengthStream.nextIntVector(nextBatchSize, lengthVector);
    } else {
        int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
        if (nullValues != nextBatchSize) {
            if (lengthStream == null) {
                throw new OrcCorruptionException("Value is not null but data stream is not present");
            }
            lengthStream.nextIntVector(nextBatchSize, lengthVector, nullVector);
        }
    }
    int[] offsets = new int[nextBatchSize + 1];
    for (int i = 1; i < offsets.length; i++) {
        int length = lengthVector[i - 1];
        offsets[i] = offsets[i - 1] + length;
    }
    Type elementType = type.getTypeParameters().get(0);
    int elementCount = offsets[offsets.length - 1];
    Block elements;
    if (elementCount > 0) {
        elementStreamReader.prepareNextRead(elementCount);
        elements = elementStreamReader.readBlock(elementType);
    } else {
        elements = elementType.createBlockBuilder(new BlockBuilderStatus(), 0).build();
    }
    ArrayBlock arrayBlock = new ArrayBlock(nextBatchSize, nullVector, offsets, elements);
    readOffset = 0;
    nextBatchSize = 0;
    return arrayBlock;
}
Also used : Type(com.facebook.presto.spi.type.Type) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) Block(com.facebook.presto.spi.block.Block) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) OrcCorruptionException(com.facebook.presto.orc.OrcCorruptionException) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Aggregations

BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)227 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)210 Block (com.facebook.presto.spi.block.Block)55 Slice (io.airlift.slice.Slice)43 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)37 Test (org.testng.annotations.Test)35 Type (com.facebook.presto.spi.type.Type)24 SqlType (com.facebook.presto.spi.function.SqlType)20 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)15 ArrayType (com.facebook.presto.type.ArrayType)14 Page (com.facebook.presto.spi.Page)12 TypeJsonUtils.appendToBlockBuilder (com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)12 TypeParameter (com.facebook.presto.spi.function.TypeParameter)11 RowType (com.facebook.presto.type.RowType)11 OrcCorruptionException (com.facebook.presto.orc.OrcCorruptionException)10 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)10 MapType (com.facebook.presto.type.MapType)10 PrestoException (com.facebook.presto.spi.PrestoException)9 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)8 DecimalType (com.facebook.presto.spi.type.DecimalType)8