Search in sources :

Example 1 with ConnectorResolvedIndex

use of io.prestosql.spi.connector.ConnectorResolvedIndex in project hetu-core by openlookeng.

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(io.prestosql.spi.connector.ConnectorResolvedIndex) PrestoThriftSchemaTableName(io.prestosql.plugin.thrift.api.PrestoThriftSchemaTableName) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 2 with ConnectorResolvedIndex

use of io.prestosql.spi.connector.ConnectorResolvedIndex in project hetu-core by openlookeng.

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 : TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) Set(java.util.Set) ConnectorResolvedIndex(io.prestosql.spi.connector.ConnectorResolvedIndex) NullableValue(io.prestosql.spi.predicate.NullableValue) TpchIndexProvider.handleToNames(io.prestosql.tests.tpch.TpchIndexProvider.handleToNames) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Predicates.in(com.google.common.base.Predicates.in) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Predicates.not(com.google.common.base.Predicates.not) TpchMetadata(io.prestosql.plugin.tpch.TpchMetadata) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ConnectorResolvedIndex(io.prestosql.spi.connector.ConnectorResolvedIndex) NullableValue(io.prestosql.spi.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle)

Example 3 with ConnectorResolvedIndex

use of io.prestosql.spi.connector.ConnectorResolvedIndex in project hetu-core by openlookeng.

the class MetadataManager method resolveIndex.

@Override
public Optional<ResolvedIndex> resolveIndex(Session session, TableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
    CatalogName catalogName = tableHandle.getCatalogName();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogName);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
    ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(catalogName);
    ConnectorSession connectorSession = session.toConnectorSession(catalogName);
    Optional<ConnectorResolvedIndex> resolvedIndex = metadata.resolveIndex(connectorSession, tableHandle.getConnectorHandle(), indexableColumns, outputColumns, tupleDomain);
    return resolvedIndex.map(resolved -> new ResolvedIndex(tableHandle.getCatalogName(), transaction, resolved));
}
Also used : ConnectorResolvedIndex(io.prestosql.spi.connector.ConnectorResolvedIndex) ConnectorResolvedIndex(io.prestosql.spi.connector.ConnectorResolvedIndex) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) CatalogName(io.prestosql.spi.connector.CatalogName) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata)

Aggregations

ConnectorResolvedIndex (io.prestosql.spi.connector.ConnectorResolvedIndex)3 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)2 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 PrestoThriftSchemaTableName (io.prestosql.plugin.thrift.api.PrestoThriftSchemaTableName)1 TpchMetadata (io.prestosql.plugin.tpch.TpchMetadata)1 TpchTableHandle (io.prestosql.plugin.tpch.TpchTableHandle)1 CatalogName (io.prestosql.spi.connector.CatalogName)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)1 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)1 ConnectorTransactionHandle (io.prestosql.spi.connector.ConnectorTransactionHandle)1 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)1 NullableValue (io.prestosql.spi.predicate.NullableValue)1 TupleDomain (io.prestosql.spi.predicate.TupleDomain)1 TpchIndexProvider.handleToNames (io.prestosql.tests.tpch.TpchIndexProvider.handleToNames)1