use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method createTable.
@Override
public void createTable(MetastoreContext metastoreContext, Table table, PrincipalPrivileges principalPrivileges) {
try {
TableInput input = GlueInputConverter.convertTable(table);
stats.getCreateTable().record(() -> glueClient.createTable(new CreateTableRequest().withCatalogId(catalogId).withDatabaseName(table.getDatabaseName()).withTableInput(input)));
} catch (AlreadyExistsException e) {
throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()));
} catch (EntityNotFoundException e) {
throw new SchemaNotFoundException(table.getDatabaseName());
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class InMemoryHiveMetastore method alterDatabase.
@Override
public synchronized void alterDatabase(MetastoreContext metastoreContext, String databaseName, Database newDatabase) {
String newDatabaseName = newDatabase.getName();
if (databaseName.equals(newDatabaseName)) {
if (databases.replace(databaseName, newDatabase) == null) {
throw new SchemaNotFoundException(databaseName);
}
return;
}
Database database = databases.get(databaseName);
if (database == null) {
throw new SchemaNotFoundException(databaseName);
}
if (databases.putIfAbsent(newDatabaseName, database) != null) {
throw new SchemaAlreadyExistsException(newDatabaseName);
}
databases.remove(databaseName);
rewriteKeys(relations, name -> new SchemaTableName(newDatabaseName, name.getTableName()));
rewriteKeys(views, name -> new SchemaTableName(newDatabaseName, name.getTableName()));
rewriteKeys(partitions, name -> name.withSchemaName(newDatabaseName));
rewriteKeys(tablePrivileges, name -> name.withDatabase(newDatabaseName));
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class KuduClientSession method createTable.
public KuduTable createTable(ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
reTryKerberos(kerberosAuthEnabled);
try {
String rawName = schemaEmulation.toRawName(tableMetadata.getTable());
if (ignoreExisting) {
if (client.tableExists(rawName)) {
return null;
}
}
if (!schemaEmulation.existsSchema(client, tableMetadata.getTable().getSchemaName())) {
throw new SchemaNotFoundException(tableMetadata.getTable().getSchemaName());
}
List<ColumnMetadata> columns = tableMetadata.getColumns();
Map<String, Object> properties = tableMetadata.getProperties();
Schema schema = buildSchema(columns, properties);
CreateTableOptions options = buildCreateTableOptions(schema, properties);
return client.createTable(rawName, schema, options);
} catch (KuduException e) {
throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
}
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class InMemoryHiveMetastore method alterDatabase.
@Override
public synchronized void alterDatabase(String databaseName, Database newDatabase) {
String newDatabaseName = newDatabase.getName();
if (databaseName.equals(newDatabaseName)) {
if (databases.replace(databaseName, newDatabase) == null) {
throw new SchemaNotFoundException(databaseName);
}
return;
}
Database database = databases.get(databaseName);
if (database == null) {
throw new SchemaNotFoundException(databaseName);
}
if (databases.putIfAbsent(newDatabaseName, database) != null) {
throw new SchemaAlreadyExistsException(newDatabaseName);
}
databases.remove(databaseName);
rewriteKeys(relations, name -> new SchemaTableName(newDatabaseName, name.getTableName()));
rewriteKeys(views, name -> new SchemaTableName(newDatabaseName, name.getTableName()));
rewriteKeys(partitions, name -> name.withSchemaName(newDatabaseName));
rewriteKeys(tablePrivileges, name -> name.withDatabase(newDatabaseName));
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class BridgingHiveMetastore method renameDatabase.
@Override
public void renameDatabase(String databaseName, String newDatabaseName) {
org.apache.hadoop.hive.metastore.api.Database database = delegate.getDatabase(databaseName).orElseThrow(() -> new SchemaNotFoundException(databaseName));
database.setName(newDatabaseName);
delegate.alterDatabase(databaseName, database);
delegate.getDatabase(databaseName).ifPresent(newDatabase -> {
if (newDatabase.getName().equals(databaseName)) {
throw new PrestoException(NOT_SUPPORTED, "Hive metastore does not support renaming schemas");
}
});
}
Aggregations