Search in sources :

Example 11 with DatabaseEntity

use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.

the class TestHetuFsMetastore method testAlterDatabase.

/**
 * test alter database
 */
@Test
public void testAlterDatabase() {
    DatabaseEntity db50 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db50").setOwner("root50").setComment(Optional.of("Hetu database")).setCreateTime(System.currentTimeMillis()).setParameters(emptyMap()).build();
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("location", "hdfs://db001").build();
    TableEntity table = TableEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db50").setTableName("table50").setTableType("view").setOwner("root50").setComment("Hetu table").setCreateTime(System.currentTimeMillis()).setParameters(emptyMap()).build();
    metastore.createDatabase(db50);
    metastore.createTable(table);
    Optional<TableEntity> checkTable = metastore.getTable(defaultCatalog.getName(), db50.getName(), "table50");
    assertTrue(checkTable.isPresent());
    assertTrue(checkTable.get().equals(table));
    // alter database properties and database name
    DatabaseEntity newDb = DatabaseEntity.builder(db50).setDatabaseName("newdb50").setParameters(properties).build();
    metastore.alterDatabase(defaultCatalog.getName(), db50.getName(), newDb);
    Optional<DatabaseEntity> originalDb = metastore.getDatabase(defaultCatalog.getName(), db50.getName());
    assertFalse(originalDb.isPresent());
    Optional<DatabaseEntity> checkDb = metastore.getDatabase(defaultCatalog.getName(), newDb.getName());
    assertTrue(checkDb.isPresent());
    assertTrue(checkDb.get().equals(newDb));
    // can show all view.
    TableEntity newTable = TableEntity.builder(table).setDatabaseName(newDb.getName()).build();
    checkTable = metastore.getTable(defaultCatalog.getName(), newDb.getName(), "table50");
    assertTrue(checkTable.isPresent());
    assertTrue(checkTable.get().equals(newTable));
    DatabaseEntity alterDb = DatabaseEntity.builder(db50).setCatalogName("hetu1").build();
    try {
        metastore.alterDatabase(db50.getCatalogName(), db50.getName(), alterDb);
        fail(format("alter database cannot cross catalog[%s,%s]", db50.getCatalogName(), alterDb.getName()));
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), HETU_METASTORE_CODE.toErrorCode());
    }
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) PrestoException(io.prestosql.spi.PrestoException) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Test(org.testng.annotations.Test)

Example 12 with DatabaseEntity

use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.

the class TestHetuFsMetastore method testDropDatabase.

/**
 * test drop database
 */
@Test
public void testDropDatabase() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("url", "127.0.0.1").put("user", "test").build();
    DatabaseEntity db20 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db20").setOwner("root11").setComment(Optional.of("Hetu schema")).setCreateTime(System.currentTimeMillis()).setParameters(properties).build();
    metastore.createDatabase(db20);
    metastore.dropDatabase(db20.getCatalogName(), db20.getName());
    String vschemaName3 = "vschema30";
    DatabaseEntity db30 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("db20").setOwner("root10").setComment(Optional.of("Hetu schema")).setCreateTime(System.currentTimeMillis()).setParameters(properties).build();
    metastore.createDatabase(db30);
    ConnectorViewDefinition definition = new ConnectorViewDefinition(viewData, Optional.of(vschemaName3), Optional.of(vschemaName3), ImmutableList.of(new ConnectorViewDefinition.ViewColumn(vschemaName3, parseTypeSignature(typeInt)), new ConnectorViewDefinition.ViewColumn(vschemaName3, parseTypeSignature(typeVarchar))), Optional.of(owner), false);
    TableEntity table = TableEntity.builder().setCatalogName(db30.getCatalogName()).setDatabaseName(db30.getName()).setTableName("view1").setOwner("root10").setComment("Hetu View").setViewOriginalText(Optional.of(definition.toString())).setTableType(TableEntityType.VIRTUAL_VIEW.toString()).build();
    metastore.createTable(table);
    try {
        metastore.dropDatabase(db30.getCatalogName(), db30.getName());
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), SCHEMA_NOT_EMPTY.toErrorCode());
    }
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) PrestoException(io.prestosql.spi.PrestoException) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) Test(org.testng.annotations.Test)

Example 13 with DatabaseEntity

use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.

the class DatabaseEntityReducer method accumulate.

@Override
public void accumulate(Map<Long, DatabaseEntity> map, RowView rowView) {
    DatabaseEntity database = map.computeIfAbsent(rowView.getColumn("d_id", Long.class), id -> rowView.getRow(DatabaseEntity.class));
    if (rowView.getColumn("p_id", Long.class) != null) {
        PropertyEntity property = rowView.getRow(PropertyEntity.class);
        database.getParameters().put(property.getKey(), property.getValue());
    }
}
Also used : DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity)

Example 14 with DatabaseEntity

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

Example 15 with DatabaseEntity

use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.

the class TestHetuFsMetastore method testCreateTable.

/**
 * testCreateView
 */
@Test
public void testCreateTable() {
    String dbName9 = "db90";
    DatabaseEntity db90 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName(dbName9).build();
    metastore.createDatabase(db90);
    SchemaTableName viewName1 = new SchemaTableName(dbName9, "testView");
    ConnectorViewDefinition definition = new ConnectorViewDefinition(viewData, Optional.of(dbName9), Optional.of(dbName9), ImmutableList.of(new ConnectorViewDefinition.ViewColumn(dbName9, parseTypeSignature(typeInt)), new ConnectorViewDefinition.ViewColumn(dbName9 + 1, parseTypeSignature(typeVarchar))), Optional.of(owner), false);
    Map<String, String> props1 = ImmutableMap.<String, String>builder().put("rowNumber", "128").put("columnNumber", "2").put("totalFile", "128").build();
    TableEntity mv = TableEntity.builder().setCatalogName(db90.getCatalogName()).setDatabaseName(dbName9).setTableName(viewName1.getTableName()).setTableType(TableEntityType.MATERIALIZED_VIEW.toString()).setViewOriginalText(Optional.of(definition.toString())).setColumns(ImmutableList.of(new ColumnEntity(dbName9, parseTypeSignature(typeInt).toString(), "dbName9 column", emptyMap()), new ColumnEntity(dbName9 + 1, parseTypeSignature(typeVarchar).toString(), "table column", emptyMap()))).setParameters(props1).build();
    metastore.createTable(mv);
    // table exist
    try {
        metastore.createTable(mv);
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), ALREADY_EXISTS.toErrorCode());
    }
    // database not exist
    try {
        mv.setDatabaseName("dbName9");
        metastore.createTable(mv);
        fail(format("Database '%s.%s' does not exist:", mv.getCatalogName(), mv.getDatabaseName()));
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode());
    }
}
Also used : ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) TableEntity(io.prestosql.spi.metastore.model.TableEntity) PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) Test(org.testng.annotations.Test)

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