use of io.prestosql.spi.metastore.model.TableEntity in project hetu-core by openlookeng.
the class TestHetuFsMetastore method testDropTable.
/**
* test drop table
*/
@Test
public void testDropTable() {
String dbName11 = "db110";
DatabaseEntity db11 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName(dbName11).build();
metastore.createDatabase(db11);
// for create table in dbName11
SchemaTableName tableName1 = new SchemaTableName(dbName11, "testview");
TableEntity table = TableEntity.builder().setCatalogName(db11.getCatalogName()).setDatabaseName(db11.getName()).setTableName(tableName1.getTableName()).setTableType(TableEntityType.TABLE.toString()).build();
metastore.createTable(table);
metastore.dropTable(table.getCatalogName(), table.getDatabaseName(), table.getName());
try {
metastore.dropTable(table.getCatalogName(), table.getDatabaseName(), table.getName());
fail("expected exception");
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode());
}
assertEquals(metastore.getTable(table.getCatalogName(), table.getDatabaseName(), table.getName()), Optional.empty());
}
use of io.prestosql.spi.metastore.model.TableEntity in project hetu-core by openlookeng.
the class TestHetuFsMetastore method testAlterTableParallel.
/**
* test alter table parallel
*/
@Test
public void testAlterTableParallel() throws InterruptedException {
String tableName = "table200";
TableEntity tableEntity1 = TableEntity.builder().setCatalogName(defaultDatabase.getCatalogName()).setDatabaseName(defaultDatabase.getName()).setTableName(tableName).setTableType(TableEntityType.TABLE.toString()).build();
metastore.createTable(tableEntity1);
TableEntity tableEntity2 = TableEntity.builder().setCatalogName(defaultDatabase.getCatalogName()).setDatabaseName(defaultDatabase.getName()).setTableName(tableName).setTableType(TableEntityType.TABLE.toString()).setComment("alter table parallel").build();
testResult = true;
Thread[] threads = new Thread[5];
for (int i = 0; i < 5; i++) {
threads[i] = new Thread(() -> {
try {
metastore.alterTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName, tableEntity2);
} catch (PrestoException e) {
testResult = false;
}
});
threads[i].start();
}
for (Thread thread : threads) {
thread.join();
}
assertTrue(testResult);
metastore.dropTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName);
}
use of io.prestosql.spi.metastore.model.TableEntity in project hetu-core by openlookeng.
the class TestHetuFsMetastore method testAlterView.
/**
* test alter view
*/
@Test
public void testAlterView() {
String dbName15 = "db150";
DatabaseEntity db15 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName(dbName15).build();
metastore.createDatabase(db15);
// alter view
String table131 = "table131";
TableEntity view = TableEntity.builder().setCatalogName(db15.getCatalogName()).setDatabaseName(db15.getName()).setTableName(table131).setTableType(TableEntityType.VIRTUAL_VIEW.toString()).setViewOriginalText(Optional.of(viewData)).setColumns(ImmutableList.of(new ColumnEntity(table131, parseTypeSignature(typeInt).toString(), "table131 column", emptyMap()))).build();
metastore.createTable(view);
String newViewName = "new131";
TableEntity newView = TableEntity.builder(view).setTableName(newViewName).setOwner(owner).setComment("alter view").setViewOriginalText(Optional.of("select * from t1")).setColumns(ImmutableList.of(new ColumnEntity(newViewName, parseTypeSignature(typeVarchar).toString(), "new131 column", emptyMap()))).build();
metastore.alterTable(view.getCatalogName(), view.getDatabaseName(), table131, newView);
Optional<TableEntity> newView1 = metastore.getTable(newView.getCatalogName(), newView.getDatabaseName(), newView.getName());
assertTrue(newView1.isPresent());
assertTableEquals(newView1.get(), newView);
assertEquals(newView1.get().getCreateTime(), view.getCreateTime());
}
use of io.prestosql.spi.metastore.model.TableEntity 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());
}
}
use of io.prestosql.spi.metastore.model.TableEntity in project hetu-core by openlookeng.
the class TestHetuFsMetastore method testAlterTableParametersParallel.
@Test
public void testAlterTableParametersParallel() throws InterruptedException {
String tableName = "table2000";
TableEntity tableEntity = TableEntity.builder().setCatalogName(defaultDatabase.getCatalogName()).setDatabaseName(defaultDatabase.getName()).setTableName(tableName).setTableType(TableEntityType.TABLE.toString()).build();
metastore.createTable(tableEntity);
int num = 100;
Thread[] threads = new Thread[num];
for (int i = 0; i < num; i++) {
int finalI = i;
threads[i] = new Thread(() -> {
try {
metastore.alterTableParameter(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName, String.valueOf(finalI), String.valueOf(finalI));
} catch (Exception e) {
testResult = false;
}
});
threads[i].start();
}
for (Thread thread : threads) {
thread.join();
}
Map<String, String> res = metastore.getTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName).get().getParameters();
assertEquals(num, res.size());
metastore.dropTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName);
}
Aggregations