Search in sources :

Example 1 with BlockBuilder

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

the class LongDictionaryBatchStreamReader method readBlock.

@Override
public Block readBlock() 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 length reader
            readOffset = presentStream.countBitsSet(readOffset);
        }
        if (inDictionaryStream != null) {
            inDictionaryStream.skip(readOffset);
        }
        if (readOffset > 0) {
            if (dataStream == null) {
                throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
            }
            dataStream.skip(readOffset);
        }
    }
    BlockBuilder builder = type.createBlockBuilder(null, nextBatchSize);
    if (presentStream == null) {
        // Data doesn't have nulls
        if (dataStream == null) {
            throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
        }
        if (inDictionaryStream == null) {
            for (int i = 0; i < nextBatchSize; i++) {
                type.writeLong(builder, dictionary[((int) dataStream.next())]);
            }
        } else {
            for (int i = 0; i < nextBatchSize; i++) {
                long id = dataStream.next();
                if (inDictionaryStream.nextBit()) {
                    type.writeLong(builder, dictionary[(int) id]);
                } else {
                    type.writeLong(builder, id);
                }
            }
        }
    } else {
        // Data has nulls
        if (dataStream == null) {
            // The only valid case for dataStream is null when data has nulls is that all values are nulls.
            int nullValues = presentStream.getUnsetBits(nextBatchSize);
            if (nullValues != nextBatchSize) {
                throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
            }
            for (int i = 0; i < nextBatchSize; i++) {
                builder.appendNull();
            }
        } else {
            for (int i = 0; i < nextBatchSize; i++) {
                if (!presentStream.nextBit()) {
                    builder.appendNull();
                } else {
                    long id = dataStream.next();
                    if (inDictionaryStream == null || inDictionaryStream.nextBit()) {
                        type.writeLong(builder, dictionary[(int) id]);
                    } else {
                        type.writeLong(builder, id);
                    }
                }
            }
        }
    }
    readOffset = 0;
    nextBatchSize = 0;
    return builder.build();
}
Also used : OrcCorruptionException(com.facebook.presto.orc.OrcCorruptionException) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 2 with BlockBuilder

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

the class MapFlatSelectiveStreamReader method getIntegerKeysBlock.

private Block getIntegerKeysBlock(List<DwrfSequenceEncoding> sequenceEncodings) {
    Type keyType;
    switch(keyOrcTypeKind) {
        case BYTE:
            keyType = TinyintType.TINYINT;
            break;
        case SHORT:
            keyType = SmallintType.SMALLINT;
            break;
        case INT:
            keyType = IntegerType.INTEGER;
            break;
        case LONG:
            keyType = BigintType.BIGINT;
            break;
        default:
            throw new IllegalArgumentException("Unsupported flat map key type: " + keyOrcTypeKind);
    }
    BlockBuilder blockBuilder = keyType.createBlockBuilder(null, sequenceEncodings.size());
    for (int i = 0; i < keyCount; i++) {
        keyType.writeLong(blockBuilder, sequenceEncodings.get(keyIndices[i]).getKey().getIntKey());
    }
    return blockBuilder.build();
}
Also used : TinyintType(com.facebook.presto.common.type.TinyintType) BigintType(com.facebook.presto.common.type.BigintType) SmallintType(com.facebook.presto.common.type.SmallintType) MapType(com.facebook.presto.common.type.MapType) IntegerType(com.facebook.presto.common.type.IntegerType) Type(com.facebook.presto.common.type.Type) FixedWidthType(com.facebook.presto.common.type.FixedWidthType) VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 3 with BlockBuilder

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

the class TestTemporalFunction method testTimestampBlock.

@Test
void testTimestampBlock() {
    BlockBuilder blockBuilder = TIMESTAMP.createBlockBuilder(null, 4);
    // start and end of UTC day
    TIMESTAMP.writeLong(blockBuilder, UTC_TIME.getMillis());
    TIMESTAMP.writeLong(blockBuilder, UTC_TIME.getMillis() + Duration.ofHours(23).toMillis());
    // start and end of PST day
    TIMESTAMP.writeLong(blockBuilder, PST_TIME.getMillis());
    TIMESTAMP.writeLong(blockBuilder, PST_TIME.getMillis() + Duration.ofHours(23).toMillis());
    Block block = blockBuilder.build();
    TemporalFunction temporalFunction = new TemporalFunction(UTC);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 0), 1);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 1), 1);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 2), 1);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 3), 2);
    temporalFunction = new TemporalFunction(PST);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 0), 0);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 1), 1);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 2), 1);
    assertEquals(temporalFunction.getDay(TIMESTAMP, block, 3), 1);
}
Also used : Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 4 with BlockBuilder

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

Example 5 with BlockBuilder

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

the class DateEncoding 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 {
            // noinspection deprecation
            type.writeLong(builder, parseDate(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