use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreGlobalCache method testAlterCatalog.
/**
* test alter catalog with metastore cache
*/
@Test
public void testAlterCatalog() {
Map<String, String> properties = ImmutableMap.<String, String>builder().build();
CatalogEntity catalog1 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("root6").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalog1);
CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("hive").setComment(Optional.of("Hetu alter catalog")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
metastore.alterCatalog("catalog6", catalog2);
assertEquals(catalogsCache.getIfPresent(""), null);
metastore.dropCatalog(catalog2.getName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreGlobalCache method testGetCatalog.
/**
* test get catalog with metastore cache
*/
@Test
public void testGetCatalog() {
Map<String, String> properties = ImmutableMap.<String, String>builder().build();
CatalogEntity catalogEntity = CatalogEntity.builder().setCatalogName("catalog3").setOwner("root3").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalogEntity);
Optional<CatalogEntity> catalogInfo = metastore.getCatalog("catalog3");
assertTrue(catalogInfo.isPresent());
assertEquals(catalogInfo.get(), catalogEntity);
metastore.dropCatalog(catalogEntity.getName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreGlobalCache method testCreateCatalog.
/**
* test create catalog with metastore cache
*/
@Test
public void testCreateCatalog() {
Map<String, String> properties = ImmutableMap.<String, String>builder().build();
CatalogEntity catalogEntity = CatalogEntity.builder().setCatalogName("catalog1").setOwner("root1").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalogEntity);
assertEquals(catalogsCache.getIfPresent(""), null);
metastore.dropCatalog(catalogEntity.getName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class HetuFsMetastore method alterCatalogParameter.
@Override
public void alterCatalogParameter(String catalogName, String key, String value) {
checkArgument(catalogName.matches("[\\p{Alnum}_]+"), "Invalid catalog name");
runTransaction(() -> {
assertCatalogExist(catalogName);
try {
Path catalogMetadataPath = getCatalogMetadataPath(catalogName);
CatalogEntity catalogEntity;
try (InputStream inputStream = client.newInputStream(catalogMetadataPath)) {
String catalogJson = CharStreams.toString(new InputStreamReader(inputStream, UTF_8));
catalogEntity = CATALOG_CODEC.fromJson(catalogJson);
}
if (value == null) {
catalogEntity.getParameters().remove(key);
} else {
catalogEntity.getParameters().put(key, value);
}
try (OutputStream outputStream = client.newOutputStream(catalogMetadataPath)) {
outputStream.write(CATALOG_CODEC.toJsonBytes(catalogEntity));
}
} catch (IOException e) {
throw new PrestoException(HETU_METASTORE_CODE, e);
}
});
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class HetuFsMetastore method alterCatalog.
@Override
public void alterCatalog(String catalogName, CatalogEntity newCatalog) {
checkArgument(catalogName.matches("[\\p{Alnum}_]+"), "Invalid catalog name");
checkArgument(newCatalog.getName().matches("[\\p{Alnum}_]+"), "Invalid new catalog name");
runTransaction(() -> {
if (!catalogName.equals(newCatalog.getName())) {
throw new PrestoException(HETU_METASTORE_CODE, "Cannot alter a catalog's name");
}
assertCatalogExist(catalogName);
try {
CatalogEntity orgCatalog;
try (InputStream inputStream = client.newInputStream(getCatalogMetadataPath(catalogName))) {
String catalogJson = CharStreams.toString(new InputStreamReader(inputStream, UTF_8));
orgCatalog = CATALOG_CODEC.fromJson(catalogJson);
}
try (OutputStream outputStream = client.newOutputStream(getCatalogMetadataPath(catalogName))) {
// can not update the create time.
newCatalog.setCreateTime(orgCatalog.getCreateTime());
outputStream.write(CATALOG_CODEC.toJsonBytes(newCatalog));
}
} catch (IOException e) {
throw new PrestoException(HETU_METASTORE_CODE, e);
}
});
}
Aggregations