Search in sources :

Example 1 with ConnectorIndexHandle

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

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 : TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) Function(java.util.function.Function) ConnectorIndexProvider(io.trino.spi.connector.ConnectorIndexProvider) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) 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) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) RecordSet(io.trino.spi.connector.RecordSet) Optional(java.util.Optional) ConnectorIndexHandle(io.trino.spi.connector.ConnectorIndexHandle) ConnectorIndex(io.trino.spi.connector.ConnectorIndex) MappedRecordSet(io.trino.split.MappedRecordSet) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArrayList(java.util.ArrayList) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) MappedRecordSet(io.trino.split.MappedRecordSet) RecordSet(io.trino.spi.connector.RecordSet) MappedRecordSet(io.trino.split.MappedRecordSet)

Aggregations

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 TpchColumnHandle (io.trino.plugin.tpch.TpchColumnHandle)1 ColumnHandle (io.trino.spi.connector.ColumnHandle)1 ConnectorIndex (io.trino.spi.connector.ConnectorIndex)1 ConnectorIndexHandle (io.trino.spi.connector.ConnectorIndexHandle)1 ConnectorIndexProvider (io.trino.spi.connector.ConnectorIndexProvider)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)1 RecordSet (io.trino.spi.connector.RecordSet)1 NullableValue (io.trino.spi.predicate.NullableValue)1 TupleDomain (io.trino.spi.predicate.TupleDomain)1 Type (io.trino.spi.type.Type)1 MappedRecordSet (io.trino.split.MappedRecordSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1