Search in sources :

Example 91 with ConnectorSession

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

the class InformationSchemaMetadata method calculatePrefixesWithSchemaName.

private Set<QualifiedTablePrefix> calculatePrefixesWithSchemaName(ConnectorSession connectorSession, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
    Optional<Set<String>> schemas = filterString(constraint, SCHEMA_COLUMN_HANDLE);
    if (schemas.isPresent()) {
        return schemas.get().stream().filter(this::isLowerCase).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
    }
    Session session = ((FullConnectorSession) connectorSession).getSession();
    return metadata.listSchemaNames(session, catalogName).stream().filter(schema -> !predicate.isPresent() || predicate.get().test(schemaAsFixedValues(schema))).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) Slice(io.airlift.slice.Slice) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) FullConnectorSession(com.facebook.presto.FullConnectorSession) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ImmutableSet(com.google.common.collect.ImmutableSet) NullableValue(com.facebook.presto.common.predicate.NullableValue) QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Session(com.facebook.presto.Session) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Predicates.compose(com.google.common.base.Predicates.compose) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) MetadataUtil.findColumnMetadata(com.facebook.presto.metadata.MetadataUtil.findColumnMetadata) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Stream(java.util.stream.Stream) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) SchemaMetadataBuilder.schemaMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Metadata(com.facebook.presto.metadata.Metadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) FullConnectorSession(com.facebook.presto.FullConnectorSession) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FullConnectorSession(com.facebook.presto.FullConnectorSession)

Example 92 with ConnectorSession

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

the class InformationSchemaMetadata method calculatePrefixesWithTableName.

public Set<QualifiedTablePrefix> calculatePrefixesWithTableName(ConnectorSession connectorSession, Set<QualifiedTablePrefix> prefixes, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    Optional<Set<String>> tables = filterString(constraint, TABLE_NAME_COLUMN_HANDLE);
    if (tables.isPresent()) {
        return prefixes.stream().flatMap(prefix -> tables.get().stream().filter(this::isLowerCase).map(table -> table.toLowerCase(ENGLISH)).map(table -> new QualifiedObjectName(catalogName, prefix.getSchemaName().get(), table))).filter(objectName -> metadata.getTableHandle(session, objectName).isPresent() || metadata.getView(session, objectName).isPresent()).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
    }
    return prefixes.stream().flatMap(prefix -> Stream.concat(metadata.listTables(session, prefix).stream(), metadata.listViews(session, prefix).stream())).filter(objectName -> !predicate.isPresent() || predicate.get().test(asFixedValues(objectName))).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) Slice(io.airlift.slice.Slice) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) FullConnectorSession(com.facebook.presto.FullConnectorSession) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ImmutableSet(com.google.common.collect.ImmutableSet) NullableValue(com.facebook.presto.common.predicate.NullableValue) QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Session(com.facebook.presto.Session) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Predicates.compose(com.google.common.base.Predicates.compose) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) MetadataUtil.findColumnMetadata(com.facebook.presto.metadata.MetadataUtil.findColumnMetadata) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Stream(java.util.stream.Stream) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) SchemaMetadataBuilder.schemaMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Metadata(com.facebook.presto.metadata.Metadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) FullConnectorSession(com.facebook.presto.FullConnectorSession) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FullConnectorSession(com.facebook.presto.FullConnectorSession)

Example 93 with ConnectorSession

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

the class ColumnJdbcTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = toSession(transactionHandle, connectorSession);
    Optional<String> catalogFilter = stringFilter(constraint, 0);
    Optional<String> schemaFilter = stringFilter(constraint, 1);
    Optional<String> tableFilter = stringFilter(constraint, 2);
    Builder table = InMemoryRecordSet.builder(METADATA);
    for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
        QualifiedTablePrefix prefix = FilterUtil.tablePrefix(catalog, schemaFilter, tableFilter);
        for (Entry<SchemaTableName, List<ColumnMetadata>> entry : listTableColumns(session, metadata, accessControl, prefix).entrySet()) {
            addColumnRows(table, catalog, entry.getKey(), entry.getValue());
        }
    }
    return table.build().cursor();
}
Also used : QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) SystemConnectorSessionUtil.toSession(com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession)

