use of io.prestosql.spi.metastore.model.DatabaseEntity 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.DatabaseEntity in project hetu-core by openlookeng.
the class HetuHBaseMetastore method addHBaseTable.
@Override
public void addHBaseTable(HBaseTable hBaseTable) {
synchronized (hbaseTables) {
TableEntity tableEntity = hBaseTableToTableEntity(hBaseTable);
if (!hetuMetastore.getDatabase(catalogName, hBaseTable.getSchema()).isPresent()) {
DatabaseEntity databaseEntity = DatabaseEntity.builder().setCatalogName(catalogName).setDatabaseName(hBaseTable.getSchema()).setCreateTime(new Date().getTime()).build();
hetuMetastore.createDatabase(databaseEntity);
}
hetuMetastore.createTable(tableEntity);
hbaseTables.put(hBaseTable.getFullTableName(), hBaseTable);
}
}
use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal method testAllDatabases.
/**
* test get all databases with metastore cache
*/
@Test
public void testAllDatabases() throws JsonProcessingException {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("desc", "vschema").build();
DatabaseEntity databaseEntity1 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db5").setOwner("root10").setComment(Optional.of("Hetu create database")).setCreateTime(System.currentTimeMillis()).setParameters(properties).build();
metastore.createDatabase(databaseEntity1);
DatabaseEntity databaseEntity2 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db6").setOwner("root11").setComment(Optional.of("Hetu create database")).setCreateTime(System.currentTimeMillis()).setParameters(properties).build();
metastore.createDatabase(databaseEntity2);
List<DatabaseEntity> databaseEntities = metastore.getAllDatabases(defaultCatalog.getName());
actual = mapper.writeValueAsString(databasesCache.getIfPresent(defaultCatalog.getName()));
expected = mapper.writeValueAsString(databaseEntities);
assertEquals(actual, expected);
metastore.dropDatabase(defaultCatalog.getName(), "db5");
metastore.dropDatabase(defaultCatalog.getName(), "db6");
}
use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreCacheLocal method testGetDatabase.
/**
* test get database with metastore cache
*/
@Test
public void testGetDatabase() throws JsonProcessingException {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("desc", "vschema").build();
DatabaseEntity databaseEntity = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db4").setOwner("root9").setComment(Optional.of("Hetu create database")).setCreateTime(System.currentTimeMillis()).setParameters(properties).build();
metastore.createDatabase(databaseEntity);
Optional<DatabaseEntity> databaseEntity2 = metastore.getDatabase(defaultCatalog.getName(), "db4");
assertTrue(databaseEntity2.isPresent());
actual = mapper.writeValueAsString(databaseEntity2.get());
expected = mapper.writeValueAsString(databaseEntity);
assertEquals(actual, expected);
metastore.dropDatabase(defaultCatalog.getName(), "db4");
}
use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestHetuMetastoreGlobalCache method testDropDatabase.
/**
* test drop database with metastore cache
*/
@Test
public void testDropDatabase() {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("desc", "vschema").build();
DatabaseEntity databaseEntity = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db3").setOwner("root8").setComment(Optional.of("Hetu create database")).setCreateTime(System.currentTimeMillis()).setParameters(properties).build();
metastore.createDatabase(databaseEntity);
metastore.dropDatabase(defaultCatalog.getName(), "db3");
String key = defaultCatalog.getName() + "." + "db3";
assertEquals(databaseCache.getIfPresent(key), null);
assertEquals(databasesCache.getIfPresent(defaultCatalog.getName()), null);
}
Aggregations