Search in sources :

Example 1 with ConnectorIndexHandle

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

the class TpchIndexProvider method getIndex.

@Override
public ConnectorIndex getIndex(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorIndexHandle indexHandle, List<ColumnHandle> lookupSchema, List<ColumnHandle> outputSchema) {
    TpchIndexHandle tpchIndexHandle = (TpchIndexHandle) indexHandle;
    Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tpchIndexHandle.getFixedValues()).get();
    checkArgument(lookupSchema.stream().noneMatch(handle -> fixedValues.keySet().contains(handle)), "Lookup columnHandles are not expected to overlap with the fixed value predicates");
    // Establish an order for the fixedValues
    List<ColumnHandle> fixedValueColumns = ImmutableList.copyOf(fixedValues.keySet());
    // Extract the fixedValues as their raw values and types
    List<Object> rawFixedValues = new ArrayList<>(fixedValueColumns.size());
    List<Type> rawFixedTypes = new ArrayList<>(fixedValueColumns.size());
    for (ColumnHandle fixedValueColumn : fixedValueColumns) {
        rawFixedValues.add(fixedValues.get(fixedValueColumn).getValue());
        rawFixedTypes.add(((TpchColumnHandle) fixedValueColumn).getType());
    }
    // Establish the schema after we append the fixed values to the lookup keys.
    List<ColumnHandle> finalLookupSchema = ImmutableList.<ColumnHandle>builder().addAll(lookupSchema).addAll(fixedValueColumns).build();
    Optional<TpchIndexedData.IndexedTable> indexedTable = indexedData.getIndexedTable(tpchIndexHandle.getTableName(), tpchIndexHandle.getScaleFactor(), tpchIndexHandle.getIndexColumnNames());
    checkState(indexedTable.isPresent());
    TpchIndexedData.IndexedTable table = indexedTable.get();
    // Compute how to map from the final lookup schema to the table index key order
    List<Integer> keyRemap = computeRemap(handleToNames(finalLookupSchema), table.getKeyColumns());
    Function<RecordSet, RecordSet> keyFormatter = key -> new MappedRecordSet(new AppendingRecordSet(key, rawFixedValues, rawFixedTypes), keyRemap);
    // Compute how to map from the output of the indexed data to the expected output schema
    List<Integer> outputRemap = computeRemap(table.getOutputColumns(), handleToNames(outputSchema));
    Function<RecordSet, RecordSet> outputFormatter = output -> new MappedRecordSet(output, outputRemap);
    return new TpchConnectorIndex(keyFormatter, outputFormatter, table);
}
Also used : ConnectorIndexHandle(com.facebook.presto.spi.ConnectorIndexHandle) Function(com.google.common.base.Function) NullableValue(com.facebook.presto.common.predicate.NullableValue) ConnectorIndexProvider(com.facebook.presto.spi.connector.ConnectorIndexProvider) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) RecordSet(com.facebook.presto.spi.RecordSet) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ConnectorIndex(com.facebook.presto.spi.ConnectorIndex) Optional(java.util.Optional) MappedRecordSet(com.facebook.presto.split.MappedRecordSet) Type(com.facebook.presto.common.type.Type) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) ArrayList(java.util.ArrayList) NullableValue(com.facebook.presto.common.predicate.NullableValue) Type(com.facebook.presto.common.type.Type) MappedRecordSet(com.facebook.presto.split.MappedRecordSet) RecordSet(com.facebook.presto.spi.RecordSet) MappedRecordSet(com.facebook.presto.split.MappedRecordSet)

Aggregations

NullableValue (com.facebook.presto.common.predicate.NullableValue)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 Type (com.facebook.presto.common.type.Type)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorIndex (com.facebook.presto.spi.ConnectorIndex)1 ConnectorIndexHandle (com.facebook.presto.spi.ConnectorIndexHandle)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 RecordSet (com.facebook.presto.spi.RecordSet)1 ConnectorIndexProvider (com.facebook.presto.spi.connector.ConnectorIndexProvider)1 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)1 MappedRecordSet (com.facebook.presto.split.MappedRecordSet)1 TpchColumnHandle (com.facebook.presto.tpch.TpchColumnHandle)1 Function (com.google.common.base.Function)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1