use of io.trino.Session 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.Session in project trino by trinodb.
the class CatalogJdbcTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Session session = ((FullConnectorSession) connectorSession).getSession();
Builder table = InMemoryRecordSet.builder(METADATA);
for (String name : listCatalogs(session, metadata, accessControl).keySet()) {
table.addRow(name);
}
return table.build().cursor();
}
use of io.trino.Session in project trino by trinodb.
the class CatalogSystemTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
Session session = ((FullConnectorSession) connectorSession).getSession();
Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
for (Map.Entry<String, Catalog> entry : getCatalogs(session, metadata, accessControl).entrySet()) {
table.addRow(entry.getKey(), entry.getValue().getConnectorCatalogName().toString(), entry.getValue().getConnectorName());
}
return table.build().cursor();
}
use of io.trino.Session in project trino by trinodb.
the class MetadataManager method schemaExists.
@Override
public boolean schemaExists(Session session, CatalogSchemaName schema) {
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, schema.getCatalogName());
if (catalog.isEmpty()) {
return false;
}
CatalogMetadata catalogMetadata = catalog.get();
ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getCatalogName());
return catalogMetadata.listConnectorIds().stream().map(catalogName -> catalogMetadata.getMetadataFor(session, catalogName)).anyMatch(metadata -> metadata.schemaExists(connectorSession, schema.getSchemaName()));
}
use of io.trino.Session in project trino by trinodb.
the class MetadataManager method listRoles.
@Override
public Set<String> listRoles(Session session, Optional<String> catalog) {
if (catalog.isPresent()) {
Optional<CatalogMetadata> catalogMetadata = getOptionalCatalogMetadata(session, catalog.get());
if (catalogMetadata.isEmpty()) {
return ImmutableSet.of();
}
// instead of returning nothing, so information schema role tables will work properly
if (catalogMetadata.get().getSecurityManagement() == SecurityManagement.CONNECTOR) {
CatalogName catalogName = catalogMetadata.get().getCatalogName();
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
ConnectorMetadata metadata = catalogMetadata.get().getMetadataFor(session, catalogName);
return metadata.listRoles(connectorSession).stream().map(role -> role.toLowerCase(ENGLISH)).collect(toImmutableSet());
}
}
return systemSecurityMetadata.listRoles(session);
}
Aggregations