use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class TableCommentSystemTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Optional<String> catalogFilter = tryGetSingleVarcharValue(constraint, 0);
Optional<String> schemaFilter = tryGetSingleVarcharValue(constraint, 1);
Optional<String> tableFilter = tryGetSingleVarcharValue(constraint, 2);
Session session = ((FullConnectorSession) connectorSession).getSession();
Builder table = InMemoryRecordSet.builder(COMMENT_TABLE);
for (String catalog : listCatalogs(session, metadata, accessControl, catalogFilter).keySet()) {
QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);
Set<SchemaTableName> names = ImmutableSet.of();
Map<SchemaTableName, ViewInfo> views = ImmutableMap.of();
Map<SchemaTableName, ViewInfo> materializedViews = ImmutableMap.of();
try {
materializedViews = getMaterializedViews(session, metadata, accessControl, prefix);
views = getViews(session, metadata, accessControl, prefix);
// Some connectors like blackhole, accumulo and raptor don't return views in listTables
// Materialized views are consistently returned in listTables by the relevant connectors
names = union(listTables(session, metadata, accessControl, prefix), views.keySet());
} catch (TrinoException e) {
// listTables throws an exception if cannot connect the database
LOG.warn(e, "Failed to get tables for catalog: %s", catalog);
}
for (SchemaTableName name : names) {
Optional<String> comment = Optional.empty();
try {
comment = getComment(session, prefix, name, views, materializedViews);
} catch (RuntimeException e) {
// getTableHandle may throw an exception (e.g. Cassandra connector doesn't allow case insensitive column names)
LOG.warn(e, "Failed to get metadata for table: %s", name);
}
table.addRow(prefix.getCatalogName(), name.getSchemaName(), name.getTableName(), comment.orElse(null));
}
}
return table.build().cursor();
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class MetadataManager method getViews.
@Override
public Map<QualifiedObjectName, ViewInfo> getViews(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Map<QualifiedObjectName, ViewInfo> views = new LinkedHashMap<>();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, 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, new ViewInfo(entry.getValue()));
}
}
}
return ImmutableMap.copyOf(views);
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class MetadataManager method getMaterializedViews.
@Override
public Map<QualifiedObjectName, ViewInfo> getMaterializedViews(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Map<QualifiedObjectName, ViewInfo> views = new LinkedHashMap<>();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
Map<SchemaTableName, ConnectorMaterializedViewDefinition> materializedViewMap;
if (tablePrefix.getTable().isPresent()) {
materializedViewMap = metadata.getMaterializedView(connectorSession, tablePrefix.toSchemaTableName()).map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view)).orElse(ImmutableMap.of());
} else {
materializedViewMap = metadata.getMaterializedViews(connectorSession, tablePrefix.getSchema());
}
for (Entry<SchemaTableName, ConnectorMaterializedViewDefinition> entry : materializedViewMap.entrySet()) {
QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
views.put(viewName, new ViewInfo(entry.getValue()));
}
}
}
return ImmutableMap.copyOf(views);
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class InputExtractor method createInput.
private Input createInput(Session session, TableHandle table, Set<Column> columns, PlanFragmentId fragmentId, PlanNodeId planNodeId) {
SchemaTableName schemaTable = metadata.getTableSchema(session, table).getTable();
Optional<Object> inputMetadata = metadata.getInfo(session, table);
return new Input(table.getCatalogName().getCatalogName(), schemaTable.getSchemaName(), schemaTable.getTableName(), inputMetadata, ImmutableList.copyOf(columns), fragmentId, planNodeId);
}
use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.
the class ExampleMetadata method listTableColumns.
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
for (SchemaTableName tableName : listTables(session, prefix)) {
ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
// table can disappear during listing operation
if (tableMetadata != null) {
columns.put(tableName, tableMetadata.getColumns());
}
}
return columns.buildOrThrow();
}
Aggregations