use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class NativeCassandraSession method getKeyspaceByCaseInsensitiveName0.
private KeyspaceMetadata getKeyspaceByCaseInsensitiveName0(String caseInsensitiveSchemaName) throws SchemaNotFoundException {
List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces());
KeyspaceMetadata result = null;
// Ensure that the error message is deterministic
List<KeyspaceMetadata> sortedKeyspaces = Ordering.from(comparing(KeyspaceMetadata::getName)).immutableSortedCopy(keyspaces);
for (KeyspaceMetadata keyspace : sortedKeyspaces) {
if (keyspace.getName().equalsIgnoreCase(caseInsensitiveSchemaName)) {
if (result != null) {
throw new PrestoException(NOT_SUPPORTED, format("More than one keyspace has been found for the case insensitive schema name: %s -> (%s, %s)", caseInsensitiveSchemaName, result.getName(), keyspace.getName()));
}
result = keyspace;
}
}
if (result == null) {
throw new SchemaNotFoundException(caseInsensitiveSchemaName);
}
return result;
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class GlueHiveMetastore method renameDatabase.
@Override
public void renameDatabase(MetastoreContext metastoreContext, String databaseName, String newDatabaseName) {
try {
Database database = getDatabase(metastoreContext, databaseName).orElseThrow(() -> new SchemaNotFoundException(databaseName));
DatabaseInput renamedDatabase = GlueInputConverter.convertDatabase(database).withName(newDatabaseName);
stats.getUpdateDatabase().record(() -> glueClient.updateDatabase(new UpdateDatabaseRequest().withCatalogId(catalogId).withName(databaseName).withDatabaseInput(renamedDatabase)));
} catch (AmazonServiceException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class BridgingHiveMetastore method renameDatabase.
@Override
public void renameDatabase(MetastoreContext metastoreContext, String databaseName, String newDatabaseName) {
org.apache.hadoop.hive.metastore.api.Database database = delegate.getDatabase(metastoreContext, databaseName).orElseThrow(() -> new SchemaNotFoundException(databaseName));
database.setName(newDatabaseName);
delegate.alterDatabase(metastoreContext, databaseName, database);
delegate.getDatabase(metastoreContext, databaseName).ifPresent(newDatabase -> {
if (newDatabase.getName().equals(databaseName)) {
throw new PrestoException(NOT_SUPPORTED, "Hive metastore does not support renaming schemas");
}
});
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class IcebergHiveMetadata method beginCreateTable.
@Override
public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) {
SchemaTableName schemaTableName = tableMetadata.getTable();
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
Schema schema = toIcebergSchema(tableMetadata.getColumns());
PartitionSpec partitionSpec = parsePartitionFields(schema, getPartitioning(tableMetadata.getProperties()));
MetastoreContext metastoreContext = new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER);
Database database = metastore.getDatabase(metastoreContext, schemaName).orElseThrow(() -> new SchemaNotFoundException(schemaName));
HdfsContext hdfsContext = new HdfsContext(session, schemaName, tableName);
String targetPath = getTableLocation(tableMetadata.getProperties());
if (targetPath == null) {
Optional<String> location = database.getLocation();
if (!location.isPresent() || location.get().isEmpty()) {
throw new PrestoException(NOT_SUPPORTED, "Database " + schemaName + " location is not set");
}
Path databasePath = new Path(location.get());
Path resultPath = new Path(databasePath, tableName);
targetPath = resultPath.toString();
}
TableOperations operations = new HiveTableOperations(metastore, new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER), hdfsEnvironment, hdfsContext, schemaName, tableName, session.getUser(), targetPath);
if (operations.current() != null) {
throw new TableAlreadyExistsException(schemaTableName);
}
ImmutableMap.Builder<String, String> propertiesBuilder = ImmutableMap.builderWithExpectedSize(2);
FileFormat fileFormat = getFileFormat(tableMetadata.getProperties());
propertiesBuilder.put(DEFAULT_FILE_FORMAT, fileFormat.toString());
if (tableMetadata.getComment().isPresent()) {
propertiesBuilder.put(TABLE_COMMENT, tableMetadata.getComment().get());
}
TableMetadata metadata = newTableMetadata(schema, partitionSpec, targetPath, propertiesBuilder.build());
transaction = createTableTransaction(tableName, operations, metadata);
return new IcebergWritableTableHandle(schemaName, tableName, SchemaParser.toJson(metadata.schema()), PartitionSpecParser.toJson(metadata.spec()), getColumns(metadata.schema(), typeManager), targetPath, fileFormat, metadata.properties());
}
use of com.facebook.presto.spi.SchemaNotFoundException in project presto by prestodb.
the class KuduClientSession method openTable.
public KuduTable openTable(SchemaTableName schemaTableName) {
reTryKerberos(kerberosAuthEnabled);
String rawName = schemaEmulation.toRawName(schemaTableName);
try {
return client.openTable(rawName);
} catch (KuduException e) {
log.debug("Error on doOpenTable: " + e, e);
if (!listSchemaNames().contains(schemaTableName.getSchemaName())) {
throw new SchemaNotFoundException(schemaTableName.getSchemaName());
}
throw new TableNotFoundException(schemaTableName);
}
}
Aggregations