Search in sources :

Example 26 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method listViews.

@Override
public List<QualifiedObjectName> listViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Set<QualifiedObjectName> views = new LinkedHashSet<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
            ConnectorSession connectorSession = session.toConnectorSession(connectorId);
            metadata.listViews(connectorSession, prefix.getSchemaName()).stream().map(convertFromSchemaTableName(prefix.getCatalogName())).filter(prefix::matches).forEach(views::add);
        }
    }
    return ImmutableList.copyOf(views);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 27 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method listRoles.

@Override
public Set<String> listRoles(Session session, String catalog) {
    Optional<CatalogMetadata> catalogMetadata = getOptionalCatalogMetadata(session, catalog);
    if (!catalogMetadata.isPresent()) {
        return ImmutableSet.of();
    }
    ConnectorId connectorId = catalogMetadata.get().getConnectorId();
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    ConnectorMetadata metadata = catalogMetadata.get().getMetadataFor(connectorId);
    return metadata.listRoles(connectorSession).stream().map(role -> role.toLowerCase(ENGLISH)).collect(toImmutableSet());
}
Also used : NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal) ComputedStatistics(com.facebook.presto.spi.statistics.ComputedStatistics) JsonCodecFactory(com.facebook.airlift.json.JsonCodecFactory) TypeSignature(com.facebook.presto.common.type.TypeSignature) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) SystemTable(com.facebook.presto.spi.SystemTable) ENGLISH(java.util.Locale.ENGLISH) HASH_CODE(com.facebook.presto.common.function.OperatorType.HASH_CODE) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TableStatisticsMetadata(com.facebook.presto.spi.statistics.TableStatisticsMetadata) Joiner(com.google.common.base.Joiner) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) Slice(io.airlift.slice.Slice) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OptionalLong(java.util.OptionalLong) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) TableHandle(com.facebook.presto.spi.TableHandle) SqlFunction(com.facebook.presto.spi.function.SqlFunction) TransactionManager(com.facebook.presto.transaction.TransactionManager) LinkedHashSet(java.util.LinkedHashSet) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorMetadataUpdateHandle(com.facebook.presto.spi.ConnectorMetadataUpdateHandle) SystemSessionProperties.isIgnoreStatsCalculatorFailures(com.facebook.presto.SystemSessionProperties.isIgnoreStatsCalculatorFailures) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) Session(com.facebook.presto.Session) Constraint(com.facebook.presto.spi.Constraint) OperatorType(com.facebook.presto.common.function.OperatorType) GREATER_THAN(com.facebook.presto.common.function.OperatorType.GREATER_THAN) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) INVALID_VIEW(com.facebook.presto.spi.StandardErrorCode.INVALID_VIEW) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) BETWEEN(com.facebook.presto.common.function.OperatorType.BETWEEN) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) QueryId(com.facebook.presto.spi.QueryId) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) TableLayoutFilterCoverage(com.facebook.presto.spi.TableLayoutFilterCoverage) TableLayout.fromConnectorLayout(com.facebook.presto.metadata.TableLayout.fromConnectorLayout) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ConnectorCapabilities(com.facebook.presto.spi.connector.ConnectorCapabilities) JsonCodec(com.facebook.airlift.json.JsonCodec) TableStatistics(com.facebook.presto.spi.statistics.TableStatistics) Privilege(com.facebook.presto.spi.security.Privilege) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HashMultimap(com.google.common.collect.HashMultimap) Locale(java.util.Locale) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) LESS_THAN(com.facebook.presto.common.function.OperatorType.LESS_THAN) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) GET_LAYOUT_TIME_NANOS(com.facebook.presto.common.RuntimeMetricName.GET_LAYOUT_TIME_NANOS) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) String.format(java.lang.String.format) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) RoleGrant(com.facebook.presto.spi.security.RoleGrant) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) Entry(java.util.Map.Entry) TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) NOT_EQUAL(com.facebook.presto.common.function.OperatorType.NOT_EQUAL) Logger(com.facebook.airlift.log.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) HashMap(java.util.HashMap) QueryManager(com.facebook.presto.execution.QueryManager) PrestoException(com.facebook.presto.spi.PrestoException) Multimap(com.google.common.collect.Multimap) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) LESS_THAN_OR_EQUAL(com.facebook.presto.common.function.OperatorType.LESS_THAN_OR_EQUAL) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Type(com.facebook.presto.common.type.Type) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) GrantInfo(com.facebook.presto.spi.security.GrantInfo) NOT_APPLICABLE(com.facebook.presto.spi.TableLayoutFilterCoverage.NOT_APPLICABLE) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) Constraint.alwaysTrue(com.facebook.presto.spi.Constraint.alwaysTrue) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) GREATER_THAN_OR_EQUAL(com.facebook.presto.common.function.OperatorType.GREATER_THAN_OR_EQUAL) MoreFutures.toListenableFuture(com.facebook.airlift.concurrent.MoreFutures.toListenableFuture) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) SYNTAX_ERROR(com.facebook.presto.spi.StandardErrorCode.SYNTAX_ERROR) ConnectorPartitioningMetadata(com.facebook.presto.spi.connector.ConnectorPartitioningMetadata) CatalogSchemaName(com.facebook.presto.common.CatalogSchemaName) MaterializedViewStatus(com.facebook.presto.spi.MaterializedViewStatus) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 28 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method getViews.

