Search in sources :

Example 16 with TableEntity

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());
}
Also used : 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) Test(org.testng.annotations.Test)

Example 17 with TableEntity

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

Example 18 with TableEntity

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

Example 19 with TableEntity

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());
    }
}
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 20 with TableEntity

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

Aggregations

TableEntity (io.prestosql.spi.metastore.model.TableEntity)53 Test (org.testng.annotations.Test)31 PrestoException (io.prestosql.spi.PrestoException)25 DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)22 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)20 ColumnEntity (io.prestosql.spi.metastore.model.ColumnEntity)11 IOException (java.io.IOException)9 ConnectorViewDefinition (io.prestosql.spi.connector.ConnectorViewDefinition)8 ImmutableList (com.google.common.collect.ImmutableList)7 CatalogEntity (io.prestosql.spi.metastore.model.CatalogEntity)7 ArrayList (java.util.ArrayList)7 Logger (io.airlift.log.Logger)5 List (java.util.List)5 Optional (java.util.Optional)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 BeforeTest (org.testng.annotations.BeforeTest)4 SchemaNotFoundException (io.prestosql.spi.connector.SchemaNotFoundException)3 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)3 HETU_METASTORE_CODE (io.prestosql.spi.metastore.HetuErrorCode.HETU_METASTORE_CODE)3 HetuMetastore (io.prestosql.spi.metastore.HetuMetastore)3