Search in sources :

Example 6 with Namespace

use of org.apache.iceberg.catalog.Namespace in project hive by apache.

the class TestHiveCatalog method testCreateNamespace.

@Test
public void testCreateNamespace() throws TException {
    Namespace namespace1 = Namespace.of("noLocation");
    catalog.createNamespace(namespace1, meta);
    Database database1 = metastoreClient.getDatabase(namespace1.toString());
    Assert.assertTrue(database1.getParameters().get("owner").equals("apache"));
    Assert.assertTrue(database1.getParameters().get("group").equals("iceberg"));
    Assert.assertEquals("There no same location for db and namespace", database1.getLocationUri(), defaultUri(namespace1));
    AssertHelpers.assertThrows("Should fail to create when namespace already exist " + namespace1, AlreadyExistsException.class, "Namespace '" + namespace1 + "' already exists!", () -> {
        catalog.createNamespace(namespace1);
    });
    ImmutableMap newMeta = ImmutableMap.<String, String>builder().putAll(meta).put("location", hiveLocalDir).build();
    Namespace namespace2 = Namespace.of("haveLocation");
    catalog.createNamespace(namespace2, newMeta);
    Database database2 = metastoreClient.getDatabase(namespace2.toString());
    Assert.assertEquals("There no same location for db and namespace", database2.getLocationUri(), hiveLocalDir);
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) Namespace(org.apache.iceberg.catalog.Namespace) ImmutableMap(org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 7 with Namespace

use of org.apache.iceberg.catalog.Namespace 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)

Example 8 with Namespace

use of org.apache.iceberg.catalog.Namespace in project hive by apache.

the class TestHiveCatalog method testNamespaceExists.

@Test
public void testNamespaceExists() throws TException {
    Namespace namespace = Namespace.of("dbname_exists");
    catalog.createNamespace(namespace, meta);
    Assert.assertTrue("Should true to namespace exist", catalog.namespaceExists(namespace));
    Assert.assertTrue("Should false to namespace doesn't exist", !catalog.namespaceExists(Namespace.of("db2", "db2", "ns2")));
}
Also used : Namespace(org.apache.iceberg.catalog.Namespace) Test(org.junit.Test)

Example 9 with Namespace

use of org.apache.iceberg.catalog.Namespace in project hive by apache.

the class TestHiveCatalog method testSetNamespaceProperties.

@Test
public void testSetNamespaceProperties() throws TException {
    Namespace namespace = Namespace.of("dbname_set");
    catalog.createNamespace(namespace, meta);
    catalog.setProperties(namespace, ImmutableMap.of("owner", "alter_apache", "test", "test", "location", "file:/data/tmp", "comment", "iceberg test"));
    Database database = metastoreClient.getDatabase(namespace.level(0));
    Assert.assertEquals(database.getParameters().get("owner"), "alter_apache");
    Assert.assertEquals(database.getParameters().get("test"), "test");
    Assert.assertEquals(database.getParameters().get("group"), "iceberg");
    AssertHelpers.assertThrows("Should fail to namespace not exist" + namespace, NoSuchNamespaceException.class, "Namespace does not exist: ", () -> {
        catalog.setProperties(Namespace.of("db2", "db2", "ns2"), meta);
    });
}
Also used : Database(org.apache.hadoop.hive.metastore.api.Database) Namespace(org.apache.iceberg.catalog.Namespace) Test(org.junit.Test)

Aggregations

Namespace (org.apache.iceberg.catalog.Namespace)9 Test (org.junit.Test)8 Database (org.apache.hadoop.hive.metastore.api.Database)4 TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)3 ImmutableMap (org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap)2 File (java.io.File)1 PosixFilePermissions.fromString (java.nio.file.attribute.PosixFilePermissions.fromString)1 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 Path (org.apache.hadoop.fs.Path)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 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 Table (org.apache.hadoop.hive.metastore.api.Table)1