Search in sources :

Example 6 with FixedSplitSource

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

the class MemorySplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle) {
    MemoryTableLayoutHandle layout = (MemoryTableLayoutHandle) layoutHandle;
    List<HostAddress> hosts = layout.getTable().getHosts();
    ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder();
    for (HostAddress host : hosts) {
        for (int i = 0; i < splitsPerNode; i++) {
            splits.add(new MemorySplit(layout.getTable(), i, splitsPerNode, ImmutableList.of(host)));
        }
    }
    return new FixedSplitSource(splits.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) HostAddress(com.facebook.presto.spi.HostAddress) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 7 with FixedSplitSource

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

the class SystemSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    SystemTableLayoutHandle layoutHandle = (SystemTableLayoutHandle) layout;
    SystemTableHandle tableHandle = layoutHandle.getTable();
    TupleDomain<ColumnHandle> constraint = layoutHandle.getConstraint();
    SystemTable systemTable = tables.get(tableHandle.getSchemaTableName());
    Distribution tableDistributionMode = systemTable.getDistribution();
    if (tableDistributionMode == SINGLE_COORDINATOR) {
        HostAddress address = nodeManager.getCurrentNode().getHostAndPort();
        ConnectorSplit split = new SystemSplit(tableHandle.getConnectorId(), tableHandle, address, constraint);
        return new FixedSplitSource(ImmutableList.of(split));
    }
    ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder();
    ImmutableSet.Builder<Node> nodes = ImmutableSet.builder();
    if (tableDistributionMode == ALL_COORDINATORS) {
        nodes.addAll(nodeManager.getCoordinators());
    } else if (tableDistributionMode == ALL_NODES) {
        nodes.addAll(nodeManager.getNodes(ACTIVE));
    }
    Set<Node> nodeSet = nodes.build();
    for (Node node : nodeSet) {
        splits.add(new SystemSplit(tableHandle.getConnectorId(), tableHandle, node.getHostAndPort(), constraint));
    }
    return new FixedSplitSource(splits.build());
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) Node(com.facebook.presto.spi.Node) HostAddress(com.facebook.presto.spi.HostAddress) ImmutableSet(com.google.common.collect.ImmutableSet) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Distribution(com.facebook.presto.spi.SystemTable.Distribution) SystemTable(com.facebook.presto.spi.SystemTable) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 8 with FixedSplitSource

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

the class KafkaSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    KafkaTableHandle kafkaTableHandle = convertLayout(layout).getTable();
    SimpleConsumer simpleConsumer = consumerManager.getConsumer(selectRandom(nodes));
    TopicMetadataRequest topicMetadataRequest = new TopicMetadataRequest(ImmutableList.of(kafkaTableHandle.getTopicName()));
    TopicMetadataResponse topicMetadataResponse = simpleConsumer.send(topicMetadataRequest);
    ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder();
    for (TopicMetadata metadata : topicMetadataResponse.topicsMetadata()) {
        for (PartitionMetadata part : metadata.partitionsMetadata()) {
            log.debug("Adding Partition %s/%s", metadata.topic(), part.partitionId());
            Broker leader = part.leader();
            if (leader == null) {
                // Leader election going on...
                log.warn("No leader for partition %s/%s found!", metadata.topic(), part.partitionId());
                continue;
            }
            HostAddress partitionLeader = HostAddress.fromParts(leader.host(), leader.port());
            SimpleConsumer leaderConsumer = consumerManager.getConsumer(partitionLeader);
            // Kafka contains a reverse list of "end - start" pairs for the splits
            long[] offsets = findAllOffsets(leaderConsumer, metadata.topic(), part.partitionId());
            for (int i = offsets.length - 1; i > 0; i--) {
                KafkaSplit split = new KafkaSplit(connectorId, metadata.topic(), kafkaTableHandle.getKeyDataFormat(), kafkaTableHandle.getMessageDataFormat(), part.partitionId(), offsets[i], offsets[i - 1], partitionLeader);
                splits.add(split);
            }
        }
    }
    return new FixedSplitSource(splits.build());
}
Also used : Broker(kafka.cluster.Broker) ImmutableList(com.google.common.collect.ImmutableList) TopicMetadataRequest(kafka.javaapi.TopicMetadataRequest) TopicMetadataResponse(kafka.javaapi.TopicMetadataResponse) HostAddress(com.facebook.presto.spi.HostAddress) TopicMetadata(kafka.javaapi.TopicMetadata) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) PartitionMetadata(kafka.javaapi.PartitionMetadata) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) SimpleConsumer(kafka.javaapi.consumer.SimpleConsumer)

Example 9 with FixedSplitSource

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

the class JmxSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    JmxTableLayoutHandle jmxLayout = (JmxTableLayoutHandle) layout;
    JmxTableHandle tableHandle = jmxLayout.getTable();
    TupleDomain<ColumnHandle> predicate = jmxLayout.getConstraint();
    //TODO is there a better way to get the node column?
    Optional<JmxColumnHandle> nodeColumnHandle = tableHandle.getColumnHandles().stream().filter(jmxColumnHandle -> jmxColumnHandle.getColumnName().equals(NODE_COLUMN_NAME)).findFirst();
    checkState(nodeColumnHandle.isPresent(), "Failed to find %s column", NODE_COLUMN_NAME);
    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
        NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
        return predicate.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
    }).map(node -> new JmxSplit(tableHandle, ImmutableList.of(node.getHostAndPort()))).collect(toList());
    return new FixedSplitSource(splits);
}
Also used : ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) NodeManager(com.facebook.presto.spi.NodeManager) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) TupleDomain.fromFixedValues(com.facebook.presto.spi.predicate.TupleDomain.fromFixedValues) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Inject(javax.inject.Inject) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) List(java.util.List) NODE_COLUMN_NAME(com.facebook.presto.connector.jmx.JmxMetadata.NODE_COLUMN_NAME) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ColumnHandle(com.facebook.presto.spi.ColumnHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 10 with FixedSplitSource

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

the class TpchSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    TpchTableHandle tableHandle = ((TpchTableLayoutHandle) layout).getTable();
    Set<Node> nodes = nodeManager.getRequiredWorkerNodes();
    int totalParts = nodes.size() * splitsPerNode;
    int partNumber = 0;
    // Split the data using split and skew by the number of nodes available.
    ImmutableList.Builder<ConnectorSplit> splits = ImmutableList.builder();
    for (Node node : nodes) {
        for (int i = 0; i < splitsPerNode; i++) {
            splits.add(new TpchSplit(tableHandle, partNumber, totalParts, ImmutableList.of(node.getHostAndPort())));
            partNumber++;
        }
    }
    return new FixedSplitSource(splits.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) Node(com.facebook.presto.spi.Node) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Aggregations

FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)11 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)10 ImmutableList (com.google.common.collect.ImmutableList)8 HostAddress (com.facebook.presto.spi.HostAddress)5 ColumnHandle (com.facebook.presto.spi.ColumnHandle)3 Node (com.facebook.presto.spi.Node)3 ArrayList (java.util.ArrayList)3 ConnectorSession (com.facebook.presto.spi.ConnectorSession)2 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)2 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)2 ConnectorSplitManager (com.facebook.presto.spi.connector.ConnectorSplitManager)2 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)2 Domain (com.facebook.presto.spi.predicate.Domain)2 NullableValue (com.facebook.presto.spi.predicate.NullableValue)2 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 AccumuloColumnConstraint (com.facebook.presto.accumulo.model.AccumuloColumnConstraint)1 AccumuloSplit (com.facebook.presto.accumulo.model.AccumuloSplit)1