Search in sources :

Example 46 with BlockBuilder

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

the class ParquetReader method rewriteLongArrayBlock.

private static Block rewriteLongArrayBlock(LongArrayBlock longArrayBlock, Type targetType) {
    int positionCount = longArrayBlock.getPositionCount();
    BlockBuilder newBlockBuilder = targetType.createBlockBuilder(null, positionCount);
    for (int position = 0; position < positionCount; position++) {
        if (longArrayBlock.isNull(position)) {
            newBlockBuilder.appendNull();
        } else {
            targetType.writeLong(newBlockBuilder, longArrayBlock.getLong(position, 0));
        }
    }
    return newBlockBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 47 with BlockBuilder

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

the class AbstractColumnReader method readNext.

@Override
public ColumnChunk readNext() {
    IntList definitionLevels = new IntArrayList();
    IntList repetitionLevels = new IntArrayList();
    seek();
    BlockBuilder blockBuilder = field.getType().createBlockBuilder(null, nextBatchSize);
    int valueCount = 0;
    while (valueCount < nextBatchSize) {
        if (page == null) {
            readNextPage();
        }
        int valuesToRead = Math.min(remainingValueCountInPage, nextBatchSize - valueCount);
        if (valuesToRead == 0) {
            // When we break here, we could end up with valueCount < nextBatchSize, this is because we may skip reading values in readValues()
            break;
        }
        readValues(blockBuilder, valuesToRead, field.getType(), definitionLevels, repetitionLevels);
        valueCount += valuesToRead;
    }
    readOffset = 0;
    nextBatchSize = 0;
    return new ColumnChunk(blockBuilder.build(), definitionLevels.toIntArray(), repetitionLevels.toIntArray());
}
Also used : IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) IntList(it.unimi.dsi.fastutil.ints.IntList) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 48 with BlockBuilder

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

the class StructuralTestUtil method rowBlockOf.

public static Block rowBlockOf(List<Type> parameterTypes, Object... values) {
    RowType rowType = RowType.anonymous(parameterTypes);
    BlockBuilder blockBuilder = rowType.createBlockBuilder(null, 1);
    BlockBuilder singleRowBlockWriter = blockBuilder.beginBlockEntry();
    for (int i = 0; i < values.length; i++) {
        appendToBlockBuilder(parameterTypes.get(i), values[i], singleRowBlockWriter);
    }
    blockBuilder.closeEntry();
    return rowType.getObject(blockBuilder, 0);
}
Also used : RowType(com.facebook.presto.common.type.RowType) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) StructuralTestUtil.appendToBlockBuilder(com.facebook.presto.util.StructuralTestUtil.appendToBlockBuilder)

Example 49 with BlockBuilder

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

the class StructuralTestUtil method mapBlockOf.

public static Block mapBlockOf(Type keyType, Type valueType, Object[] keys, Object[] values) {
    checkArgument(keys.length == values.length, "keys/values must have the same length");
    MapType mapType = mapType(keyType, valueType);
    BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 10);
    BlockBuilder singleMapBlockWriter = blockBuilder.beginBlockEntry();
    for (int i = 0; i < keys.length; i++) {
        Object key = keys[i];
        Object value = values[i];
        appendToBlockBuilder(keyType, key, singleMapBlockWriter);
        appendToBlockBuilder(valueType, value, singleMapBlockWriter);
    }
    blockBuilder.closeEntry();
    return mapType.getObject(blockBuilder, 0);
}
Also used : MapType(com.facebook.presto.common.type.MapType) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) StructuralTestUtil.appendToBlockBuilder(com.facebook.presto.util.StructuralTestUtil.appendToBlockBuilder)

Example 50 with BlockBuilder

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

the class TestLearnAggregations method assertLearnClassifer.

private static void assertLearnClassifer(Accumulator accumulator) {
    accumulator.addInput(getPage());
    BlockBuilder finalOut = accumulator.getFinalType().createBlockBuilder(null, 1);
    accumulator.evaluateFinal(finalOut);
    Block block = finalOut.build();
    Slice slice = accumulator.getFinalType().getSlice(block, 0);
    Model deserialized = ModelUtils.deserialize(slice);
    assertNotNull(deserialized, "deserialization failed");
    assertTrue(deserialized instanceof Classifier, "deserialized model is not a classifier");
}
Also used : Slice(io.airlift.slice.Slice) Block(com.facebook.presto.common.block.Block) 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