use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.
the class MetadataManager method getRedirectedTableName.
private QualifiedObjectName getRedirectedTableName(Session session, QualifiedObjectName originalTableName) {
requireNonNull(session, "session is null");
requireNonNull(originalTableName, "originalTableName is null");
if (originalTableName.getCatalogName().isEmpty() || originalTableName.getSchemaName().isEmpty() || originalTableName.getObjectName().isEmpty()) {
// table cannot exist
return originalTableName;
}
QualifiedObjectName tableName = originalTableName;
Set<QualifiedObjectName> visitedTableNames = new LinkedHashSet<>();
visitedTableNames.add(tableName);
for (int count = 0; count < MAX_TABLE_REDIRECTIONS; count++) {
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, tableName.getCatalogName());
if (catalog.isEmpty()) {
// Stop redirection
return tableName;
}
CatalogMetadata catalogMetadata = catalog.get();
CatalogName catalogName = catalogMetadata.getConnectorId(session, tableName);
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
Optional<QualifiedObjectName> redirectedTableName = metadata.redirectTable(session.toConnectorSession(catalogName), tableName.asSchemaTableName()).map(name -> convertFromSchemaTableName(name.getCatalogName()).apply(name.getSchemaTableName()));
if (redirectedTableName.isEmpty()) {
return tableName;
}
tableName = redirectedTableName.get();
// Check for loop in redirection
if (!visitedTableNames.add(tableName)) {
throw new TrinoException(TABLE_REDIRECTION_ERROR, format("Table redirections form a loop: %s", Streams.concat(visitedTableNames.stream(), Stream.of(tableName)).map(QualifiedObjectName::toString).collect(Collectors.joining(" -> "))));
}
}
throw new TrinoException(TABLE_REDIRECTION_ERROR, format("Table redirected too many times (%d): %s", MAX_TABLE_REDIRECTIONS, visitedTableNames));
}
use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.
the class MetadataManager method getColumnHandles.
@Override
public Map<String, ColumnHandle> getColumnHandles(Session session, TableHandle tableHandle) {
CatalogName catalogName = tableHandle.getCatalogName();
ConnectorMetadata metadata = getMetadata(session, catalogName);
Map<String, ColumnHandle> handles = metadata.getColumnHandles(session.toConnectorSession(catalogName), tableHandle.getConnectorHandle());
ImmutableMap.Builder<String, ColumnHandle> map = ImmutableMap.builder();
for (Entry<String, ColumnHandle> mapEntry : handles.entrySet()) {
map.put(mapEntry.getKey().toLowerCase(ENGLISH), mapEntry.getValue());
}
return map.buildOrThrow();
}
use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.
the class MetadataManager method denySchemaPrivileges.
@Override
public void denySchemaPrivileges(Session session, CatalogSchemaName schemaName, Set<Privilege> privileges, TrinoPrincipal grantee) {
CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, schemaName.getCatalogName());
if (catalogMetadata.getSecurityManagement() == SecurityManagement.SYSTEM) {
systemSecurityMetadata.denySchemaPrivileges(session, schemaName, privileges, grantee);
return;
}
CatalogName catalogName = catalogMetadata.getCatalogName();
ConnectorMetadata metadata = catalogMetadata.getMetadata(session);
metadata.denySchemaPrivileges(session.toConnectorSession(catalogName), schemaName.getSchemaName(), privileges, grantee);
}
use of io.trino.spi.connector.ConnectorMetadata in project trino by trinodb.
the class MetadataManager method roleExists.
@Override
public boolean roleExists(Session session, String role, Optional<String> catalog) {
if (catalog.isEmpty()) {
return systemSecurityMetadata.roleExists(session, role);
}
CatalogMetadata catalogMetadata = getCatalogMetadata(session, new CatalogName(catalog.get()));
CatalogName catalogName = catalogMetadata.getCatalogName();
ConnectorMetadata metadata = catalogMetadata.getMetadata(session);
return metadata.roleExists(session.toConnectorSession(catalogName), role);
}
use of io.trino.spi.connector.ConnectorMetadata 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);
}
Aggregations