Search in sources :

Example 1 with NoSuchNamespaceException

use of org.apache.iceberg.exceptions.NoSuchNamespaceException in project hive by apache.

the class HiveCatalog method loadNamespaceMetadata.

@Override
public Map<String, String> loadNamespaceMetadata(Namespace namespace) {
    if (!isValidateNamespace(namespace)) {
        throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
    }
    try {
        Database database = clients.run(client -> client.getDatabase(namespace.level(0)));
        Map<String, String> metadata = convertToMetadata(database);
        LOG.debug("Loaded metadata for namespace {} found {}", namespace, metadata.keySet());
        return metadata;
    } catch (NoSuchObjectException | UnknownDBException e) {
        throw new NoSuchNamespaceException(e, "Namespace does not exist: %s", namespace);
    } catch (TException e) {
        throw new RuntimeException("Failed to list namespace under namespace: " + namespace + " in Hive Matastore", e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException("Interrupted in call to getDatabase(name) " + namespace + " in Hive Matastore", e);
    }
}
Also used : TException(org.apache.thrift.TException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) NoSuchNamespaceException(org.apache.iceberg.exceptions.NoSuchNamespaceException) Database(org.apache.hadoop.hive.metastore.api.Database) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 2 with NoSuchNamespaceException

use of org.apache.iceberg.exceptions.NoSuchNamespaceException in project hive by apache.

the class HiveCatalog method convertToDatabase.

Database convertToDatabase(Namespace namespace, Map<String, String> meta) {
    if (!isValidateNamespace(namespace)) {
        throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
    }
    Database database = new Database();
    Map<String, String> parameter = Maps.newHashMap();
    database.setName(namespace.level(0));
    database.setLocationUri(new Path(getExternalWarehouseLocation(), namespace.level(0)).toString() + ".db");
    database.setManagedLocationUri(new Path(getWarehouseLocation(), namespace.level(0)).toString() + ".db");
    meta.forEach((key, value) -> {
        if (key.equals("comment")) {
            database.setDescription(value);
        } else if (key.equals("location")) {
            database.setLocationUri(value);
        } else {
            if (value != null) {
                parameter.put(key, value);
            }
        }
    });
    database.setParameters(parameter);
    return database;
}
Also used : Path(org.apache.hadoop.fs.Path) NoSuchNamespaceException(org.apache.iceberg.exceptions.NoSuchNamespaceException) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 3 with NoSuchNamespaceException

use of org.apache.iceberg.exceptions.NoSuchNamespaceException in project hive by apache.

the class HiveCatalog method listTables.

@Override
public List<TableIdentifier> listTables(Namespace namespace) {
    Preconditions.checkArgument(isValidateNamespace(namespace), "Missing database in namespace: %s", namespace);
    String database = namespace.level(0);
    try {
        List<String> tableNames = clients.run(client -> client.getAllTables(database));
        List<Table> tableObjects = clients.run(client -> client.getTableObjectsByName(database, tableNames));
        List<TableIdentifier> tableIdentifiers = tableObjects.stream().filter(table -> table.getParameters() == null ? false : BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE.equalsIgnoreCase(table.getParameters().get(BaseMetastoreTableOperations.TABLE_TYPE_PROP))).map(table -> TableIdentifier.of(namespace, table.getTableName())).collect(Collectors.toList());
        LOG.debug("Listing of namespace: {} resulted in the following tables: {}", namespace, tableIdentifiers);
        return tableIdentifiers;
    } catch (UnknownDBException e) {
        throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
    } catch (TException e) {
        throw new RuntimeException("Failed to list all tables under namespace " + namespace, e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException("Interrupted in call to listTables", e);
    }
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) CatalogUtil(org.apache.iceberg.CatalogUtil) ImmutableMap(org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap) LoggerFactory(org.slf4j.LoggerFactory) HadoopFileIO(org.apache.iceberg.hadoop.HadoopFileIO) TableMetadata(org.apache.iceberg.TableMetadata) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) CatalogProperties(org.apache.iceberg.CatalogProperties) TableOperations(org.apache.iceberg.TableOperations) BaseMetastoreTableOperations(org.apache.iceberg.BaseMetastoreTableOperations) NoSuchNamespaceException(org.apache.iceberg.exceptions.NoSuchNamespaceException) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) BaseMetastoreCatalog(org.apache.iceberg.BaseMetastoreCatalog) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) Path(org.apache.hadoop.fs.Path) NamespaceNotEmptyException(org.apache.iceberg.exceptions.NamespaceNotEmptyException) Namespace(org.apache.iceberg.catalog.Namespace) Configurable(org.apache.hadoop.conf.Configurable) SupportsNamespaces(org.apache.iceberg.catalog.SupportsNamespaces) Logger(org.slf4j.Logger) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Maps(org.apache.iceberg.relocated.com.google.common.collect.Maps) Set(java.util.Set) TException(org.apache.thrift.TException) MoreObjects(org.apache.iceberg.relocated.com.google.common.base.MoreObjects) ImmutableList(org.apache.iceberg.relocated.com.google.common.collect.ImmutableList) Collectors(java.util.stream.Collectors) Table(org.apache.hadoop.hive.metastore.api.Table) List(java.util.List) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) ClientPool(org.apache.iceberg.ClientPool) Preconditions(org.apache.iceberg.relocated.com.google.common.base.Preconditions) FileIO(org.apache.iceberg.io.FileIO) Database(org.apache.hadoop.hive.metastore.api.Database) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) TException(org.apache.thrift.TException) Table(org.apache.hadoop.hive.metastore.api.Table) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) NoSuchNamespaceException(org.apache.iceberg.exceptions.NoSuchNamespaceException)

Aggregations

Database (org.apache.hadoop.hive.metastore.api.Database)3 NoSuchNamespaceException (org.apache.iceberg.exceptions.NoSuchNamespaceException)3 Path (org.apache.hadoop.fs.Path)2 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)2 TException (org.apache.thrift.TException)2 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Configurable (org.apache.hadoop.conf.Configurable)1 Configuration (org.apache.hadoop.conf.Configuration)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 BaseMetastoreCatalog (org.apache.iceberg.BaseMetastoreCatalog)1 BaseMetastoreTableOperations (org.apache.iceberg.BaseMetastoreTableOperations)1 CatalogProperties (org.apache.iceberg.CatalogProperties)1