Search in sources :

Example 91 with BlockBuilder

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

the class MapConstructor method createMap.

@UsedByGeneratedCode
public static Block createMap(MapType mapType, Block keyBlock, Block valueBlock) {
    BlockBuilder blockBuilder = new InterleavedBlockBuilder(mapType.getTypeParameters(), new BlockBuilderStatus(), keyBlock.getPositionCount() * 2);
    checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, "Key and value arrays must be the same length");
    for (int i = 0; i < keyBlock.getPositionCount(); i++) {
        if (keyBlock.isNull(i)) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
        }
        mapType.getKeyType().appendTo(keyBlock, i, blockBuilder);
        mapType.getValueType().appendTo(valueBlock, i, blockBuilder);
    }
    return blockBuilder.build();
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) 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) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 92 with BlockBuilder

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

the class ByteEncoding method decodeColumn.

@Override
public Block decodeColumn(ColumnData columnData) {
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), size);
    Slice slice = columnData.getSlice();
    for (int i = 0; i < size; i++) {
        int length = columnData.getLength(i);
        if (length != 0) {
            checkState(length == SIZE_OF_BYTE, "Bytes should be 1 byte");
            type.writeLong(builder, slice.getByte(columnData.getOffset(i)));
        } else {
            builder.appendNull();
        }
    }
    return builder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 93 with BlockBuilder

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

the class StringEncoding method decodeColumn.

@Override
public Block decodeColumn(ColumnData columnData) {
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), size);
    Slice slice = columnData.getSlice();
    for (int i = 0; i < size; i++) {
        int length = columnData.getLength(i);
        if (length > 0) {
            int offset = columnData.getOffset(i);
            if ((length == 1) && slice.getByte(offset) == HIVE_EMPTY_STRING_BYTE) {
                type.writeSlice(builder, EMPTY_SLICE);
            } else {
                length = calculateTruncationLength(type, slice, offset, length);
                type.writeSlice(builder, slice.slice(offset, length));
            }
        } else {
            builder.appendNull();
        }
    }
    return builder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 94 with BlockBuilder

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

the class StructEncoding method decodeValueInto.

@Override
public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length) {
    int fieldId = 0;
    int nullByte = 0;
    int elementOffset = offset;
    BlockBuilder rowBuilder = builder.beginBlockEntry();
    while (fieldId < structFields.size() && elementOffset < offset + length) {
        BinaryColumnEncoding field = structFields.get(fieldId);
        // null byte prefixes every 8 fields
        if ((fieldId % 8) == 0) {
            nullByte = slice.getByte(elementOffset);
            elementOffset++;
        }
        // read field
        if ((nullByte & (1 << (fieldId % 8))) != 0) {
            int valueOffset = field.getValueOffset(slice, elementOffset);
            int valueLength = field.getValueLength(slice, elementOffset);
            field.decodeValueInto(rowBuilder, slice, elementOffset + valueOffset, valueLength);
            elementOffset = elementOffset + valueOffset + valueLength;
        } else {
            rowBuilder.appendNull();
        }
        fieldId++;
    }
    // so we fill with nulls
    while (fieldId < structFields.size()) {
        rowBuilder.appendNull();
        fieldId++;
    }
    builder.closeEntry();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 95 with BlockBuilder

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

the class BlockEncoding method decodeColumn.

@Override
public final Block decodeColumn(ColumnData columnData) throws RcFileCorruptionException {
    int size = columnData.rowCount();
    Slice slice = columnData.getSlice();
    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), size);
    for (int i = 0; i < size; i++) {
        int length = columnData.getLength(i);
        int offset = columnData.getOffset(i);
        if (!isNullSequence(slice, offset, length)) {
            decodeValueInto(1, builder, slice, offset, length);
        } else {
            builder.appendNull();
        }
    }
    return builder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Aggregations

BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)290 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)211 Block (com.facebook.presto.spi.block.Block)56 Slice (io.airlift.slice.Slice)53 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)39 Test (org.testng.annotations.Test)38 Type (com.facebook.presto.spi.type.Type)33 SqlType (com.facebook.presto.spi.function.SqlType)24 ArrayType (com.facebook.presto.type.ArrayType)19 Page (com.facebook.presto.spi.Page)18 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)17 TypeParameter (com.facebook.presto.spi.function.TypeParameter)15 MapType (com.facebook.presto.type.MapType)14 RowType (com.facebook.presto.type.RowType)14 TypeJsonUtils.appendToBlockBuilder (com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)13 PageBuilder (com.facebook.presto.spi.PageBuilder)12 ImmutableList (com.google.common.collect.ImmutableList)12 PrestoException (com.facebook.presto.spi.PrestoException)11 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)11 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)10