Search in sources :

Example 16 with RecordSet

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

the class RedisRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<? extends ColumnHandle> columns) {
    RedisSplit redisSplit = (RedisSplit) split;
    List<RedisColumnHandle> redisColumns = columns.stream().map(RedisColumnHandle.class::cast).collect(toImmutableList());
    RowDecoder keyDecoder = decoderFactory.create(redisSplit.getKeyDataFormat(), emptyMap(), redisColumns.stream().filter(col -> !col.isInternal()).filter(RedisColumnHandle::isKeyDecoder).collect(toImmutableSet()));
    RowDecoder valueDecoder = decoderFactory.create(redisSplit.getValueDataFormat(), emptyMap(), redisColumns.stream().filter(col -> !col.isInternal()).filter(col -> !col.isKeyDecoder()).collect(toImmutableSet()));
    return new RedisRecordSet(redisSplit, jedisManager, redisColumns, keyDecoder, valueDecoder);
}
Also used : ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) Collections.emptyMap(java.util.Collections.emptyMap) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConnectorSession(io.trino.spi.connector.ConnectorSession) Inject(javax.inject.Inject) List(java.util.List) RowDecoder(io.trino.decoder.RowDecoder) DispatchingRowDecoderFactory(io.trino.decoder.DispatchingRowDecoderFactory) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) RecordSet(io.trino.spi.connector.RecordSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) RowDecoder(io.trino.decoder.RowDecoder)

Example 17 with RecordSet

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

the class ThriftIndexedTpchService method createLookupPageSource.

@Override
protected ConnectorPageSource createLookupPageSource(SplitInfo splitInfo, List<String> outputColumnNames) {
    IndexedTable indexedTable = indexedData.getIndexedTable(splitInfo.getTableName(), schemaNameToScaleFactor(splitInfo.getSchemaName()), ImmutableSet.copyOf(splitInfo.getLookupColumnNames())).orElseThrow(() -> new IllegalArgumentException(format("No such index: %s%s", splitInfo.getTableName(), splitInfo.getLookupColumnNames())));
    List<Type> lookupColumnTypes = types(splitInfo.getTableName(), splitInfo.getLookupColumnNames());
    RecordSet keyRecordSet = new ListBasedRecordSet(splitInfo.getKeys(), lookupColumnTypes);
    RecordSet outputRecordSet = lookupIndexKeys(keyRecordSet, indexedTable, outputColumnNames, splitInfo.getLookupColumnNames());
    return new RecordPageSource(outputRecordSet);
}
Also used : Type(io.trino.spi.type.Type) RecordSet(io.trino.spi.connector.RecordSet) MappedRecordSet(io.trino.split.MappedRecordSet) IndexedTable(io.trino.testing.tpch.TpchIndexedData.IndexedTable) RecordPageSource(io.trino.spi.connector.RecordPageSource)

Example 18 with RecordSet

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

the class ThriftIndexedTpchService method lookupIndexKeys.

/**
 * Get lookup result and re-map output columns based on requested order.
 */
private static RecordSet lookupIndexKeys(RecordSet keys, IndexedTable table, List<String> outputColumnNames, List<String> lookupColumnNames) {
    RecordSet allColumnsOutputRecordSet = table.lookupKeys(new MappedRecordSet(keys, computeRemap(lookupColumnNames, table.getKeyColumns())));
    List<Integer> outputRemap = computeRemap(table.getOutputColumns(), outputColumnNames);
    return new MappedRecordSet(allColumnsOutputRecordSet, outputRemap);
}
Also used : MappedRecordSet(io.trino.split.MappedRecordSet) RecordSet(io.trino.spi.connector.RecordSet) MappedRecordSet(io.trino.split.MappedRecordSet)

Example 19 with RecordSet

use of io.trino.spi.connector.RecordSet 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)

Example 20 with RecordSet

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

the class TpchIndexedData method indexTable.

private static IndexedTable indexTable(RecordSet recordSet, List<String> outputColumns, List<String> keyColumns) {
    List<Integer> keyPositions = keyColumns.stream().map(columnName -> {
        int position = outputColumns.indexOf(columnName);
        checkState(position != -1);
        return position;
    }).collect(toImmutableList());
    ImmutableListMultimap.Builder<MaterializedTuple, MaterializedTuple> indexedValuesBuilder = ImmutableListMultimap.builder();
    List<Type> outputTypes = recordSet.getColumnTypes();
    List<Type> keyTypes = extractPositionValues(outputTypes, keyPositions);
    RecordCursor cursor = recordSet.cursor();
    while (cursor.advanceNextPosition()) {
        List<Object> values = extractValues(cursor, outputTypes);
        List<Object> keyValues = extractPositionValues(values, keyPositions);
        indexedValuesBuilder.put(new MaterializedTuple(keyValues), new MaterializedTuple(values));
    }
    return new IndexedTable(keyColumns, keyTypes, outputColumns, outputTypes, indexedValuesBuilder.build());
}
Also used : Iterables(com.google.common.collect.Iterables) Slice(io.airlift.slice.Slice) ListMultimap(com.google.common.collect.ListMultimap) TpchRecordSetProvider(io.trino.plugin.tpch.TpchRecordSetProvider) Type(io.trino.spi.type.Type) DecimalTypeMapping(io.trino.plugin.tpch.DecimalTypeMapping) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Preconditions.checkPositionIndex(com.google.common.base.Preconditions.checkPositionIndex) TpchTable(io.trino.tpch.TpchTable) RecordCursor(io.trino.spi.connector.RecordCursor) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) AbstractIterator(com.google.common.collect.AbstractIterator) Set(java.util.Set) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) RecordSet(io.trino.spi.connector.RecordSet) Optional(java.util.Optional) TpchMetadata(io.trino.plugin.tpch.TpchMetadata) Type(io.trino.spi.type.Type) RecordCursor(io.trino.spi.connector.RecordCursor) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap)

Aggregations

RecordSet (io.trino.spi.connector.RecordSet)25 Test (org.testng.annotations.Test)14 RecordCursor (io.trino.spi.connector.RecordCursor)12 LinkedHashMap (java.util.LinkedHashMap)8 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)6 List (java.util.List)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ColumnHandle (io.trino.spi.connector.ColumnHandle)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)4 ConnectorSession (io.trino.spi.connector.ConnectorSession)4 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)4 ArrayList (java.util.ArrayList)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 DispatchingRowDecoderFactory (io.trino.decoder.DispatchingRowDecoderFactory)3 RowDecoder (io.trino.decoder.RowDecoder)3 ConnectorRecordSetProvider (io.trino.spi.connector.ConnectorRecordSetProvider)3