Search in sources :

Example 1 with TpchTableHandle

use of com.facebook.presto.tpch.TpchTableHandle 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) 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) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) 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) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle)

Example 2 with TpchTableHandle

use of com.facebook.presto.tpch.TpchTableHandle in project presto by prestodb.

the class H2QueryRunner method insertRows.

private void insertRows(TpchMetadata tpchMetadata, TpchTable tpchTable) {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(null, new SchemaTableName(TINY_SCHEMA_NAME, tpchTable.getTableName()));
    insertRows(tpchMetadata.getTableMetadata(null, tableHandle), handle, createTpchRecordSet(tpchTable, tableHandle.getScaleFactor()));
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle)

Aggregations

TpchTableHandle (com.facebook.presto.tpch.TpchTableHandle)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorResolvedIndex (com.facebook.presto.spi.ConnectorResolvedIndex)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 NullableValue (com.facebook.presto.spi.predicate.NullableValue)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1 TpchIndexProvider.handleToNames (com.facebook.presto.tests.tpch.TpchIndexProvider.handleToNames)1 TpchMetadata (com.facebook.presto.tpch.TpchMetadata)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 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Set (java.util.Set)1