Search in sources :

Example 1 with NODE_COLUMN_NAME

use of io.trino.plugin.jmx.JmxMetadata.NODE_COLUMN_NAME in project trino by trinodb.

the class JmxSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy, DynamicFilter dynamicFilter) {
    JmxTableHandle tableHandle = (JmxTableHandle) table;
    // 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);
    TupleDomain<ColumnHandle> nodeFilter = tableHandle.getNodeFilter();
    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
        NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
        return nodeFilter.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
    }).map(node -> new JmxSplit(ImmutableList.of(node.getHostAndPort()))).collect(toList());
    return new FixedSplitSource(splits);
}
Also used : ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) ImmutableMap(com.google.common.collect.ImmutableMap) NullableValue(io.trino.spi.predicate.NullableValue) NodeManager(io.trino.spi.NodeManager) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) ConnectorSplitSource(io.trino.spi.connector.ConnectorSplitSource) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Inject(javax.inject.Inject) TupleDomain.fromFixedValues(io.trino.spi.predicate.TupleDomain.fromFixedValues) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) NODE_COLUMN_NAME(io.trino.plugin.jmx.JmxMetadata.NODE_COLUMN_NAME) DynamicFilter(io.trino.spi.connector.DynamicFilter) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) Optional(java.util.Optional) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) NullableValue(io.trino.spi.predicate.NullableValue) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 NODE_COLUMN_NAME (io.trino.plugin.jmx.JmxMetadata.NODE_COLUMN_NAME)1 NodeManager (io.trino.spi.NodeManager)1 ColumnHandle (io.trino.spi.connector.ColumnHandle)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)1 ConnectorSplitManager (io.trino.spi.connector.ConnectorSplitManager)1 ConnectorSplitSource (io.trino.spi.connector.ConnectorSplitSource)1 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)1 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)1 DynamicFilter (io.trino.spi.connector.DynamicFilter)1 FixedSplitSource (io.trino.spi.connector.FixedSplitSource)1 NullableValue (io.trino.spi.predicate.NullableValue)1 TupleDomain (io.trino.spi.predicate.TupleDomain)1 TupleDomain.fromFixedValues (io.trino.spi.predicate.TupleDomain.fromFixedValues)1 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)1 List (java.util.List)1