Search in sources :

Example 6 with SchemaNotFoundException

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

Example 7 with SchemaNotFoundException

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);
    }
}
Also used : UpdateDatabaseRequest(com.amazonaws.services.glue.model.UpdateDatabaseRequest) Database(com.facebook.presto.hive.metastore.Database) AmazonServiceException(com.amazonaws.AmazonServiceException) DatabaseInput(com.amazonaws.services.glue.model.DatabaseInput) PrestoException(com.facebook.presto.spi.PrestoException) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException)

Example 8 with SchemaNotFoundException

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

Example 9 with SchemaNotFoundException

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());
}
Also used : Path(org.apache.hadoop.fs.Path) TableMetadata(org.apache.iceberg.TableMetadata) TableMetadata.newTableMetadata(org.apache.iceberg.TableMetadata.newTableMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) Schema(org.apache.iceberg.Schema) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) PrestoException(com.facebook.presto.spi.PrestoException) FileFormat(org.apache.iceberg.FileFormat) IcebergTableProperties.getFileFormat(com.facebook.presto.iceberg.IcebergTableProperties.getFileFormat) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PartitionSpec(org.apache.iceberg.PartitionSpec) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TableOperations(org.apache.iceberg.TableOperations) Database(com.facebook.presto.hive.metastore.Database) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) HdfsContext(com.facebook.presto.hive.HdfsContext)

Example 10 with SchemaNotFoundException

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

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