Search in sources :

Example 1 with DEFAULT_RAPTOR_CONTEXT

use of com.facebook.presto.raptor.filesystem.FileSystemUtil.DEFAULT_RAPTOR_CONTEXT in project presto by prestodb.

the class TestOrcStorageManager method testRewriter.

@Test
public void testRewriter() throws Exception {
    OrcStorageManager manager = createOrcStorageManager();
    FileSystem fileSystem = new LocalOrcDataEnvironment().getFileSystem(DEFAULT_RAPTOR_CONTEXT);
    long transactionId = TRANSACTION_ID;
    List<Long> columnIds = ImmutableList.of(3L, 7L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10));
    // create file with 2 rows
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello").row(456L, "bye").build();
    sink.appendPages(pages);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shardRecorder.getShards().size(), 1);
    // delete one row
    BitSet rowsToDelete = new BitSet();
    rowsToDelete.set(0);
    InplaceShardRewriter shardRewriter = (InplaceShardRewriter) manager.createShardRewriter(DEFAULT_RAPTOR_CONTEXT, fileSystem, transactionId, OptionalInt.empty(), shards.get(0).getShardUuid(), 2, Optional.empty(), false, IntStream.range(0, columnIds.size()).boxed().collect(Collectors.toMap(index -> String.valueOf(columnIds.get(index)), columnTypes::get)));
    Collection<Slice> fragments = shardRewriter.rewriteShard(rowsToDelete);
    Slice shardDelta = Iterables.getOnlyElement(fragments);
    ShardDelta shardDeltas = jsonCodec(ShardDelta.class).fromJson(shardDelta.getBytes());
    ShardInfo shardInfo = Iterables.getOnlyElement(shardDeltas.getNewShards());
    // check that output file has one row
    assertEquals(shardInfo.getRowCount(), 1);
    // check that storage file is same as backup file
    File storageFile = new File(storageService.getStorageFile(shardInfo.getShardUuid()).toString());
    File backupFile = fileBackupStore.getBackupFile(shardInfo.getShardUuid());
    assertFileEquals(storageFile, backupFile);
    // verify recorded shard
    List<RecordedShard> recordedShards = shardRecorder.getShards();
    assertEquals(recordedShards.size(), 2);
    assertEquals(recordedShards.get(1).getTransactionId(), TRANSACTION_ID);
    assertEquals(recordedShards.get(1).getShardUuid(), shardInfo.getShardUuid());
}
Also used : Page(com.facebook.presto.common.Page) ShardDeleteDelta(com.facebook.presto.raptor.metadata.ShardDeleteDelta) Arrays(java.util.Arrays) FileSystem(org.apache.hadoop.fs.FileSystem) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Test(org.testng.annotations.Test) OrcTestingUtil.octets(com.facebook.presto.raptor.storage.OrcTestingUtil.octets) AfterMethod(org.testng.annotations.AfterMethod) MoreFutures.getFutureValue(com.facebook.airlift.concurrent.MoreFutures.getFutureValue) Slices.wrappedBuffer(io.airlift.slice.Slices.wrappedBuffer) LocalOrcDataEnvironment(com.facebook.presto.raptor.filesystem.LocalOrcDataEnvironment) Configuration(org.apache.hadoop.conf.Configuration) ShardManager(com.facebook.presto.raptor.metadata.ShardManager) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) FileAssert.assertFile(org.testng.FileAssert.assertFile) OrcDataSource(com.facebook.presto.orc.OrcDataSource) Assert.assertFalse(org.testng.Assert.assertFalse) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) FileBackupStore(com.facebook.presto.raptor.backup.FileBackupStore) NullableValue(com.facebook.presto.common.predicate.NullableValue) JsonCodec.jsonCodec(com.facebook.airlift.json.JsonCodec.jsonCodec) SchemaDaoUtil.createTablesWithRetry(com.facebook.presto.raptor.metadata.SchemaDaoUtil.createTablesWithRetry) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp) ISOChronology(org.joda.time.chrono.ISOChronology) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) Iterables(com.google.common.collect.Iterables) ColumnStats(com.facebook.presto.raptor.metadata.ColumnStats) Slice(io.airlift.slice.Slice) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) RaptorLocalFileSystem(com.facebook.presto.raptor.filesystem.RaptorLocalFileSystem) DATE(com.facebook.presto.common.type.DateType.DATE) OptionalLong(java.util.OptionalLong) SqlDate(com.facebook.presto.common.type.SqlDate) ALLOW_INSECURE(com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) DBI(org.skife.jdbi.v2.DBI) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SNAPPY(com.facebook.presto.orc.metadata.CompressionKind.SNAPPY) StorageStripeMetadataSource(com.facebook.presto.orc.StorageStripeMetadataSource) IOException(java.io.IOException) UTC_KEY(com.facebook.presto.common.type.TimeZoneKey.UTC_KEY) UTC(org.joda.time.DateTimeZone.UTC) File(java.io.File) DEFAULT_RAPTOR_CONTEXT(com.facebook.presto.raptor.filesystem.FileSystemUtil.DEFAULT_RAPTOR_CONTEXT) ShardDelta(com.facebook.presto.raptor.metadata.ShardDelta) IDBI(org.skife.jdbi.v2.IDBI) MoreFiles.deleteRecursively(com.google.common.io.MoreFiles.deleteRecursively) Duration(io.airlift.units.Duration) MaterializedResult.materializeSourceDataStream(com.facebook.presto.testing.MaterializedResult.materializeSourceDataStream) SESSION(com.facebook.presto.testing.TestingConnectorSession.SESSION) Days(org.joda.time.Days) Path(org.apache.hadoop.fs.Path) URI(java.net.URI) TIME(com.facebook.presto.common.type.TimeType.TIME) StripeMetadataSourceFactory(com.facebook.presto.orc.StripeMetadataSourceFactory) Files.createTempDir(com.google.common.io.Files.createTempDir) NodeManager(com.facebook.presto.spi.NodeManager) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) UUID(java.util.UUID) Assert.assertNotNull(org.testng.Assert.assertNotNull) TestingNodeManager(com.facebook.presto.testing.TestingNodeManager) Collectors(java.util.stream.Collectors) ENABLED_AND_VALIDATED(com.facebook.presto.raptor.storage.StorageManagerConfig.OrcOptimizedWriterStage.ENABLED_AND_VALIDATED) String.format(java.lang.String.format) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) SqlTime(com.facebook.presto.common.type.SqlTime) OrcBatchRecordReader(com.facebook.presto.orc.OrcBatchRecordReader) BackupManager(com.facebook.presto.raptor.backup.BackupManager) IntStream(java.util.stream.IntStream) FileSystemUtil.xxhash64(com.facebook.presto.raptor.filesystem.FileSystemUtil.xxhash64) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) DateTimeTestingUtils.sqlTimestampOf(com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf) BackupStore(com.facebook.presto.raptor.backup.BackupStore) PrestoException(com.facebook.presto.spi.PrestoException) OptionalInt(java.util.OptionalInt) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Hashing.md5(com.google.common.hash.Hashing.md5) Files.hash(com.google.common.io.Files.hash) RecordedShard(com.facebook.presto.raptor.storage.InMemoryShardRecorder.RecordedShard) ImmutableList(com.google.common.collect.ImmutableList) DEFAULT_HIVE_FILE_CONTEXT(com.facebook.presto.hive.HiveFileContext.DEFAULT_HIVE_FILE_CONTEXT) FileAssert.assertDirectory(org.testng.FileAssert.assertDirectory) Type(com.facebook.presto.common.type.Type) TestDatabaseShardManager.createShardManager(com.facebook.presto.raptor.metadata.TestDatabaseShardManager.createShardManager) Assert.fail(org.testng.Assert.fail) DateTime(org.joda.time.DateTime) VARBINARY(com.facebook.presto.common.type.VarbinaryType.VARBINARY) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) ShardRecorder(com.facebook.presto.raptor.metadata.ShardRecorder) TimeUnit(java.util.concurrent.TimeUnit) OrcTestingUtil.createReader(com.facebook.presto.raptor.storage.OrcTestingUtil.createReader) StorageOrcFileTailSource(com.facebook.presto.orc.cache.StorageOrcFileTailSource) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) Handle(org.skife.jdbi.v2.Handle) Assert.assertTrue(org.testng.Assert.assertTrue) LocalFileStorageService(com.facebook.presto.raptor.filesystem.LocalFileStorageService) BitSet(java.util.BitSet) Block(com.facebook.presto.common.block.Block) BYTE(io.airlift.units.DataSize.Unit.BYTE) BitSet(java.util.BitSet) 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) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) FileSystem(org.apache.hadoop.fs.FileSystem) RaptorLocalFileSystem(com.facebook.presto.raptor.filesystem.RaptorLocalFileSystem) OptionalLong(java.util.OptionalLong) LocalOrcDataEnvironment(com.facebook.presto.raptor.filesystem.LocalOrcDataEnvironment) ShardDelta(com.facebook.presto.raptor.metadata.ShardDelta) FileAssert.assertFile(org.testng.FileAssert.assertFile) File(java.io.File) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Aggregations

MoreFutures.getFutureValue (com.facebook.airlift.concurrent.MoreFutures.getFutureValue)1 JsonCodec.jsonCodec (com.facebook.airlift.json.JsonCodec.jsonCodec)1 RowPagesBuilder.rowPagesBuilder (com.facebook.presto.RowPagesBuilder.rowPagesBuilder)1 Page (com.facebook.presto.common.Page)1 Block (com.facebook.presto.common.block.Block)1 NullableValue (com.facebook.presto.common.predicate.NullableValue)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1 DATE (com.facebook.presto.common.type.DateType.DATE)1 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)1 SqlDate (com.facebook.presto.common.type.SqlDate)1 SqlTime (com.facebook.presto.common.type.SqlTime)1 SqlTimestamp (com.facebook.presto.common.type.SqlTimestamp)1 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)1 TIME (com.facebook.presto.common.type.TimeType.TIME)1 UTC_KEY (com.facebook.presto.common.type.TimeZoneKey.UTC_KEY)1 TIMESTAMP (com.facebook.presto.common.type.TimestampType.TIMESTAMP)1 Type (com.facebook.presto.common.type.Type)1 VARBINARY (com.facebook.presto.common.type.VarbinaryType.VARBINARY)1