Search in sources :

Example 16 with ConnectorSession

use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.

the class MetadataManager method applyDelete.

@Override
public Optional<TableHandle> applyDelete(Session session, TableHandle table) {
    CatalogName catalogName = table.getCatalogName();
    ConnectorMetadata metadata = getMetadata(session, catalogName);
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    return metadata.applyDelete(connectorSession, table.getConnectorHandle()).map(newHandle -> new TableHandle(catalogName, newHandle, table.getTransaction()));
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 17 with ConnectorSession

use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.

the class MetadataManager method listTables.

@Override
public List<QualifiedObjectName> listTables(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<QualifiedObjectName> objectName = prefix.asQualifiedObjectName();
    if (objectName.isPresent()) {
        Optional<Boolean> exists = isExistingRelationForListing(session, objectName.get());
        if (exists.isPresent()) {
            return exists.get() ? ImmutableList.of(objectName.get()) : ImmutableList.of();
        }
    }
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Set<QualifiedObjectName> tables = new LinkedHashSet<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        for (CatalogName catalogName : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
            ConnectorSession connectorSession = session.toConnectorSession(catalogName);
            metadata.listTables(connectorSession, prefix.getSchemaName()).stream().map(convertFromSchemaTableName(prefix.getCatalogName())).filter(prefix::matches).forEach(tables::add);
        }
    }
    return ImmutableList.copyOf(tables);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 18 with ConnectorSession

use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.

the class MetadataManager method applyTableScanRedirect.

@Override
public Optional<TableScanRedirectApplicationResult> applyTableScanRedirect(Session session, TableHandle tableHandle) {
    CatalogName catalogName = tableHandle.getCatalogName();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogName);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    return metadata.applyTableScanRedirect(connectorSession, tableHandle.getConnectorHandle());
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 19 with ConnectorSession

use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.

the class MetadataManager method listApplicableRoles.

@Override
public Set<RoleGrant> listApplicableRoles(Session session, TrinoPrincipal principal, 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 ImmutableSet.copyOf(metadata.listApplicableRoles(connectorSession, principal));
        }
    }
    return systemSecurityMetadata.listApplicableRoles(session, principal);
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 20 with ConnectorSession

use of io.trino.spi.connector.ConnectorSession in project trino by trinodb.

the class MetadataManager method listEnabledRoles.

@Override
public Set<String> listEnabledRoles(Session session, String catalog) {
    Optional<CatalogMetadata> catalogMetadata = getOptionalCatalogMetadata(session, catalog);
    if (catalogMetadata.isEmpty()) {
        return ImmutableSet.of();
    }
    // instead of returning nothing, so information schema role tables will work properly
    if (catalogMetadata.get().getSecurityManagement() == SecurityManagement.SYSTEM) {
        return systemSecurityMetadata.listEnabledRoles(session.getIdentity());
    }
    CatalogName catalogName = catalogMetadata.get().getCatalogName();
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    ConnectorMetadata metadata = catalogMetadata.get().getMetadataFor(session, catalogName);
    return ImmutableSet.copyOf(metadata.listEnabledRoles(connectorSession));
}
Also used : CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Aggregations

ConnectorSession (io.trino.spi.connector.ConnectorSession)252 SchemaTableName (io.trino.spi.connector.SchemaTableName)131 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)122 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)119 List (java.util.List)111 ColumnHandle (io.trino.spi.connector.ColumnHandle)108 Optional (java.util.Optional)107 ImmutableList (com.google.common.collect.ImmutableList)98 Objects.requireNonNull (java.util.Objects.requireNonNull)97 TrinoException (io.trino.spi.TrinoException)94 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)92 Map (java.util.Map)88 TestingConnectorSession (io.trino.testing.TestingConnectorSession)87 ImmutableMap (com.google.common.collect.ImmutableMap)85 TupleDomain (io.trino.spi.predicate.TupleDomain)85 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)83 Test (org.testng.annotations.Test)82 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)80 Constraint (io.trino.spi.connector.Constraint)76 Type (io.trino.spi.type.Type)72