Example 94 with ConnectorSession

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

the class SystemSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingContext splitSchedulingContext) {
    SystemTableLayoutHandle layoutHandle = (SystemTableLayoutHandle) layout;
    SystemTableHandle tableHandle = layoutHandle.getTable();
    TupleDomain<ColumnHandle> constraint = layoutHandle.getConstraint();
    SystemTable systemTable = tables.getSystemTable(session, tableHandle.getSchemaTableName()).orElseThrow(() -> new PrestoException(NOT_FOUND, format("Table %s not found", tableHandle.getSchemaTableName())));
    Distribution tableDistributionMode = systemTable.getDistribution();
    if (tableDistributionMode == SINGLE_COORDINATOR) {
        HostAddress address = nodeManager.getCurrentNode().getHostAndPort();
        ConnectorSplit split = new SystemSplit(tableHandle.getConnectorId(), tableHandle, address, constraint);
        return new FixedSplitSource(ImmutableList.of(split));
    }
    ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder();
    ImmutableSet.Builder<InternalNode> nodes = ImmutableSet.builder();
    if (tableDistributionMode == ALL_COORDINATORS) {
        nodes.addAll(nodeManager.getCoordinators());
    } else if (tableDistributionMode == ALL_NODES) {
        nodes.addAll(nodeManager.getNodes(ACTIVE).stream().filter(node -> !node.isResourceManager()).collect(toImmutableSet()));
    }
    Set<InternalNode> nodeSet = nodes.build();
    for (InternalNode node : nodeSet) {
        splits.add(new SystemSplit(tableHandle.getConnectorId(), tableHandle, node.getHostAndPort(), constraint));
    }
    return new FixedSplitSource(splits.build());
}
Also used : ALL_COORDINATORS(com.facebook.presto.spi.SystemTable.Distribution.ALL_COORDINATORS) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) SINGLE_COORDINATOR(com.facebook.presto.spi.SystemTable.Distribution.SINGLE_COORDINATOR) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SystemTable(com.facebook.presto.spi.SystemTable) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ImmutableSet(com.google.common.collect.ImmutableSet) ALL_NODES(com.facebook.presto.spi.SystemTable.Distribution.ALL_NODES) HostAddress(com.facebook.presto.spi.HostAddress) Set(java.util.Set) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Distribution(com.facebook.presto.spi.SystemTable.Distribution) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) HostAddress(com.facebook.presto.spi.HostAddress) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Distribution(com.facebook.presto.spi.SystemTable.Distribution) SystemTable(com.facebook.presto.spi.SystemTable) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 95 with ConnectorSession

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

the class CatalogSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = toSession(transactionHandle, connectorSession);
    Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
    for (Map.Entry<String, ConnectorId> entry : listCatalogs(session, metadata, accessControl).entrySet()) {
        table.addRow(entry.getKey(), entry.getValue().toString());
    }
    return table.build().cursor();
}
Also used : TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) Map(java.util.Map) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) SystemConnectorSessionUtil.toSession(com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession) ConnectorId(com.facebook.presto.spi.ConnectorId)

Aggregations

ConnectorSession (com.facebook.presto.spi.ConnectorSession)190 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)94 ColumnHandle (com.facebook.presto.spi.ColumnHandle)92 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)80 List (java.util.List)80 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)78 SchemaTableName (com.facebook.presto.spi.SchemaTableName)75 Optional (java.util.Optional)74 ImmutableList (com.google.common.collect.ImmutableList)73 Objects.requireNonNull (java.util.Objects.requireNonNull)73 Map (java.util.Map)64 PrestoException (com.facebook.presto.spi.PrestoException)63 ImmutableMap (com.google.common.collect.ImmutableMap)63 Test (org.testng.annotations.Test)63 Path (org.apache.hadoop.fs.Path)62 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)54 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