Search in sources :

Example 1 with HdfsContext

use of com.facebook.presto.hive.HdfsContext in project presto by prestodb.

the class RaptorPageSinkProvider method createPageSink.

@Override
public ConnectorPageSink createPageSink(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorOutputTableHandle tableHandle, PageSinkContext pageSinkContext) {
    checkArgument(!pageSinkContext.isCommitRequired(), "Raptor connector does not support page sink commit");
    RaptorOutputTableHandle handle = (RaptorOutputTableHandle) tableHandle;
    return new RaptorPageSink(new HdfsContext(session, handle.getSchemaName(), handle.getTableName()), pageSorter, storageManager, temporalFunction, handle.getTransactionId(), toColumnIds(handle.getColumnHandles()), handle.getColumnTypes(), toColumnIds(handle.getSortColumnHandles()), handle.getSortOrders(), handle.getBucketCount(), toColumnIds(handle.getBucketColumnHandles()), handle.getTemporalColumnHandle(), getWriterMaxBufferSize(session), maxAllowedFilesPerWriter);
}
Also used : HdfsContext(com.facebook.presto.hive.HdfsContext)

Example 2 with HdfsContext

use of com.facebook.presto.hive.HdfsContext in project presto by prestodb.

the class RaptorPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns, SplitContext splitContext) {
    RaptorSplit raptorSplit = (RaptorSplit) split;
    OptionalInt bucketNumber = raptorSplit.getBucketNumber();
    TupleDomain<RaptorColumnHandle> predicate = raptorSplit.getEffectivePredicate();
    ReaderAttributes attributes = ReaderAttributes.from(session);
    OptionalLong transactionId = raptorSplit.getTransactionId();
    Optional<Map<String, Type>> columnTypes = raptorSplit.getColumnTypes();
    boolean tableSupportsDeltaDelete = raptorSplit.isTableSupportsDeltaDelete();
    HdfsContext context = new HdfsContext(session);
    Map<UUID, UUID> shardDeltaMap = raptorSplit.getShardDeltaMap();
    if (raptorSplit.getShardUuids().size() == 1) {
        UUID shardUuid = raptorSplit.getShardUuids().iterator().next();
        return createPageSource(context, DEFAULT_HIVE_FILE_CONTEXT, shardUuid, Optional.ofNullable(shardDeltaMap.get(shardUuid)), tableSupportsDeltaDelete, bucketNumber, columns, predicate, attributes, transactionId, columnTypes);
    }
    Iterator<ConnectorPageSource> iterator = raptorSplit.getShardUuids().stream().map(shardUuid -> createPageSource(context, DEFAULT_HIVE_FILE_CONTEXT, shardUuid, Optional.ofNullable(shardDeltaMap.get(shardUuid)), tableSupportsDeltaDelete, bucketNumber, columns, predicate, attributes, transactionId, columnTypes)).iterator();
    return new ConcatPageSource(iterator);
}
Also used : OptionalInt(java.util.OptionalInt) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Inject(javax.inject.Inject) OptionalLong(java.util.OptionalLong) SplitContext(com.facebook.presto.spi.SplitContext) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ReaderAttributes(com.facebook.presto.raptor.storage.ReaderAttributes) DEFAULT_HIVE_FILE_CONTEXT(com.facebook.presto.hive.HiveFileContext.DEFAULT_HIVE_FILE_CONTEXT) StorageManager(com.facebook.presto.raptor.storage.StorageManager) HdfsContext(com.facebook.presto.hive.HdfsContext) ConnectorPageSourceProvider(com.facebook.presto.spi.connector.ConnectorPageSourceProvider) Type(com.facebook.presto.common.type.Type) ConcatPageSource(com.facebook.presto.raptor.util.ConcatPageSource) Iterator(java.util.Iterator) HiveFileContext(com.facebook.presto.hive.HiveFileContext) UUID(java.util.UUID) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Optional(java.util.Optional) ConcatPageSource(com.facebook.presto.raptor.util.ConcatPageSource) OptionalInt(java.util.OptionalInt) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) ReaderAttributes(com.facebook.presto.raptor.storage.ReaderAttributes) OptionalLong(java.util.OptionalLong) HdfsContext(com.facebook.presto.hive.HdfsContext) UUID(java.util.UUID) Map(java.util.Map)

Example 3 with HdfsContext

use of com.facebook.presto.hive.HdfsContext in project presto by prestodb.

the class SemiTransactionalHiveMetastore method addPartition.

