Search in sources :

Example 11 with BlockBuilder

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

the class TimestampEncoding method decodeColumn.

@Override
public Block decodeColumn(ColumnData columnData) {
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(null, 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, parseTimestamp(slice, offset, length));
        }
    }
    return builder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 12 with BlockBuilder

use of com.facebook.presto.common.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(null, 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.common.block.BlockBuilder)

Example 13 with BlockBuilder

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

the class DecimalEncoding method decodeColumn.

@Override
public Block decodeColumn(ColumnData columnData) {
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(null, 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.common.block.BlockBuilder)

Example 14 with BlockBuilder

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

the class FloatEncoding method decodeColumn.

@Override
public Block decodeColumn(ColumnData columnData) {
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(null, 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.common.block.BlockBuilder)

Example 15 with BlockBuilder

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

the class LongEncoding method decodeColumn.

@Override
public Block decodeColumn(ColumnData columnData) {
    int size = columnData.rowCount();
    BlockBuilder builder = type.createBlockBuilder(null, 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.common.block.BlockBuilder)

Aggregations

BlockBuilder (com.facebook.presto.common.block.BlockBuilder)493 Block (com.facebook.presto.common.block.Block)124 Test (org.testng.annotations.Test)106 Slice (io.airlift.slice.Slice)85 Type (com.facebook.presto.common.type.Type)76 Page (com.facebook.presto.common.Page)49 SqlType (com.facebook.presto.spi.function.SqlType)46 ArrayType (com.facebook.presto.common.type.ArrayType)44 MapType (com.facebook.presto.common.type.MapType)32 RowType (com.facebook.presto.common.type.RowType)28 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)26 RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)22 PrestoException (com.facebook.presto.spi.PrestoException)22 PageBuilder (com.facebook.presto.common.PageBuilder)21 StructuralTestUtil.appendToBlockBuilder (com.facebook.presto.util.StructuralTestUtil.appendToBlockBuilder)21 Map (java.util.Map)21 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)20 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)19 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)18 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)18