Search in sources :

Example 6 with InterleavedBlock

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

the class TestInterleavedBlock method testGetSizeInBytes.

@Test
private void testGetSizeInBytes() {
    int numEntries = 2000;
    VarcharType unboundedVarcharType = createUnboundedVarcharType();
    InterleavedBlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(unboundedVarcharType, BIGINT), new BlockBuilderStatus(), numEntries);
    for (int i = 0; i < numEntries; i += 2) {
        unboundedVarcharType.writeString(blockBuilder, String.valueOf(ThreadLocalRandom.current().nextLong()));
        BIGINT.writeLong(blockBuilder, ThreadLocalRandom.current().nextLong());
    }
    InterleavedBlock block = blockBuilder.build();
    List<Block> splitQuarter = splitBlock(block, 4);
    int sizeInBytes = block.getSizeInBytes();
    int quarter1size = splitQuarter.get(0).getSizeInBytes();
    int quarter2size = splitQuarter.get(1).getSizeInBytes();
    int quarter3size = splitQuarter.get(2).getSizeInBytes();
    int quarter4size = splitQuarter.get(3).getSizeInBytes();
    double expectedQuarterSizeMin = sizeInBytes * 0.2;
    double expectedQuarterSizeMax = sizeInBytes * 0.3;
    assertTrue(quarter1size > expectedQuarterSizeMin && quarter1size < expectedQuarterSizeMax, format("quarter1size is %s, should be between %s and %s", quarter1size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter2size > expectedQuarterSizeMin && quarter2size < expectedQuarterSizeMax, format("quarter2size is %s, should be between %s and %s", quarter2size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter3size > expectedQuarterSizeMin && quarter3size < expectedQuarterSizeMax, format("quarter3size is %s, should be between %s and %s", quarter3size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter4size > expectedQuarterSizeMin && quarter4size < expectedQuarterSizeMax, format("quarter4size is %s, should be between %s and %s", quarter4size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertEquals(quarter1size + quarter2size + quarter3size + quarter4size, sizeInBytes);
}
Also used : VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(com.facebook.presto.spi.type.VarcharType) Block(com.facebook.presto.spi.block.Block) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 7 with InterleavedBlock

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

the class ParquetReader method readStruct.

private Block readStruct(Type type, List<String> path, IntList elementOffsets) throws IOException {
    List<TypeSignatureParameter> parameters = type.getTypeSignature().getParameters();
    Block[] blocks = new Block[parameters.size()];
    for (int i = 0; i < parameters.size(); i++) {
        NamedTypeSignature namedTypeSignature = parameters.get(i).getNamedTypeSignature();
        Type fieldType = typeManager.getType(namedTypeSignature.getTypeSignature());
        String name = namedTypeSignature.getName();
        blocks[i] = readBlock(name, fieldType, path, new IntArrayList());
    }
    InterleavedBlock interleavedBlock = new InterleavedBlock(blocks);
    int blockSize = blocks[0].getPositionCount();
    int[] offsets = new int[blockSize + 1];
    for (int i = 1; i < offsets.length; i++) {
        elementOffsets.add(parameters.size());
        offsets[i] = i * parameters.size();
    }
    return new ArrayBlock(blockSize, new boolean[blockSize], offsets, interleavedBlock);
}
Also used : Type(com.facebook.presto.spi.type.Type) MessageType(parquet.schema.MessageType) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) TypeSignatureParameter(com.facebook.presto.spi.type.TypeSignatureParameter) Block(com.facebook.presto.spi.block.Block) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock)

Aggregations

Block (com.facebook.presto.spi.block.Block)7 InterleavedBlock (com.facebook.presto.spi.block.InterleavedBlock)7 ArrayBlock (com.facebook.presto.spi.block.ArrayBlock)5 Type (com.facebook.presto.spi.type.Type)4 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)3 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)3 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)2 MessageType (parquet.schema.MessageType)2 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)1 TypedSet (com.facebook.presto.operator.aggregation.TypedSet)1 OrcCorruptionException (com.facebook.presto.orc.OrcCorruptionException)1 StreamReaders.createStreamReader (com.facebook.presto.orc.reader.StreamReaders.createStreamReader)1 PageBuilder (com.facebook.presto.spi.PageBuilder)1 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)1 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)1 NamedTypeSignature (com.facebook.presto.spi.type.NamedTypeSignature)1 TypeSignatureParameter (com.facebook.presto.spi.type.TypeSignatureParameter)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 VarcharType.createUnboundedVarcharType (com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1