Search in sources :

Example 1 with FileOrcDataSource

use of com.facebook.presto.orc.FileOrcDataSource in project presto by prestodb.

the class TestWriterBlockRawSize method testFileMetadataRawSize.

@Test
public void testFileMetadataRawSize() throws IOException {
    Type type = INTEGER;
    List<Type> types = ImmutableList.of(type);
    int numBlocksPerRowGroup = 3;
    int numBlocksPerStripe = numBlocksPerRowGroup * 5;
    int numStripes = 4;
    int numBlocksPerFile = numBlocksPerStripe * numStripes + 1;
    BlockBuilder blockBuilder = type.createBlockBuilder(null, NUM_ELEMENTS * 2);
    for (int i = 0; i < NUM_ELEMENTS; i++) {
        blockBuilder.appendNull();
        type.writeLong(blockBuilder, i);
    }
    long blockRawSize = ((FixedWidthType) type).getFixedSize() * NUM_ELEMENTS + NUM_ELEMENTS;
    Block block = blockBuilder.build();
    Block[] blocks = new Block[] { block };
    OrcWriterOptions writerOptions = OrcWriterOptions.builder().withRowGroupMaxRowCount(block.getPositionCount() * numBlocksPerRowGroup).withFlushPolicy(DefaultOrcWriterFlushPolicy.builder().withStripeMaxRowCount(block.getPositionCount() * numBlocksPerStripe).build()).build();
    for (OrcEncoding encoding : OrcEncoding.values()) {
        try (TempFile tempFile = new TempFile()) {
            OrcWriter writer = createOrcWriter(tempFile.getFile(), encoding, ZSTD, Optional.empty(), types, writerOptions, new OrcWriterStats());
            for (int i = 0; i < numBlocksPerFile; i++) {
                writer.write(new Page(blocks));
            }
            writer.close();
            writer.validate(new FileOrcDataSource(tempFile.getFile(), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), true));
            Footer footer = OrcTester.getFileMetadata(tempFile.getFile(), encoding).getFooter();
            verifyValue(encoding, footer.getRawSize(), blockRawSize * numBlocksPerFile);
            assertEquals(footer.getStripes().size(), numStripes + 1);
            int numBlocksRemaining = numBlocksPerFile;
            for (StripeInformation stripeInfo : footer.getStripes()) {
                int numBlocksInStripe = Math.min(numBlocksRemaining, numBlocksPerStripe);
                verifyValue(encoding, stripeInfo.getRawDataSize(), blockRawSize * numBlocksInStripe);
                numBlocksRemaining -= numBlocksInStripe;
            }
        }
    }
}
Also used : OrcWriterStats(com.facebook.presto.orc.OrcWriterStats) OrcWriter(com.facebook.presto.orc.OrcWriter) OrcTester.createOrcWriter(com.facebook.presto.orc.OrcTester.createOrcWriter) Page(com.facebook.presto.common.Page) OrcEncoding(com.facebook.presto.orc.OrcEncoding) OrcWriterOptions(com.facebook.presto.orc.OrcWriterOptions) TestOrcMapNullKey.createMapType(com.facebook.presto.orc.TestOrcMapNullKey.createMapType) TimestampType(com.facebook.presto.common.type.TimestampType) ArrayType(com.facebook.presto.common.type.ArrayType) OrcType(com.facebook.presto.orc.metadata.OrcType) Type(com.facebook.presto.common.type.Type) FixedWidthType(com.facebook.presto.common.type.FixedWidthType) RowType(com.facebook.presto.common.type.RowType) TempFile(com.facebook.presto.orc.TempFile) FileOrcDataSource(com.facebook.presto.orc.FileOrcDataSource) DataSize(io.airlift.units.DataSize) Footer(com.facebook.presto.orc.metadata.Footer) RowBlock(com.facebook.presto.common.block.RowBlock) Block(com.facebook.presto.common.block.Block) StripeInformation(com.facebook.presto.orc.metadata.StripeInformation) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) FixedWidthType(com.facebook.presto.common.type.FixedWidthType) Test(org.testng.annotations.Test)

Example 2 with FileOrcDataSource

use of com.facebook.presto.orc.FileOrcDataSource in project presto by prestodb.

the class OrcStorageManager method computeShardStats.

private List<ColumnStats> computeShardStats(File file) {
    try (OrcDataSource dataSource = fileOrcDataSource(defaultReaderAttributes, file)) {
        OrcReader reader = new OrcReader(dataSource, new OrcMetadataReader(), defaultReaderAttributes.getMaxMergeDistance(), defaultReaderAttributes.getMaxReadSize());
        ImmutableList.Builder<ColumnStats> list = ImmutableList.builder();
        for (ColumnInfo info : getColumnInfo(reader)) {
            computeColumnStats(reader, info.getColumnId(), info.getType()).ifPresent(list::add);
        }
        return list.build();
    } catch (IOException e) {
        throw new PrestoException(RAPTOR_ERROR, "Failed to read file: " + file, e);
    }
}
Also used : FileOrcDataSource(com.facebook.presto.orc.FileOrcDataSource) OrcDataSource(com.facebook.presto.orc.OrcDataSource) OrcReader(com.facebook.presto.orc.OrcReader) ImmutableList(com.google.common.collect.ImmutableList) ColumnStats(com.facebook.presto.raptor.metadata.ColumnStats) ShardStats.computeColumnStats(com.facebook.presto.raptor.storage.ShardStats.computeColumnStats) OrcMetadataReader(com.facebook.presto.orc.metadata.OrcMetadataReader) ColumnInfo(com.facebook.presto.raptor.metadata.ColumnInfo) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException)

Aggregations

FileOrcDataSource (com.facebook.presto.orc.FileOrcDataSource)2 Page (com.facebook.presto.common.Page)1 Block (com.facebook.presto.common.block.Block)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 RowBlock (com.facebook.presto.common.block.RowBlock)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 FixedWidthType (com.facebook.presto.common.type.FixedWidthType)1 RowType (com.facebook.presto.common.type.RowType)1 TimestampType (com.facebook.presto.common.type.TimestampType)1 Type (com.facebook.presto.common.type.Type)1 OrcDataSource (com.facebook.presto.orc.OrcDataSource)1 OrcEncoding (com.facebook.presto.orc.OrcEncoding)1 OrcReader (com.facebook.presto.orc.OrcReader)1 OrcTester.createOrcWriter (com.facebook.presto.orc.OrcTester.createOrcWriter)1 OrcWriter (com.facebook.presto.orc.OrcWriter)1 OrcWriterOptions (com.facebook.presto.orc.OrcWriterOptions)1 OrcWriterStats (com.facebook.presto.orc.OrcWriterStats)1 TempFile (com.facebook.presto.orc.TempFile)1 TestOrcMapNullKey.createMapType (com.facebook.presto.orc.TestOrcMapNullKey.createMapType)1 Footer (com.facebook.presto.orc.metadata.Footer)1