Search in sources :

Example 66 with BlockBuilderStatus

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

the class DecimalEncoding 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 offset = columnData.getOffset(i);
        int length = columnData.getLength(i);
        if (length == 0) {
            builder.appendNull();
        } else if (isShortDecimal(type)) {
            type.writeLong(builder, parseLong(slice, offset));
        } else {
            type.writeSlice(builder, parseSlice(slice, offset));
        }
    }
    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 67 with BlockBuilderStatus

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

the class FloatEncoding 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_FLOAT, "Float should be 4 bytes");
            int intBits = slice.getInt(columnData.getOffset(i));
            // the file format uses big endian
            type.writeLong(builder, Integer.reverseBytes(intBits));
        } 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 68 with BlockBuilderStatus

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

the class LongEncoding 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 offset = columnData.getOffset(i);
        int length = columnData.getLength(i);
        if (length == 0) {
            builder.appendNull();
        } else {
            type.writeLong(builder, readVInt(slice, offset, length));
        }
    }
    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 69 with BlockBuilderStatus

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

the class ShortEncoding 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_SHORT, "Short should be 2 bytes");
            type.writeLong(builder, (long) Short.reverseBytes(slice.getShort(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 70 with BlockBuilderStatus

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

the class FloatEncoding method decodeColumn.

@Override
public Block decodeColumn(ColumnData columnData) throws RcFileCorruptionException {
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), size);
    Slice slice = columnData.getSlice();
    for (int i = 0; i < size; i++) {
        int offset = columnData.getOffset(i);
        int length = columnData.getLength(i);
        if (length == 0 || nullSequence.equals(0, nullSequence.length(), slice, offset, length)) {
            builder.appendNull();
        } else {
            type.writeLong(builder, Float.floatToIntBits(parseFloat(slice, offset, length)));
        }
    }
    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

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