use of io.prestosql.spi.connector.SchemaTablePrefix in project boostkit-bigdata by kunpengcompute.
the class AbstractTestHive method testListUnknownSchema.
@Test
public void testListUnknownSchema() {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
assertNull(metadata.getTableHandle(session, new SchemaTableName(INVALID_DATABASE, INVALID_TABLE)));
assertEquals(metadata.listTables(session, Optional.of(INVALID_DATABASE)), ImmutableList.of());
assertEquals(metadata.listTableColumns(session, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)), ImmutableMap.of());
assertEquals(metadata.listViews(session, Optional.of(INVALID_DATABASE)), ImmutableList.of());
assertEquals(metadata.getViews(session, Optional.of(INVALID_DATABASE)), ImmutableMap.of());
assertEquals(metadata.getView(session, new SchemaTableName(INVALID_DATABASE, INVALID_TABLE)), Optional.empty());
}
}
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)))));
}
use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.
the class MetadataManager method listTableColumns.
@Override
public Map<QualifiedObjectName, List<ColumnMetadata>> listTableColumns(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Map<QualifiedObjectName, List<ColumnMetadata>> tableColumns = new HashMap<>();
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);
for (Entry<SchemaTableName, List<ColumnMetadata>> entry : metadata.listTableColumns(connectorSession, tablePrefix).entrySet()) {
QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
tableColumns.put(tableName, entry.getValue());
}
// if table and view names overlap, the view wins
for (Entry<QualifiedObjectName, ConnectorViewDefinition> entry : getViews(session, prefix).entrySet()) {
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (ViewColumn column : entry.getValue().getColumns()) {
try {
columns.add(new ColumnMetadata(column.getName(), getType(column.getType())));
} catch (TypeNotFoundException e) {
throw new PrestoException(INVALID_VIEW, format("Unknown type '%s' for column '%s' in view: %s", column.getType(), column.getName(), entry.getKey()));
}
}
tableColumns.put(entry.getKey(), columns.build());
}
}
}
return ImmutableMap.copyOf(tableColumns);
}
use of io.prestosql.spi.connector.SchemaTablePrefix in project hetu-core by openlookeng.
the class AbstractTestHive method testGetAllTableColumnsInSchema.
@Test
public void testGetAllTableColumnsInSchema() {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
Map<SchemaTableName, List<ColumnMetadata>> allColumns = metadata.listTableColumns(newSession(), new SchemaTablePrefix(database));
assertTrue(allColumns.containsKey(tablePartitionFormat));
assertTrue(allColumns.containsKey(tableUnpartitioned));
}
}
Aggregations