Search in sources :

Example 11 with ConnectorTransactionHandle

use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.

the class RedisRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    RedisSplit redisSplit = convertSplit(split);
    List<RedisColumnHandle> redisColumns = columns.stream().map(RedisHandleResolver::convertColumnHandle).collect(ImmutableList.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 : Collections.emptyMap(java.util.Collections.emptyMap) RowDecoder(com.facebook.presto.decoder.RowDecoder) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) RecordSet(com.facebook.presto.spi.RecordSet) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Inject(javax.inject.Inject) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) List(java.util.List) ConnectorRecordSetProvider(com.facebook.presto.spi.connector.ConnectorRecordSetProvider) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) RedisHandleResolver.convertSplit(com.facebook.presto.redis.RedisHandleResolver.convertSplit) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) DispatchingRowDecoderFactory(com.facebook.presto.decoder.DispatchingRowDecoderFactory) RowDecoder(com.facebook.presto.decoder.RowDecoder)

Example 12 with ConnectorTransactionHandle

use of com.facebook.presto.spi.connector.ConnectorTransactionHandle 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)

Example 13 with ConnectorTransactionHandle

use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.

the class IndexedTpchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(properties);
    TpchIndexedData indexedData = new TpchIndexedData(catalogName, indexSpec);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) {
            return new TpchIndexMetadata(catalogName, indexedData);
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpchRecordSetProvider();
        }

        @Override
        public ConnectorIndexProvider getIndexProvider() {
            return new TpchIndexProvider(indexedData);
        }

        @Override
        public Set<SystemTable> getSystemTables() {
            return ImmutableSet.of(new ExampleSystemTable());
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : Connector(com.facebook.presto.spi.connector.Connector) IsolationLevel(com.facebook.presto.spi.transaction.IsolationLevel) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TpchSplitManager(com.facebook.presto.tpch.TpchSplitManager) NodeManager(com.facebook.presto.spi.NodeManager) TpchNodePartitioningProvider(com.facebook.presto.tpch.TpchNodePartitioningProvider) SystemTable(com.facebook.presto.spi.SystemTable) TpchRecordSetProvider(com.facebook.presto.tpch.TpchRecordSetProvider)

Example 14 with ConnectorTransactionHandle

use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.

the class TpchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(properties);
    ColumnNaming columnNaming = ColumnNaming.valueOf(properties.getOrDefault(TPCH_COLUMN_NAMING_PROPERTY, ColumnNaming.SIMPLIFIED.name()).toUpperCase());
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction) {
            return new TpchMetadata(catalogName, columnNaming, predicatePushdownEnabled, isPartitioningEnabled(properties));
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpchRecordSetProvider();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : NodeManager(com.facebook.presto.spi.NodeManager) Connector(com.facebook.presto.spi.connector.Connector) IsolationLevel(com.facebook.presto.spi.transaction.IsolationLevel) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle)

Example 15 with ConnectorTransactionHandle

use of com.facebook.presto.spi.connector.ConnectorTransactionHandle in project presto by prestodb.

the class TpcdsConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(config);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) {
            return TpcdsTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) {
            return new TpcdsMetadata();
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpcdsSplitManager(nodeManager, splitsPerNode, isWithNoSexism(config));
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpcdsRecordSetProvider();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpcdsNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : NodeManager(com.facebook.presto.spi.NodeManager) Connector(com.facebook.presto.spi.connector.Connector) IsolationLevel(com.facebook.presto.spi.transaction.IsolationLevel) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle)

Aggregations

ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)40 ConnectorSession (com.facebook.presto.spi.ConnectorSession)18 ColumnHandle (com.facebook.presto.spi.ColumnHandle)13 ConnectorId (com.facebook.presto.spi.ConnectorId)12 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)12 List (java.util.List)12 Objects.requireNonNull (java.util.Objects.requireNonNull)12 ImmutableList (com.google.common.collect.ImmutableList)11 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)10 Inject (javax.inject.Inject)9 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)8 Optional (java.util.Optional)8 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)7 SchemaTableName (com.facebook.presto.spi.SchemaTableName)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)6 Type (com.facebook.presto.common.type.Type)6 Map (java.util.Map)5 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)4 NodeManager (com.facebook.presto.spi.NodeManager)4