use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore 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);
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), HETU_METASTORE_CODE.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(), HETU_METASTORE_CODE.toErrorCode());
}
}
use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore method testGetTable.
/**
* test get table
*/
@Test
public void testGetTable() {
String dbName7 = "db70";
DatabaseEntity db70 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName(dbName7).build();
metastore.createDatabase(db70);
String tableName = "table1";
SchemaTableName viewName = new SchemaTableName(db70.getName(), tableName);
ConnectorViewDefinition definition = new ConnectorViewDefinition(viewData, Optional.of(dbName7), Optional.of(dbName7), ImmutableList.of(new ConnectorViewDefinition.ViewColumn(dbName7, parseTypeSignature(typeInt)), new ConnectorViewDefinition.ViewColumn(dbName7 + tableName, parseTypeSignature(typeVarchar))), Optional.of(owner), false);
TableEntity table = TableEntity.builder().setCatalogName(db70.getCatalogName()).setDatabaseName(db70.getName()).setTableName(viewName.getTableName()).setOwner(dbName7).setTableType(TableEntityType.VIRTUAL_VIEW.toString()).setColumns(definition.getColumns().stream().map(column -> new ColumnEntity(column.getName(), column.getType().toString(), "View column", emptyMap())).collect(toList())).build();
metastore.createTable(table);
// table exist
Optional<TableEntity> tableEntity = metastore.getTable(table.getCatalogName(), table.getDatabaseName(), table.getName());
assertTrue(tableEntity.isPresent());
assertEquals(tableEntity.get(), table);
// table not exist
assertEquals(metastore.getTable(db70.getCatalogName(), dbName7, "table2"), Optional.empty());
}
use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore 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());
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), HETU_METASTORE_CODE.toErrorCode());
}
}
use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore method testCreateDatabaseParallel.
/**
* test create database parallel
*/
@Test
public void testCreateDatabaseParallel() throws InterruptedException {
Map<String, String> properties = ImmutableMap.<String, String>builder().put("desc", "vschema").build();
DatabaseEntity tmpDatabase = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName("database100").setOwner("root9").setComment(Optional.of("Hetu create database.")).setCreateTime(System.currentTimeMillis()).setParameters(properties).build();
testResult = true;
Thread[] threads = new Thread[5];
for (int i = 0; i < 5; i++) {
threads[i] = new Thread(() -> {
try {
metastore.createDatabaseIfNotExist(tmpDatabase);
} catch (PrestoException e) {
testResult = false;
}
});
threads[i].start();
}
for (Thread thread : threads) {
thread.join();
}
assertTrue(testResult);
metastore.dropDatabase(tmpDatabase.getCatalogName(), tmpDatabase.getName());
}
use of io.prestosql.spi.metastore.model.DatabaseEntity in project hetu-core by openlookeng.
the class TestJdbcHetuMetastore method alterDatabase.
/**
* test alter database
*/
@Test
public void alterDatabase() {
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();
DatabaseEntity newDb = DatabaseEntity.builder(db50).setParameters(properties).build();
metastore.createDatabase(db50);
metastore.alterDatabase(defaultCatalog.getName(), db50.getName(), newDb);
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());
}
}
Aggregations