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