use of io.trino.metadata.ViewInfo in project trino by trinodb.
the class TableCommentSystemTable method getComment.
private Optional<String> getComment(Session session, QualifiedTablePrefix prefix, SchemaTableName name, Map<SchemaTableName, ViewInfo> views, Map<SchemaTableName, ViewInfo> materializedViews) {
ViewInfo materializedViewDefinition = materializedViews.get(name);
if (materializedViewDefinition != null) {
return materializedViewDefinition.getComment();
}
ViewInfo viewInfo = views.get(name);
if (viewInfo != null) {
return viewInfo.getComment();
}
QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), name.getSchemaName(), name.getTableName());
return metadata.getRedirectionAwareTableHandle(session, tableName).getTableHandle().map(handle -> metadata.getTableMetadata(session, handle)).map(metadata -> metadata.getMetadata().getComment()).orElseGet(() -> {
// A previously listed table might have been dropped concurrently
LOG.warn("Failed to get metadata for table: %s", name);
return Optional.empty();
});
}
use of io.trino.metadata.ViewInfo 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();
}
Aggregations