use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class IndexRecordManager method addIndexRecord.
/**
* Add IndexRecord into record file. If the method is called with a name that already exists,
*
* it will OVERWRITE the existing entry but COMBINE the partition columns (if it previously was partitioned)
*/
public synchronized void addIndexRecord(String name, String user, String table, String[] columns, String indexType, long indexSize, List<String> indexProperties, List<String> partitions) {
IndexRecord record = new IndexRecord(name, user, table, columns, indexType, indexSize, indexProperties, partitions);
IndexRecord old = lookUpIndexRecord(name);
if (old != null) {
record.partitions.addAll(0, old.partitions);
}
Optional<CatalogEntity> oldCatalog = metastore.getCatalog(record.catalog);
if (!oldCatalog.isPresent()) {
CatalogEntity newCatalog = CatalogEntity.builder().setCatalogName(record.catalog).build();
metastore.createCatalogIfNotExist(newCatalog);
}
Optional<DatabaseEntity> oldSchema = metastore.getDatabase(record.catalog, record.schema);
if (!oldSchema.isPresent()) {
DatabaseEntity newSchema = DatabaseEntity.builder().setCatalogName(record.catalog).setDatabaseName(record.schema).build();
metastore.createDatabaseIfNotExist(newSchema);
}
Optional<TableEntity> oldTable = metastore.getTable(record.catalog, record.schema, record.table);
if (!oldTable.isPresent()) {
TableEntity newTable = TableEntity.builder().setCatalogName(record.catalog).setDatabaseName(record.schema).setTableName(record.table).setTableType(TableEntityType.TABLE.toString()).build();
metastore.createTableIfNotExist(newTable);
}
metastore.alterTableParameter(record.catalog, record.schema, record.table, record.serializeKey(), record.serializeValue());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal method testDropCatalog.
/**
* test drop dropCatalog with metastore cache
*/
@Test
public void testDropCatalog() {
Map<String, String> properties = ImmutableMap.<String, String>builder().build();
CatalogEntity catalogEntity = CatalogEntity.builder().setCatalogName("catalog2").setOwner("root2").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalogEntity);
metastore.dropCatalog(catalogEntity.getName());
assertEquals(catalogCache.getIfPresent("catalog2"), null);
assertEquals(catalogsCache.getIfPresent(""), null);
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal method testGetCatalog.
/**
* test get catalog with metastore cache
*/
@Test
public void testGetCatalog() throws JsonProcessingException {
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());
actual = mapper.writeValueAsString(catalogInfo.get());
expected = mapper.writeValueAsString(catalogEntity);
assertEquals(actual, expected);
assertEquals(catalogInfo.get(), catalogEntity);
metastore.dropCatalog(catalogEntity.getName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal method testGetAllCatalogs.
/**
* test get All catalogs with metastore cache
*/
@Test
public void testGetAllCatalogs() throws JsonProcessingException {
Map<String, String> properties = ImmutableMap.<String, String>builder().build();
CatalogEntity catalog1 = CatalogEntity.builder().setCatalogName("catalog4").setOwner("root4").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalog1);
CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog5").setOwner("root5").setComment(Optional.of("Hetu create catalog")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
metastore.createCatalog(catalog2);
List<CatalogEntity> catalogEntities = metastore.getCatalogs();
actual = mapper.writeValueAsString(catalogsCache.getIfPresent(""));
expected = mapper.writeValueAsString(catalogEntities);
assertEquals(actual, expected);
metastore.dropCatalog(catalog1.getName());
metastore.dropCatalog(catalog2.getName());
}
use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal 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());
}
Aggregations