Search in sources :

Example 11 with OrcBatchRecordReader

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

the class TestOrcStorageManager method testWriter.

@Test
public void testWriter() throws Exception {
    OrcStorageManager manager = createOrcStorageManager();
    List<Long> columnIds = ImmutableList.of(3L, 7L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10));
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello").row(456L, "bye").build();
    sink.appendPages(pages);
    // shard is not recorded until flush
    assertEquals(shardRecorder.getShards().size(), 0);
    sink.flush();
    // shard is recorded after flush
    List<RecordedShard> recordedShards = shardRecorder.getShards();
    assertEquals(recordedShards.size(), 1);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shards.size(), 1);
    ShardInfo shardInfo = Iterables.getOnlyElement(shards);
    UUID shardUuid = shardInfo.getShardUuid();
    File file = new File(storageService.getStorageFile(shardUuid).toString());
    File backupFile = fileBackupStore.getBackupFile(shardUuid);
    assertEquals(recordedShards.get(0).getTransactionId(), TRANSACTION_ID);
    assertEquals(recordedShards.get(0).getShardUuid(), shardUuid);
    assertEquals(shardInfo.getRowCount(), 2);
    assertEquals(shardInfo.getCompressedSize(), file.length());
    assertEquals(shardInfo.getXxhash64(), xxhash64(new RaptorLocalFileSystem(new Configuration()), new Path(file.toURI())));
    // verify primary and backup shard exist
    assertFile(file, "primary shard");
    assertFile(backupFile, "backup shard");
    assertFileEquals(file, backupFile);
    // remove primary shard to force recovery from backup
    assertTrue(file.delete());
    assertTrue(file.getParentFile().delete());
    assertFalse(file.exists());
    recoveryManager.restoreFromBackup(shardUuid, shardInfo.getCompressedSize(), OptionalLong.of(shardInfo.getXxhash64()));
    FileSystem fileSystem = new LocalOrcDataEnvironment().getFileSystem(DEFAULT_RAPTOR_CONTEXT);
    try (OrcDataSource dataSource = manager.openShard(fileSystem, shardUuid, READER_ATTRIBUTES)) {
        OrcBatchRecordReader reader = createReader(dataSource, columnIds, columnTypes);
        assertEquals(reader.nextBatch(), 2);
        Block column0 = reader.readBlock(0);
        assertEquals(column0.isNull(0), false);
        assertEquals(column0.isNull(1), false);
        assertEquals(BIGINT.getLong(column0, 0), 123L);
        assertEquals(BIGINT.getLong(column0, 1), 456L);
        Block column1 = reader.readBlock(1);
        assertEquals(createVarcharType(10).getSlice(column1, 0), utf8Slice("hello"));
        assertEquals(createVarcharType(10).getSlice(column1, 1), utf8Slice("bye"));
        assertEquals(reader.nextBatch(), -1);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OrcDataSource(com.facebook.presto.orc.OrcDataSource) Configuration(org.apache.hadoop.conf.Configuration) OrcBatchRecordReader(com.facebook.presto.orc.OrcBatchRecordReader) Page(com.facebook.presto.common.Page) RecordedShard(com.facebook.presto.raptor.storage.InMemoryShardRecorder.RecordedShard) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) RaptorLocalFileSystem(com.facebook.presto.raptor.filesystem.RaptorLocalFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) RaptorLocalFileSystem(com.facebook.presto.raptor.filesystem.RaptorLocalFileSystem) OptionalLong(java.util.OptionalLong) LocalOrcDataEnvironment(com.facebook.presto.raptor.filesystem.LocalOrcDataEnvironment) Block(com.facebook.presto.common.block.Block) UUID(java.util.UUID) FileAssert.assertFile(org.testng.FileAssert.assertFile) File(java.io.File) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Aggregations

OrcBatchRecordReader (com.facebook.presto.orc.OrcBatchRecordReader)11 OrcDataSource (com.facebook.presto.orc.OrcDataSource)10 Type (com.facebook.presto.common.type.Type)9 Block (com.facebook.presto.common.block.Block)6 PrestoException (com.facebook.presto.spi.PrestoException)6 ArrayType (com.facebook.presto.common.type.ArrayType)5 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)5 OrcReader (com.facebook.presto.orc.OrcReader)5 OrcReaderOptions (com.facebook.presto.orc.OrcReaderOptions)5 IOException (java.io.IOException)5 Page (com.facebook.presto.common.Page)4 RuntimeStats (com.facebook.presto.common.RuntimeStats)4 OrcAggregatedMemoryContext (com.facebook.presto.orc.OrcAggregatedMemoryContext)4 OrcTestingUtil.fileOrcDataSource (com.facebook.presto.raptor.storage.OrcTestingUtil.fileOrcDataSource)4 ImmutableList (com.google.common.collect.ImmutableList)4 File (java.io.File)4 Path (org.apache.hadoop.fs.Path)4 Test (org.testng.annotations.Test)4 DecimalType (com.facebook.presto.common.type.DecimalType)3 RowType (com.facebook.presto.common.type.RowType)3