@Override
public Map<QualifiedObjectName, ViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
    Map<QualifiedObjectName, ViewDefinition> views = new LinkedHashMap<>();
    if (catalog.isPresent()) {
        CatalogMetadata catalogMetadata = catalog.get();
        SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
        for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
            ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
            ConnectorSession connectorSession = session.toConnectorSession(connectorId);
            for (Entry<SchemaTableName, ConnectorViewDefinition> entry : metadata.getViews(connectorSession, tablePrefix).entrySet()) {
                QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
                views.put(viewName, deserializeView(entry.getValue().getViewData()));
            }
        }
    }
    return ImmutableMap.copyOf(views);
}
Also used : ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) SchemaTableName(com.facebook.presto.spi.SchemaTableName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) LinkedHashMap(java.util.LinkedHashMap) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 29 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method schemaExists.

@Override
public boolean schemaExists(Session session, CatalogSchemaName schema) {
    Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, schema.getCatalogName());
    if (!catalog.isPresent()) {
        return false;
    }
    CatalogMetadata catalogMetadata = catalog.get();
    ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getConnectorId());
    return catalogMetadata.listConnectorIds().stream().map(catalogMetadata::getMetadataFor).anyMatch(metadata -> metadata.schemaExists(connectorSession, schema.getSchemaName()));
}
Also used : ConnectorSession(com.facebook.presto.spi.ConnectorSession)

Example 30 with ConnectorSession

use of com.facebook.presto.spi.ConnectorSession in project presto by prestodb.

the class MetadataManager method getPreferredShuffleLayoutForNewTable.

@Override
public Optional<NewTableLayout> getPreferredShuffleLayoutForNewTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata) {
    CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);
    ConnectorId connectorId = catalogMetadata.getConnectorId();
    ConnectorMetadata metadata = catalogMetadata.getMetadata();
    ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(connectorId);
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    return metadata.getPreferredShuffleLayoutForNewTable(connectorSession, tableMetadata).map(layout -> new NewTableLayout(connectorId, transactionHandle, layout));
}
Also used : ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Aggregations

ConnectorSession (com.facebook.presto.spi.ConnectorSession)189 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)94 ColumnHandle (com.facebook.presto.spi.ColumnHandle)91 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)80 List (java.util.List)79 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)78 SchemaTableName (com.facebook.presto.spi.SchemaTableName)74 Optional (java.util.Optional)73 ImmutableList (com.google.common.collect.ImmutableList)72 Objects.requireNonNull (java.util.Objects.requireNonNull)72 PrestoException (com.facebook.presto.spi.PrestoException)63 ImmutableMap (com.google.common.collect.ImmutableMap)63 Map (java.util.Map)63 Test (org.testng.annotations.Test)63 Path (org.apache.hadoop.fs.Path)61 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)53 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)53 Constraint (com.facebook.presto.spi.Constraint)51 Slice (io.airlift.slice.Slice)51 Type (com.facebook.presto.common.type.Type)50