use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.
the class MetadataManager method getViews.
@Override
public Map<QualifiedObjectName, ConnectorViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Map<QualifiedObjectName, ConnectorViewDefinition> views = new LinkedHashMap<>();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
Map<SchemaTableName, ConnectorViewDefinition> viewMap;
if (tablePrefix.getTable().isPresent()) {
viewMap = metadata.getView(connectorSession, tablePrefix.toSchemaTableName()).map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view)).orElse(ImmutableMap.of());
} else {
viewMap = metadata.getViews(connectorSession, tablePrefix.getSchema());
}
for (Entry<SchemaTableName, ConnectorViewDefinition> entry : viewMap.entrySet()) {
QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
views.put(viewName, entry.getValue());
}
}
}
return ImmutableMap.copyOf(views);
}
use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.
the class AbstractTestHive method testGetAllTableColumns.
@Test
public void testGetAllTableColumns() {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
Map<SchemaTableName, List<ColumnMetadata>> allColumns = metadata.listTableColumns(newSession(), new SchemaTablePrefix());
assertTrue(allColumns.containsKey(tablePartitionFormat));
assertTrue(allColumns.containsKey(tableUnpartitioned));
}
}
use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.
the class AbstractTestHive method testHiveViewsHaveNoColumns.
@Test
public void testHiveViewsHaveNoColumns() {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
assertEquals(metadata.listTableColumns(newSession(), new SchemaTablePrefix(view.getSchemaName(), view.getTableName())), ImmutableMap.of());
}
}
use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.
the class TestHBase method testListTableColumns.
/**
* testListTableColumns
*/
@Test
public void testListTableColumns() {
Map<SchemaTableName, List<ColumnMetadata>> tables = hcm.listTableColumns(session, new SchemaTablePrefix("hbase", "test_table"));
assertEquals(5, tables.get(new SchemaTableName("hbase", "test_table")).size());
}
use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.
the class TestCachingJdbcMetadata method testListTableColumns.
@Test
public void testListTableColumns() throws SQLException, InterruptedException {
// add cachingtable
database.getConnection().createStatement().execute("CREATE SCHEMA cachingschema");
database.getConnection().createStatement().execute("CREATE TABLE cachingschema.cachingtable(id varchar primary key)");
// should only have one column
SchemaTablePrefix tablePrefix = new SchemaTablePrefix("cachingschema", "cachingtable");
assertEquals(metadata.listTableColumns(session, tablePrefix), ImmutableMap.of(cachingSchemaTableName, ImmutableList.of(new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap()))));
// add a new column
database.getConnection().createStatement().execute("ALTER TABLE cachingschema.cachingtable ADD COLUMN value VARCHAR(50)");
// should still only have one column bc it is cached
assertEquals(metadata.listTableColumns(session, tablePrefix), ImmutableMap.of(cachingSchemaTableName, ImmutableList.of(new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap()))));
// wait for cache to expire
Thread.sleep(CACHE_TTL + 50);
// should now see the new column
assertEquals(metadata.listTableColumns(session, tablePrefix), ImmutableMap.of(cachingSchemaTableName, ImmutableList.of(new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("value", createVarcharType(50)))));
}
Aggregations