Search in sources :

Example 1 with Distribution

use of com.facebook.presto.spi.SystemTable.Distribution in project presto by prestodb.

the class SystemSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingContext splitSchedulingContext) {
    SystemTableLayoutHandle layoutHandle = (SystemTableLayoutHandle) layout;
    SystemTableHandle tableHandle = layoutHandle.getTable();
    TupleDomain<ColumnHandle> constraint = layoutHandle.getConstraint();
    SystemTable systemTable = tables.getSystemTable(session, tableHandle.getSchemaTableName()).orElseThrow(() -> new PrestoException(NOT_FOUND, format("Table %s not found", 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<InternalNode> nodes = ImmutableSet.builder();
    if (tableDistributionMode == ALL_COORDINATORS) {
        nodes.addAll(nodeManager.getCoordinators());
    } else if (tableDistributionMode == ALL_NODES) {
        nodes.addAll(nodeManager.getNodes(ACTIVE).stream().filter(node -> !node.isResourceManager()).collect(toImmutableSet()));
    }
    Set<InternalNode> nodeSet = nodes.build();
    for (InternalNode node : nodeSet) {
        splits.add(new SystemSplit(tableHandle.getConnectorId(), tableHandle, node.getHostAndPort(), constraint));
    }
    return new FixedSplitSource(splits.build());
}
Also used : ALL_COORDINATORS(com.facebook.presto.spi.SystemTable.Distribution.ALL_COORDINATORS) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) SINGLE_COORDINATOR(com.facebook.presto.spi.SystemTable.Distribution.SINGLE_COORDINATOR) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SystemTable(com.facebook.presto.spi.SystemTable) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ImmutableSet(com.google.common.collect.ImmutableSet) ALL_NODES(com.facebook.presto.spi.SystemTable.Distribution.ALL_NODES) HostAddress(com.facebook.presto.spi.HostAddress) Set(java.util.Set) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) String.format(java.lang.String.format) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Distribution(com.facebook.presto.spi.SystemTable.Distribution) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) HostAddress(com.facebook.presto.spi.HostAddress) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) 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) InternalNode(com.facebook.presto.metadata.InternalNode) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 2 with Distribution

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

Aggregations

ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)2 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)2 HostAddress (com.facebook.presto.spi.HostAddress)2 SystemTable (com.facebook.presto.spi.SystemTable)2 Distribution (com.facebook.presto.spi.SystemTable.Distribution)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 InternalNode (com.facebook.presto.metadata.InternalNode)1 InternalNodeManager (com.facebook.presto.metadata.InternalNodeManager)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)1 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)1 Node (com.facebook.presto.spi.Node)1 ACTIVE (com.facebook.presto.spi.NodeState.ACTIVE)1 PrestoException (com.facebook.presto.spi.PrestoException)1 NOT_FOUND (com.facebook.presto.spi.StandardErrorCode.NOT_FOUND)1 ALL_COORDINATORS (com.facebook.presto.spi.SystemTable.Distribution.ALL_COORDINATORS)1 ALL_NODES (com.facebook.presto.spi.SystemTable.Distribution.ALL_NODES)1