Search in sources :

Example 51 with BlockBuilder

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

the class TestTinyintArrayType method getGreaterValue.

@Override
protected Object getGreaterValue(Object value) {
    Block block = (Block) value;
    BlockBuilder blockBuilder = TINYINT.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        TINYINT.appendTo(block, i, blockBuilder);
    }
    TINYINT.writeLong(blockBuilder, 1L);
    return blockBuilder.build();
}
Also used : Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 52 with BlockBuilder

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

the class TestUuidOperators method hashFromType.

private static long hashFromType(String uuidString) {
    BlockBuilder blockBuilder = UUID.createBlockBuilder(null, 1);
    UUID.writeSlice(blockBuilder, castFromVarcharToUuid(utf8Slice(uuidString)));
    Block block = blockBuilder.build();
    return UUID.hash(block, 0);
}
Also used : Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 53 with BlockBuilder

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

the class MongoPageSource method getNextPage.

@Override
public Page getNextPage() {
    verify(pageBuilder.isEmpty());
    for (int i = 0; i < ROWS_PER_REQUEST; i++) {
        if (!cursor.hasNext()) {
            finished = true;
            break;
        }
        currentDoc = cursor.next();
        pageBuilder.declarePosition();
        for (int column = 0; column < columnTypes.size(); column++) {
            BlockBuilder output = pageBuilder.getBlockBuilder(column);
            appendTo(columnTypes.get(column), currentDoc.get(columnNames.get(column)), output);
        }
    }
    Page page = pageBuilder.build();
    pageBuilder.reset();
    completedBytes += page.getSizeInBytes();
    completedPositions += page.getPositionCount();
    return page;
}
Also used : Page(com.facebook.presto.common.Page) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 54 with BlockBuilder

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

the class TestDictionaryColumnWriter method testDictionary.

private List<StripeFooter> testDictionary(Type type, OrcEncoding encoding, OrcWriterOptions orcWriterOptions, DirectConversionTester directConversionTester, List<?> values) throws IOException {
    List<Type> types = ImmutableList.of(type);
    try (TempFile tempFile = new TempFile()) {
        OrcWriter writer = createOrcWriter(tempFile.getFile(), encoding, ZSTD, Optional.empty(), types, orcWriterOptions, new OrcWriterStats());
        int index = 0;
        int batchId = 0;
        while (index < values.size()) {
            int end = Math.min(index + BATCH_ROWS, values.size());
            BlockBuilder blockBuilder = type.createBlockBuilder(null, end - index);
            appendListToBlock(type, values, blockBuilder, index, end);
            Block[] blocks = new Block[] { blockBuilder.build() };
            writer.write(new Page(blocks));
            directConversionTester.validate(batchId, writer);
            batchId++;
            index = end;
        }
        writer.close();
        writer.validate(new FileOrcDataSource(tempFile.getFile(), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), true));
        index = 0;
        try (OrcSelectiveRecordReader reader = createCustomOrcSelectiveRecordReader(tempFile, encoding, OrcPredicate.TRUE, type, INITIAL_BATCH_SIZE, true, false)) {
            while (index < values.size()) {
                Page page = reader.getNextPage();
                if (page == null) {
                    break;
                }
                Block block = page.getBlock(0).getLoadedBlock();
                index = verifyBlock(type, values, index, block);
            }
            assertEquals(index, values.size());
        }
        return OrcTester.getStripes(tempFile.getFile(), encoding);
    }
}
Also used : OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) OrcTester.createOrcWriter(com.facebook.presto.orc.OrcTester.createOrcWriter) Page(com.facebook.presto.common.Page) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) DataSize(io.airlift.units.DataSize) Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 55 with BlockBuilder

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

the class TestDictionaryColumnWriter method appendListToBlock.

private void appendListToBlock(Type type, List<?> values, BlockBuilder blockBuilder, int startIndex, int endIndex) {
    while (startIndex < endIndex) {
        Object value = values.get(startIndex++);
        if (value == null) {
            blockBuilder.appendNull();
        } else {
            if (isArrayType(type)) {
                List<?> childList = (List<?>) value;
                BlockBuilder childBlockBuilder = blockBuilder.beginBlockEntry();
                appendListToBlock(type.getTypeParameters().get(0), childList, childBlockBuilder, 0, childList.size());
                blockBuilder.closeEntry();
            } else if (type.equals(VARCHAR)) {
                type.writeSlice(blockBuilder, utf8Slice((String) value));
            } else {
                Number number = (Number) value;
                type.writeLong(blockBuilder, number.longValue());
            }
        }
    }
}
Also used : List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) 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