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);
}
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);
}
}
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")));
}
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);
});
}
Aggregations