public synchronized void addPartition(ConnectorSession session, String databaseName, String tableName, String tablePath, boolean isNewTable, Partition partition, Path currentLocation, PartitionStatistics statistics) {
    setShared();
    checkArgument(getPrestoQueryId(partition).isPresent());
    Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(new SchemaTableName(databaseName, tableName), k -> new HashMap<>());
    Action<PartitionAndMore> oldPartitionAction = partitionActionsOfTable.get(partition.getValues());
    HdfsContext context = new HdfsContext(session, databaseName, tableName, tablePath, isNewTable);
    if (oldPartitionAction == null) {
        partitionActionsOfTable.put(partition.getValues(), new Action<>(ActionType.ADD, new PartitionAndMore(partition, currentLocation, Optional.empty(), statistics, statistics), context));
        return;
    }
    switch(oldPartitionAction.getType()) {
        case DROP:
            {
                if (!oldPartitionAction.getContext().getIdentity().getUser().equals(session.getUser())) {
                    throw new PrestoException(TRANSACTION_CONFLICT, "Operation on the same partition with different user in the same transaction is not supported");
                }
                partitionActionsOfTable.put(partition.getValues(), new Action<>(ActionType.ALTER, new PartitionAndMore(partition, currentLocation, Optional.empty(), statistics, statistics), context));
                break;
            }
        case ADD:
        case ALTER:
        case INSERT_EXISTING:
            throw new PrestoException(ALREADY_EXISTS, format("Partition already exists for table '%s.%s': %s", databaseName, tableName, partition.getValues()));
        default:
            throw new IllegalStateException("Unknown action type");
    }
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) PrestoException(com.facebook.presto.spi.PrestoException) HdfsContext(com.facebook.presto.hive.HdfsContext) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 4 with HdfsContext

use of com.facebook.presto.hive.HdfsContext in project presto by prestodb.

the class SemiTransactionalHiveMetastore method commitShared.

@GuardedBy("this")
private void commitShared() {
    checkHoldsLock();
    Committer committer = new Committer();
    try {
        for (Map.Entry<SchemaTableName, Action<TableAndMore>> entry : tableActions.entrySet()) {
            SchemaTableName schemaTableName = entry.getKey();
            Action<TableAndMore> action = entry.getValue();
            HdfsContext hdfsContext = action.getContext();
            MetastoreContext metastoreContext = new MetastoreContext(hdfsContext.getIdentity(), hdfsContext.getQueryId().orElse(""), hdfsContext.getClientInfo(), hdfsContext.getSource(), hdfsContext.getSession().flatMap(MetastoreUtil::getMetastoreHeaders), hdfsContext.getSession().map(MetastoreUtil::isUserDefinedTypeEncodingEnabled).orElse(false), columnConverterProvider);
            switch(action.getType()) {
                case DROP:
                    committer.prepareDropTable(metastoreContext, schemaTableName);
                    break;
                case ALTER:
                    committer.prepareAlterTable();
                    break;
                case ADD:
                    committer.prepareAddTable(metastoreContext, hdfsContext, action.getData());
                    break;
                case INSERT_EXISTING:
                    committer.prepareInsertExistingTable(metastoreContext, hdfsContext, action.getData());
                    break;
                default:
                    throw new IllegalStateException("Unknown action type");
            }
        }
        for (Map.Entry<SchemaTableName, Map<List<String>, Action<PartitionAndMore>>> tableEntry : partitionActions.entrySet()) {
            SchemaTableName schemaTableName = tableEntry.getKey();
            for (Map.Entry<List<String>, Action<PartitionAndMore>> partitionEntry : tableEntry.getValue().entrySet()) {
                List<String> partitionValues = partitionEntry.getKey();
                Action<PartitionAndMore> action = partitionEntry.getValue();
                HdfsContext hdfsContext = action.getContext();
                MetastoreContext metastoreContext = new MetastoreContext(hdfsContext.getIdentity(), hdfsContext.getQueryId().orElse(""), hdfsContext.getClientInfo(), hdfsContext.getSource(), hdfsContext.getSession().flatMap(MetastoreUtil::getMetastoreHeaders), hdfsContext.getSession().map(MetastoreUtil::isUserDefinedTypeEncodingEnabled).orElse(false), columnConverterProvider);
                switch(action.getType()) {
                    case DROP:
                        committer.prepareDropPartition(metastoreContext, schemaTableName, partitionValues);
                        break;
                    case ALTER:
                        committer.prepareAlterPartition(metastoreContext, hdfsContext, action.getData());
                        break;
                    case ADD:
                        committer.prepareAddPartition(metastoreContext, hdfsContext, action.getData());
                        break;
                    case INSERT_EXISTING:
                        committer.prepareInsertExistingPartition(metastoreContext, hdfsContext, action.getData());
                        break;
                    default:
                        throw new IllegalStateException("Unknown action type");
                }
            }
        }
        // Wait for all renames submitted for "INSERT_EXISTING" action to finish
        ListenableFuture<?> listenableFutureAggregate = whenAllSucceed(committer.getFileRenameFutures()).call(() -> null, directExecutor());
        try {
            getFutureValue(listenableFutureAggregate, PrestoException.class);
        } catch (RuntimeException e) {
            listenableFutureAggregate.cancel(true);
            throw e;
        }
        // At this point, all file system operations, whether asynchronously issued or not, have completed successfully.
        // We are moving on to metastore operations now.
        committer.executeAddTableOperations();
        committer.executeAlterPartitionOperations();
        committer.executeAddPartitionOperations();
        committer.executeUpdateStatisticsOperations();
    } catch (Throwable t) {
        committer.cancelUnstartedAsyncRenames();
        committer.undoUpdateStatisticsOperations();
        committer.undoAddPartitionOperations();
        committer.undoAddTableOperations();
        committer.waitForAsyncRenamesSuppressThrowables();
        // fileRenameFutures must all come back before any file system cleanups are carried out.
        // Otherwise, files that should be deleted may be created after cleanup is done.
        committer.executeCleanupTasksForAbort(declaredIntentionsToWrite);
        committer.executeRenameTasksForAbort();
        // Partition directory must be put back before relevant metastore operation can be undone
        committer.undoAlterPartitionOperations();
        rollbackShared();
        throw t;
    }
    try {
        if (!committer.metastoreDeleteOperations.isEmpty()) {
            committer.executeMetastoreDeleteOperations();
        }
    // If control flow reached this point, this commit is considered successful no matter
    // what happens later. The only kind of operations that haven't been carried out yet
    // are cleanups.
    // The program control flow will go to finally next. And cleanup will run because
    // moveForwardInFinally has been set to false.
    } finally {
        // In this method, all operations are best-effort clean up operations.
        // If any operation fails, the error will be logged and ignored.
        // Additionally, other clean up operations should still be attempted.
        // Execute deletion tasks
        committer.executeDeletionTasksForFinish();
        // Clean up temporary tables
        deleteTemporaryTableDirectories(declaredIntentionsToWrite, hdfsEnvironment);
        // Clean up empty staging directories (that may recursively contain empty directories)
        committer.deleteEmptyStagingDirectories(declaredIntentionsToWrite);
        // Clean up root temp directories
        deleteTempPathRootDirectory(declaredIntentionsToWrite, hdfsEnvironment);
    }
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) HdfsContext(com.facebook.presto.hive.HdfsContext) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 5 with HdfsContext

