Search in sources :

Example 1 with ConnectorMetadata

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));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TrinoException(io.trino.spi.TrinoException) CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) Constraint(io.trino.spi.connector.Constraint)

Example 2 with ConnectorMetadata

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();
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with ConnectorMetadata

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);
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 4 with ConnectorMetadata

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);
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 5 with ConnectorMetadata

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);
}
Also used : SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) QualifiedObjectName.convertFromSchemaTableName(io.trino.metadata.QualifiedObjectName.convertFromSchemaTableName) LinkedHashMap(java.util.LinkedHashMap) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Aggregations

ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)190 CatalogName (io.trino.connector.CatalogName)101 ConnectorSession (io.trino.spi.connector.ConnectorSession)97 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)70 Test (org.testng.annotations.Test)63 TestingConnectorSession (io.trino.testing.TestingConnectorSession)52 SchemaTableName (io.trino.spi.connector.SchemaTableName)48 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)43 ColumnHandle (io.trino.spi.connector.ColumnHandle)40 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)32 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)32 ConnectorInsertTableHandle (io.trino.spi.connector.ConnectorInsertTableHandle)31 Constraint (io.trino.spi.connector.Constraint)31 MaterializedResult (io.trino.testing.MaterializedResult)27 HiveColumnHandle.bucketColumnHandle (io.trino.plugin.hive.HiveColumnHandle.bucketColumnHandle)26 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)26 TrinoException (io.trino.spi.TrinoException)23 Slice (io.airlift.slice.Slice)22 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)21 SchemaTablePrefix (io.trino.spi.connector.SchemaTablePrefix)20