Search in sources :

Example 1 with ConnectorResolvedIndex

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

the class TpchIndexMetadata method resolveIndex.

@Override
public Optional<ConnectorResolvedIndex> resolveIndex(ConnectorSession session, ConnectorTableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
    TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle;
    // Keep the fixed values that don't overlap with the indexableColumns
    // Note: technically we could more efficiently utilize the overlapped columns, but this way is simpler for now
    Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of()).entrySet().stream().filter(entry -> !indexableColumns.contains(entry.getKey())).filter(// strip nulls since meaningless in index join lookups
    entry -> !entry.getValue().isNull()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    // determine all columns available for index lookup
    Set<String> lookupColumnNames = ImmutableSet.<String>builder().addAll(handleToNames(ImmutableList.copyOf(indexableColumns))).addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))).build();
    // do we have an index?
    if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) {
        return Optional.empty();
    }
    TupleDomain<ColumnHandle> filteredTupleDomain = tupleDomain;
    if (!tupleDomain.isNone()) {
        filteredTupleDomain = TupleDomain.withColumnDomains(Maps.filterKeys(tupleDomain.getDomains().get(), not(in(fixedValues.keySet()))));
    }
    TpchIndexHandle indexHandle = new TpchIndexHandle(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
    return Optional.of(new ConnectorResolvedIndex(indexHandle, filteredTupleDomain));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) NullableValue(com.facebook.presto.common.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) TpchIndexProvider.handleToNames(com.facebook.presto.tests.tpch.TpchIndexProvider.handleToNames) Set(java.util.Set) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) TpchMetadata(com.facebook.presto.tpch.TpchMetadata) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) Predicates.in(com.google.common.base.Predicates.in) ImmutableList(com.google.common.collect.ImmutableList) Predicates.not(com.google.common.base.Predicates.not) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) NullableValue(com.facebook.presto.common.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle)

Example 2 with ConnectorResolvedIndex

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

the class MetadataManager method resolveIndex.

@Override
public Optional<ResolvedIndex> resolveIndex(Session session, TableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
    ConnectorId connectorId = tableHandle.getConnectorId();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, connectorId);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
    ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(connectorId);
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    Optional<ConnectorResolvedIndex> resolvedIndex = metadata.resolveIndex(connectorSession, tableHandle.getConnectorHandle(), indexableColumns, outputColumns, tupleDomain);
    return resolvedIndex.map(resolved -> new ResolvedIndex(tableHandle.getConnectorId(), transaction, resolved));
}
Also used : ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) 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)

Example 3 with ConnectorResolvedIndex

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

the class ThriftMetadata method resolveIndex.

@Override
public Optional<ConnectorResolvedIndex> resolveIndex(ConnectorSession session, ConnectorTableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
    ThriftTableHandle table = (ThriftTableHandle) tableHandle;
    ThriftTableMetadata tableMetadata = getRequiredTableMetadata(new SchemaTableName(table.getSchemaName(), table.getTableName()));
    if (tableMetadata.containsIndexableColumns(indexableColumns)) {
        return Optional.of(new ConnectorResolvedIndex(new ThriftIndexHandle(tableMetadata.getSchemaTableName(), tupleDomain, session), tupleDomain));
    } else {
        return Optional.empty();
    }
}
Also used : ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PrestoThriftSchemaTableName(com.facebook.presto.thrift.api.connector.PrestoThriftSchemaTableName)

Aggregations

ConnectorResolvedIndex (com.facebook.presto.spi.ConnectorResolvedIndex)3 ConnectorSession (com.facebook.presto.spi.ConnectorSession)2 NullableValue (com.facebook.presto.common.predicate.NullableValue)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorId (com.facebook.presto.spi.ConnectorId)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)1 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)1 TpchIndexProvider.handleToNames (com.facebook.presto.tests.tpch.TpchIndexProvider.handleToNames)1 PrestoThriftSchemaTableName (com.facebook.presto.thrift.api.connector.PrestoThriftSchemaTableName)1 TpchMetadata (com.facebook.presto.tpch.TpchMetadata)1 TpchTableHandle (com.facebook.presto.tpch.TpchTableHandle)1 Predicates.in (com.google.common.base.Predicates.in)1 Predicates.not (com.google.common.base.Predicates.not)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1