use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class StarTreeMetaStore method persist.
@Override
public void persist(CubeMetadata cubeMetadata) {
CatalogEntity catalogEntity = catalogEntity();
if (!metastore.getCatalog(catalogEntity.getName()).isPresent()) {
metastore.createCatalog(catalogEntity);
}
DatabaseEntity databaseEntity = databaseEntity();
if (!metastore.getDatabase(catalogEntity.getName(), databaseEntity.getName()).isPresent()) {
metastore.createDatabase(databaseEntity);
}
String cubeNameDelimited = cubeMetadata.getCubeName().replace(".", "_");
TableEntity table = getTableEntity((StarTreeMetadata) cubeMetadata);
if (metastore.getTable(CUBE_CATALOG, CUBE_DATABASE, cubeNameDelimited).isPresent()) {
// update flow
metastore.alterTable(CUBE_CATALOG, CUBE_DATABASE, cubeNameDelimited, table);
} else {
// create flow
metastore.createTable(table);
}
cubeCache.invalidate(cubeMetadata.getSourceTableName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuFsMetastore method testDropCatalog.
/**
* test drop dropCatalog
*/
@Test
public void testDropCatalog() {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("hive1.metastore", "129.0.0.1").put("hive1.config", "core-site.xml").build();
CatalogEntity hive = CatalogEntity.builder().setCatalogName("hive").setOwner("root3").setComment(Optional.of("hive database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(hive);
// drop not exist catalog
try {
metastore.dropCatalog("noExistCatalog");
fail("expected exception");
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode());
}
// drop catalog not empty
DatabaseEntity db1 = DatabaseEntity.builder().setCatalogName(hive.getName()).setDatabaseName("db1").setOwner("root4").build();
metastore.createDatabase(db1);
try {
metastore.dropCatalog(hive.getName());
fail("expected exception");
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), CATALOG_NOT_EMPTY.toErrorCode());
}
metastore.dropDatabase(db1.getCatalogName(), db1.getName());
metastore.dropCatalog(hive.getName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore method testGetAllCatalogs.
/**
* test get All catalogs
*/
@Test
public void testGetAllCatalogs() {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("hive.metastore", "130.0.0.1").put("hive.config", "hdfs-site.xml").build();
CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog2").setOwner("root6").setComment(Optional.of("mysql database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalog2);
CatalogEntity catalog3 = CatalogEntity.builder().setCatalogName("catalog3").setOwner("root7").setComment(Optional.of("mysql1 database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalog3);
CatalogEntity catalog4 = CatalogEntity.builder().setCatalogName("catalog4").setOwner("root8").setComment(Optional.of("oracle database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalog4);
final int catalogNumer = 3;
assertTrue(metastore.getCatalogs().size() > catalogNumer);
ImmutableList.Builder<CatalogEntity> catalogs = ImmutableList.builder();
metastore.getCatalogs().stream().forEach(catalog -> {
String name = catalog.getName();
if (name.equals(catalog2.getName()) || name.equals(catalog3.getName()) || name.equals(catalog4.getName())) {
catalogs.add(catalog);
}
});
assertEquals(catalogs.build(), ImmutableList.of(catalog2, catalog3, catalog4));
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore method testCreateCatalogParallel.
/**
* test create catalog parallel
*/
@Test
public void testCreateCatalogParallel() throws InterruptedException {
Map<String, String> properties = ImmutableMap.<String, String>builder().build();
CatalogEntity catalog = CatalogEntity.builder().setCatalogName("catalog100").setOwner("root1").setComment(Optional.of("create catalog parallel")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
testResult = true;
Thread[] threads = new Thread[5];
for (int i = 0; i < 5; i++) {
threads[i] = new Thread(() -> {
try {
metastore.createCatalogIfNotExist(catalog);
} catch (PrestoException e) {
testResult = false;
}
});
threads[i].start();
}
for (Thread thread : threads) {
thread.join();
}
assertTrue(testResult);
metastore.dropCatalog(catalog.getName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore method testGetCatalog.
/**
* test get catalog
*/
@Test
public void testGetCatalog() {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("hive.metastore", "126.0.0.1").put("hive.config", "hdfs-site.xml").build();
CatalogEntity catalog1 = CatalogEntity.builder().setCatalogName("hive2").setOwner("root5").setComment(Optional.of("hive database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalog1);
Optional<CatalogEntity> catalogInfo = metastore.getCatalog(catalog1.getName());
assertTrue(catalogInfo.isPresent());
assertEquals(catalog1.getParameters(), catalogInfo.get().getParameters());
assertEquals(catalogInfo.get(), catalog1);
Optional<CatalogEntity> catalogInfo1 = metastore.getCatalog("mysql");
assertFalse(catalogInfo1.isPresent());
}
Aggregations