Search in sources :

Example 1 with ConnectorResolvedIndex

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

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

Example 2 with ConnectorResolvedIndex

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

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(session, 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.trino.spi.connector.ConnectorResolvedIndex) ConnectorResolvedIndex(io.trino.spi.connector.ConnectorResolvedIndex) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) CatalogName(io.trino.connector.CatalogName) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata)

Example 3 with ConnectorResolvedIndex

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

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).isEmpty()) {
        return Optional.empty();
    }
    TupleDomain<ColumnHandle> filteredTupleDomain = tupleDomain.filter((column, domain) -> !fixedValues.containsKey(column));
    TpchIndexHandle indexHandle = new TpchIndexHandle(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
    return Optional.of(new ConnectorResolvedIndex(indexHandle, filteredTupleDomain));
}
Also used : ConnectorResolvedIndex(io.trino.spi.connector.ConnectorResolvedIndex) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) NullableValue(io.trino.spi.predicate.NullableValue) Set(java.util.Set) TpchIndexProvider.handleToNames(io.trino.testing.tpch.TpchIndexProvider.handleToNames) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) Collectors(java.util.stream.Collectors) ImmutableList(com.google.common.collect.ImmutableList) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) Optional(java.util.Optional) TpchMetadata(io.trino.plugin.tpch.TpchMetadata) ColumnHandle(io.trino.spi.connector.ColumnHandle) ConnectorResolvedIndex(io.trino.spi.connector.ConnectorResolvedIndex) NullableValue(io.trino.spi.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle)

Aggregations

ConnectorResolvedIndex (io.trino.spi.connector.ConnectorResolvedIndex)3 ConnectorSession (io.trino.spi.connector.ConnectorSession)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 CatalogName (io.trino.connector.CatalogName)1 TrinoThriftSchemaTableName (io.trino.plugin.thrift.api.TrinoThriftSchemaTableName)1 TpchMetadata (io.trino.plugin.tpch.TpchMetadata)1 TpchTableHandle (io.trino.plugin.tpch.TpchTableHandle)1 ColumnHandle (io.trino.spi.connector.ColumnHandle)1 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)1 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)1 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)1 SchemaTableName (io.trino.spi.connector.SchemaTableName)1 NullableValue (io.trino.spi.predicate.NullableValue)1 TupleDomain (io.trino.spi.predicate.TupleDomain)1 TpchIndexProvider.handleToNames (io.trino.testing.tpch.TpchIndexProvider.handleToNames)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1