Search in sources :

Example 26 with TableEntity

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

the class TestJdbcHetuMetastore method testGetAllTables.

/**
 * test get all table
 */
@Test
public void testGetAllTables() {
    String dbName8 = "db80";
    DatabaseEntity db80 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName(dbName8).build();
    metastore.createDatabase(db80);
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("bucket", "yes").put("index", "0").build();
    String tableName5 = "table5";
    TableEntity table = TableEntity.builder().setCatalogName(db80.getCatalogName()).setDatabaseName(dbName8).setTableName(tableName5).setOwner(dbName8).setTableType(TableEntityType.TABLE.toString()).setColumns(ImmutableList.of(new ColumnEntity(dbName8, parseTypeSignature(typeInt).toString(), "dbName8 column", emptyMap()), new ColumnEntity(dbName8 + tableName5, parseTypeSignature(typeVarchar).toString(), "table1 column", properties))).setCreateTime(System.currentTimeMillis()).build();
    metastore.createTable(table);
    TableEntity table1 = TableEntity.builder().setCatalogName(db80.getCatalogName()).setDatabaseName(dbName8).setTableName(dbName8 + tableName5).setOwner(dbName8).setTableType(TableEntityType.TABLE.toString()).setColumns(ImmutableList.of(new ColumnEntity(dbName8, parseTypeSignature(typeInt).toString(), "dbName8 column", emptyMap()), new ColumnEntity(dbName8 + tableName5, parseTypeSignature(typeVarchar).toString(), "table column", properties))).setCreateTime(System.currentTimeMillis()).build();
    metastore.createTable(table1);
    assertEquals(ImmutableSet.copyOf(metastore.getAllTables(db80.getCatalogName(), dbName8)), ImmutableSet.of(table, table1));
}
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 27 with TableEntity

use of io.prestosql.spi.metastore.model.TableEntity 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 28 with TableEntity

use of io.prestosql.spi.metastore.model.TableEntity 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 29 with TableEntity

use of io.prestosql.spi.metastore.model.TableEntity 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 30 with TableEntity

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

the class HetuHBaseMetastore method getAllHBaseTables.

@Override
public Map<String, HBaseTable> getAllHBaseTables() {
    synchronized (hbaseTables) {
        if (hasAllTables.get()) {
            return ImmutableMap.copyOf(hbaseTables);
        }
        Map<String, HBaseTable> hbaseTablesTemp = new ConcurrentHashMap<>();
        List<DatabaseEntity> dbs = hetuMetastore.getAllDatabases(catalogName);
        for (DatabaseEntity db : dbs) {
            List<TableEntity> tables = hetuMetastore.getAllTables(db.getCatalogName(), db.getName());
            for (TableEntity table : tables) {
                HBaseTable hBaseTable = getHBaseTableFromHetuMetastore(table.getCatalogName(), table.getDatabaseName(), table.getName());
                hbaseTablesTemp.put(hBaseTable.getFullTableName(), hBaseTable);
            }
        }
        hbaseTables.clear();
        hbaseTables.putAll(hbaseTablesTemp);
        hasAllTables.set(true);
        return ImmutableMap.copyOf(hbaseTables);
    }
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity)

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