use of com.facebook.presto.hive.HdfsContext in project presto by prestodb.

the class IcebergPageSinkProvider method createPageSink.

private ConnectorPageSink createPageSink(ConnectorSession session, IcebergWritableTableHandle tableHandle) {
    HdfsContext hdfsContext = new HdfsContext(session, tableHandle.getSchemaName(), tableHandle.getTableName());
    Schema schema = SchemaParser.fromJson(tableHandle.getSchemaAsJson());
    PartitionSpec partitionSpec = PartitionSpecParser.fromJson(schema, tableHandle.getPartitionSpecAsJson());
    LocationProvider locationProvider = getLocationProvider(new SchemaTableName(tableHandle.getSchemaName(), tableHandle.getTableName()), tableHandle.getOutputPath(), tableHandle.getStorageProperties());
    return new IcebergPageSink(schema, partitionSpec, locationProvider, fileWriterFactory, pageIndexerFactory, hdfsEnvironment, hdfsContext, tableHandle.getInputColumns(), jsonCodec, session, tableHandle.getFileFormat());
}
Also used : IcebergUtil.getLocationProvider(com.facebook.presto.iceberg.IcebergUtil.getLocationProvider) LocationProvider(org.apache.iceberg.io.LocationProvider) Schema(org.apache.iceberg.Schema) HdfsContext(com.facebook.presto.hive.HdfsContext) PartitionSpec(org.apache.iceberg.PartitionSpec) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Aggregations

HdfsContext (com.facebook.presto.hive.HdfsContext)19 PrestoException (com.facebook.presto.spi.PrestoException)12 SchemaTableName (com.facebook.presto.spi.SchemaTableName)10 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 ArrayList (java.util.ArrayList)7 Path (org.apache.hadoop.fs.Path)7 Collectors.toList (java.util.stream.Collectors.toList)6 Type (com.facebook.presto.common.type.Type)5 ConnectorSession (com.facebook.presto.spi.ConnectorSession)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 IOException (java.io.IOException)5 Map (java.util.Map)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Optional (java.util.Optional)5 HdfsEnvironment (com.facebook.presto.hive.HdfsEnvironment)4 Inject (javax.inject.Inject)4 FileFormat (org.apache.iceberg.FileFormat)4 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)3