use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class FileHiveMetastore method alterTable.
private void alterTable(String databaseName, String tableName, Function<TableMetadata, TableMetadata> alterFunction) {
requireNonNull(databaseName, "databaseName is null");
requireNonNull(tableName, "tableName is null");
Path tableMetadataDirectory = getTableMetadataDirectory(databaseName, tableName);
TableMetadata oldTableSchema = readSchemaFile("table", tableMetadataDirectory, tableCodec).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
TableMetadata newTableSchema = alterFunction.apply(oldTableSchema);
if (oldTableSchema == newTableSchema) {
return;
}
writeSchemaFile("table", tableMetadataDirectory, tableCodec, newTableSchema, true);
}
use of com.facebook.presto.spi.SchemaTableName 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();
switch(action.getType()) {
case DROP:
committer.prepareDropTable(schemaTableName);
break;
case ALTER:
committer.prepareAlterTable();
break;
case ADD:
committer.prepareAddTable(action.getUser(), action.getData());
break;
case INSERT_EXISTING:
committer.prepareInsertExistingTable(action.getUser(), 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();
switch(action.getType()) {
case DROP:
committer.prepareDropPartition(schemaTableName, partitionValues);
break;
case ALTER:
committer.prepareAlterPartition(action.getQueryId(), action.getUser(), action.getData());
break;
case ADD:
committer.prepareAddPartition(action.getUser(), action.getData());
break;
case INSERT_EXISTING:
committer.prepareInsertExistingPartition(action.getUser(), action.getData());
break;
default:
throw new IllegalStateException("Unknown action type");
}
}
}
// Wait for all renames submitted for "INSERT_EXISTING" action to finish
committer.waitForAsyncRenames();
// 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();
} catch (Throwable t) {
committer.cancelUnstartedAsyncRenames();
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(committer.extractFilePrefixes(declaredIntentionsToWrite));
committer.executeRenameTasksForAbort();
// Partition directory must be put back before relevant metastore operation can be undone
committer.undoAlterPartitionOperations();
rollbackShared();
throw t;
}
try {
// After this line, operations are no longer reversible.
// The next section will deal with "dropping table/partition". Commit may still fail in
// this section. Even if commit fails, cleanups, instead of rollbacks, will be executed.
committer.executeIrreversibleMetastoreOperations();
// 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 empty staging directories (that may recursively contain empty directories)
committer.deleteEmptyStagingDirectories(declaredIntentionsToWrite);
}
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class SemiTransactionalHiveMetastore method getTableSource.
/**
* This method can only be called when the table is known to exist
*/
@GuardedBy("this")
private TableSource getTableSource(String databaseName, String tableName) {
checkHoldsLock();
checkReadable();
Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
if (tableAction == null) {
return TableSource.PRE_EXISTING_TABLE;
}
switch(tableAction.getType()) {
case ADD:
return TableSource.CREATED_IN_THIS_TRANSACTION;
case ALTER:
throw new IllegalStateException("Tables are never altered in the current implementation");
case DROP:
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
case INSERT_EXISTING:
return TableSource.PRE_EXISTING_TABLE;
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class SemiTransactionalHiveMetastore method getTable.
public synchronized Optional<Table> getTable(String databaseName, String tableName) {
checkReadable();
Action<TableAndMore> tableAction = tableActions.get(new SchemaTableName(databaseName, tableName));
if (tableAction == null) {
return delegate.getTable(databaseName, tableName);
}
switch(tableAction.getType()) {
case ADD:
case ALTER:
case INSERT_EXISTING:
return Optional.of(tableAction.getData().getTable());
case DROP:
return Optional.empty();
default:
throw new IllegalStateException("Unknown action type");
}
}
use of com.facebook.presto.spi.SchemaTableName in project presto by prestodb.
the class SemiTransactionalHiveMetastore method getPartition.
public synchronized Optional<Partition> getPartition(String databaseName, String tableName, List<String> partitionValues) {
checkReadable();
TableSource tableSource = getTableSource(databaseName, tableName);
Map<List<String>, Action<PartitionAndMore>> partitionActionsOfTable = partitionActions.computeIfAbsent(new SchemaTableName(databaseName, tableName), k -> new HashMap<>());
Action<PartitionAndMore> partitionAction = partitionActionsOfTable.get(partitionValues);
if (partitionAction != null) {
return getPartitionFromPartitionAction(partitionAction);
}
switch(tableSource) {
case PRE_EXISTING_TABLE:
return delegate.getPartition(databaseName, tableName, partitionValues);
case CREATED_IN_THIS_TRANSACTION:
return Optional.empty();
default:
throw new UnsupportedOperationException("unknown table source");
}
}
Aggregations