Search in sources :

Example 1 with DatabaseEntity

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());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) TableEntity(io.prestosql.spi.metastore.model.TableEntity) IndexRecord(io.prestosql.spi.heuristicindex.IndexRecord) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity)

Example 2 with DatabaseEntity

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);
    }
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Date(java.util.Date)

Example 3 with DatabaseEntity

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");
}
Also used : DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Test(org.testng.annotations.Test)

Example 4 with DatabaseEntity

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");
}
Also used : DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Test(org.testng.annotations.Test)

Example 5 with DatabaseEntity

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);
}
Also used : DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)48 Test (org.testng.annotations.Test)38 PrestoException (io.prestosql.spi.PrestoException)24 TableEntity (io.prestosql.spi.metastore.model.TableEntity)21 ImmutableList (com.google.common.collect.ImmutableList)8 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)8 CatalogEntity (io.prestosql.spi.metastore.model.CatalogEntity)8 ColumnEntity (io.prestosql.spi.metastore.model.ColumnEntity)8 ConnectorViewDefinition (io.prestosql.spi.connector.ConnectorViewDefinition)5 IOException (java.io.IOException)5 BeforeTest (org.testng.annotations.BeforeTest)5 Logger (io.airlift.log.Logger)4 HETU_METASTORE_CODE (io.prestosql.spi.metastore.HetuErrorCode.HETU_METASTORE_CODE)4 HetuMetastore (io.prestosql.spi.metastore.HetuMetastore)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Optional (java.util.Optional)4 SchemaNotFoundException (io.prestosql.spi.connector.SchemaNotFoundException)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Throwables.throwIfUnchecked (com.google.common.base.Throwables.throwIfUnchecked)2