Search in sources :

Example 31 with ConnectorSplit

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

the class RedisSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    RedisTableHandle redisTableHandle = convertLayout(layout).getTable();
    List<HostAddress> nodes = new ArrayList<>(redisConnectorConfig.getNodes());
    Collections.shuffle(nodes);
    checkState(!nodes.isEmpty(), "No Redis nodes available");
    ImmutableList.Builder<ConnectorSplit> builder = ImmutableList.builder();
    long numberOfKeys = 1;
    // splits by splitting zset in chunks
    if (redisTableHandle.getKeyDataFormat().equals("zset")) {
        try (Jedis jedis = jedisManager.getJedisPool(nodes.get(0)).getResource()) {
            numberOfKeys = jedis.zcount(redisTableHandle.getKeyName(), "-inf", "+inf");
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    long stride = REDIS_STRIDE_SPLITS;
    if (numberOfKeys / stride > REDIS_MAX_SPLITS) {
        stride = numberOfKeys / REDIS_MAX_SPLITS;
    }
    for (long startIndex = 0; startIndex < numberOfKeys; startIndex += stride) {
        long endIndex = startIndex + stride - 1;
        if (endIndex >= numberOfKeys) {
            endIndex = -1;
        }
        RedisSplit split = new RedisSplit(connectorId, redisTableHandle.getSchemaName(), redisTableHandle.getTableName(), redisTableHandle.getKeyDataFormat(), redisTableHandle.getValueDataFormat(), redisTableHandle.getKeyName(), startIndex, endIndex, nodes);
        builder.add(split);
    }
    return new FixedSplitSource(builder.build());
}
Also used : Jedis(redis.clients.jedis.Jedis) ImmutableList(com.google.common.collect.ImmutableList) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) ArrayList(java.util.ArrayList) HostAddress(com.facebook.presto.spi.HostAddress) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Aggregations

ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)31 ColumnHandle (com.facebook.presto.spi.ColumnHandle)15 ImmutableList (com.google.common.collect.ImmutableList)15 Test (org.testng.annotations.Test)13 ConnectorSession (com.facebook.presto.spi.ConnectorSession)11 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)11 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)10 List (java.util.List)10 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)9 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)9 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)9 Constraint (com.facebook.presto.spi.Constraint)9 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)8 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)8 MaterializedResult (com.facebook.presto.testing.MaterializedResult)8 MaterializedRow (com.facebook.presto.testing.MaterializedRow)8 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)8 ConnectorTableLayoutResult (com.facebook.presto.spi.ConnectorTableLayoutResult)7 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)7 ConnectorSplitManager (com.facebook.presto.spi.connector.ConnectorSplitManager)7