Search in sources :

Example 21 with DatabaseEntity

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

Example 22 with DatabaseEntity

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());
}
Also used : HetuMetastore(io.prestosql.spi.metastore.HetuMetastore) CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) TestingMysqlDatabase(io.hetu.core.metastore.TestingMysqlDatabase) Logger(io.airlift.log.Logger) MBeanModule(org.weakref.jmx.guice.MBeanModule) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) TableEntityType(io.prestosql.spi.metastore.model.TableEntityType) NOT_FOUND(io.prestosql.spi.StandardErrorCode.NOT_FOUND) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) LOCAL(io.hetu.core.metastore.MetaStoreConstants.LOCAL) Map(java.util.Map) MetastoreUtFileLoader(io.hetu.core.metastore.MetastoreUtFileLoader) Assert.assertFalse(org.testng.Assert.assertFalse) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) AfterClass(org.testng.annotations.AfterClass) Collections.emptyMap(java.util.Collections.emptyMap) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) MBeanServerModule(io.prestosql.plugin.base.jmx.MBeanServerModule) BeforeClass(org.testng.annotations.BeforeClass) Assert.fail(org.testng.Assert.fail) JdbcMetastoreModule(io.hetu.core.metastore.jdbc.JdbcMetastoreModule) IOException(java.io.IOException) String.format(java.lang.String.format) Injector(com.google.inject.Injector) PROPERTY_FILE_PATH(io.hetu.core.metastore.MetaStoreUtConstants.PROPERTY_FILE_PATH) TableEntity(io.prestosql.spi.metastore.model.TableEntity) Collectors.toList(java.util.stream.Collectors.toList) ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) Bootstrap(io.airlift.bootstrap.Bootstrap) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) HETU_METASTORE_CODE(io.prestosql.spi.metastore.HetuErrorCode.HETU_METASTORE_CODE) ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) TableEntity(io.prestosql.spi.metastore.model.TableEntity) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) Test(org.testng.annotations.Test)

Example 23 with DatabaseEntity

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());
    }
}
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 24 with DatabaseEntity

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

Example 25 with DatabaseEntity

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