Search in sources :

Example 6 with FileWriteInfo

use of com.facebook.presto.hive.PartitionUpdate.FileWriteInfo in project presto by prestodb.

the class TestPartitionUpdate method testRoundTrip.

@Test
public void testRoundTrip() {
    PartitionUpdate expected = new PartitionUpdate("test", UpdateMode.APPEND, "/writePath", "/targetPath", ImmutableList.of(new PartitionUpdate.FileWriteInfo(".file1", "file1", Optional.empty()), new FileWriteInfo(".file3", "file3", Optional.empty())), 123, 456, 789, false);
    PartitionUpdate actual = CODEC.fromJson(CODEC.toJson(expected));
    assertEquals(actual.getName(), "test");
    assertEquals(actual.getUpdateMode(), UpdateMode.APPEND);
    assertEquals(actual.getWritePath(), new Path("/writePath"));
    assertEquals(actual.getTargetPath(), new Path("/targetPath"));
    assertEquals(actual.getFileWriteInfos(), ImmutableList.of(new FileWriteInfo(".file1", "file1", Optional.empty()), new FileWriteInfo(".file3", "file3", Optional.empty())));
    assertEquals(actual.getRowCount(), 123);
    assertEquals(actual.getInMemoryDataSizeInBytes(), 456);
    assertEquals(actual.getOnDiskDataSizeInBytes(), 789);
}
Also used : Path(org.apache.hadoop.fs.Path) FileWriteInfo(com.facebook.presto.hive.PartitionUpdate.FileWriteInfo) Test(org.testng.annotations.Test)

Example 7 with FileWriteInfo

use of com.facebook.presto.hive.PartitionUpdate.FileWriteInfo in project presto by prestodb.

the class HiveStagingFileCommitter method commitFiles.

@Override
public ListenableFuture<Void> commitFiles(ConnectorSession session, String schemaName, String tableName, String tablePath, boolean isCreateTable, List<PartitionUpdate> partitionUpdates) {
    HdfsContext context = new HdfsContext(session, schemaName, tableName, tablePath, isCreateTable);
    List<ListenableFuture<Void>> commitFutures = new ArrayList<>();
    for (PartitionUpdate partitionUpdate : partitionUpdates) {
        Path path = partitionUpdate.getWritePath();
        FileSystem fileSystem = getFileSystem(hdfsEnvironment, context, path);
        for (FileWriteInfo fileWriteInfo : partitionUpdate.getFileWriteInfos()) {
            checkState(!fileWriteInfo.getWriteFileName().equals(fileWriteInfo.getTargetFileName()));
            Path source = new Path(path, fileWriteInfo.getWriteFileName());
            Path target = new Path(path, fileWriteInfo.getTargetFileName());
            commitFutures.add(fileRenameExecutor.submit(() -> {
                renameFile(fileSystem, source, target);
                return null;
            }));
        }
    }
    ListenableFuture<Void> result = whenAllSucceed(commitFutures).call(() -> null, directExecutor());
    return catching(result, RuntimeException.class, e -> {
        checkState(e != null, "Null exception is caught during commitFiles");
        result.cancel(true);
        throw e;
    }, directExecutor());
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) MetastoreUtil.getFileSystem(com.facebook.presto.hive.metastore.MetastoreUtil.getFileSystem) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FileWriteInfo(com.facebook.presto.hive.PartitionUpdate.FileWriteInfo)

Aggregations

FileWriteInfo (com.facebook.presto.hive.PartitionUpdate.FileWriteInfo)7 Path (org.apache.hadoop.fs.Path)5 ArrayList (java.util.ArrayList)2 MoreFutures.toCompletableFuture (com.facebook.airlift.concurrent.MoreFutures.toCompletableFuture)1 JsonCodec (com.facebook.airlift.json.JsonCodec)1 JsonCodec.jsonCodec (com.facebook.airlift.json.JsonCodec.jsonCodec)1 SmileCodec (com.facebook.airlift.json.smile.SmileCodec)1 PageBuilder (com.facebook.presto.common.PageBuilder)1 Subfield (com.facebook.presto.common.Subfield)1 Block (com.facebook.presto.common.block.Block)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 Domain (com.facebook.presto.common.predicate.Domain)1 NullableValue (com.facebook.presto.common.predicate.NullableValue)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 TupleDomain.withColumnDomains (com.facebook.presto.common.predicate.TupleDomain.withColumnDomains)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1 Chars.isCharType (com.facebook.presto.common.type.Chars.isCharType)1 DATE (com.facebook.presto.common.type.DateType.DATE)1