Search in sources :

Example 1 with SchemaNotFoundException

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);
    }
}
Also used : TableInput(com.amazonaws.services.glue.model.TableInput) GlueInputConverter.toTableInput(com.facebook.presto.hive.metastore.glue.converter.GlueInputConverter.toTableInput) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) AlreadyExistsException(com.amazonaws.services.glue.model.AlreadyExistsException) AmazonServiceException(com.amazonaws.AmazonServiceException) PrestoException(com.facebook.presto.spi.PrestoException) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) CreateTableRequest(com.amazonaws.services.glue.model.CreateTableRequest) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 2 with SchemaNotFoundException

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));
}
Also used : SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) Database(org.apache.hadoop.hive.metastore.api.Database) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 3 with SchemaNotFoundException

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);
    }
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Schema(org.apache.kudu.Schema) ColumnSchema(org.apache.kudu.ColumnSchema) PrestoException(com.facebook.presto.spi.PrestoException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) CreateTableOptions(org.apache.kudu.client.CreateTableOptions) KuduException(org.apache.kudu.client.KuduException)

Example 4 with SchemaNotFoundException

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));
}
Also used : SchemaAlreadyExistsException(com.facebook.presto.hive.SchemaAlreadyExistsException) Database(org.apache.hadoop.hive.metastore.api.Database) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 5 with SchemaNotFoundException

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");
        }
    });
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException)

Aggregations

SchemaNotFoundException (com.facebook.presto.spi.SchemaNotFoundException)10 PrestoException (com.facebook.presto.spi.PrestoException)7 SchemaTableName (com.facebook.presto.spi.SchemaTableName)4 SchemaAlreadyExistsException (com.facebook.presto.hive.SchemaAlreadyExistsException)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)2 Database (com.facebook.presto.hive.metastore.Database)2 Database (org.apache.hadoop.hive.metastore.api.Database)2 KuduException (org.apache.kudu.client.KuduException)2 AlreadyExistsException (com.amazonaws.services.glue.model.AlreadyExistsException)1 CreateTableRequest (com.amazonaws.services.glue.model.CreateTableRequest)1 DatabaseInput (com.amazonaws.services.glue.model.DatabaseInput)1 EntityNotFoundException (com.amazonaws.services.glue.model.EntityNotFoundException)1 TableInput (com.amazonaws.services.glue.model.TableInput)1 UpdateDatabaseRequest (com.amazonaws.services.glue.model.UpdateDatabaseRequest)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 HdfsContext (com.facebook.presto.hive.HdfsContext)1 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)1 GlueInputConverter.toTableInput (com.facebook.presto.hive.metastore.glue.converter.GlueInputConverter.toTableInput)1 IcebergTableProperties.getFileFormat (com.facebook.presto.iceberg.IcebergTableProperties.getFileFormat)1