use of io.trino.connector.CatalogName in project trino by trinodb.
the class TransactionsSystemTable method createStringsBlock.
private static Block createStringsBlock(List<CatalogName> values) {
VarcharType varchar = createUnboundedVarcharType();
BlockBuilder builder = varchar.createBlockBuilder(null, values.size());
for (CatalogName value : values) {
if (value == null) {
builder.appendNull();
} else {
varchar.writeString(builder, value.getCatalogName());
}
}
return builder.build();
}
use of io.trino.connector.CatalogName 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.connector.CatalogName 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.connector.CatalogName 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.connector.CatalogName 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);
}
Aggregations