Example usage for org.apache.cassandra.db PartitionPosition getToken

List of usage examples for org.apache.cassandra.db PartitionPosition getToken

Introduction

In this page you can find the example usage for org.apache.cassandra.db PartitionPosition getToken.

Prototype

public Token getToken();

Source Link

Usage

From source file:com.stratio.cassandra.lucene.IndexService.java

License:Apache License

/**
 * Returns a Lucene {@link Query} to retrieve all the rows in the specified partition position.
 *
 * @param position the ring position//w  ww.j  av  a  2s.c  o  m
 * @return the query
 */
public Query query(PartitionPosition position) {
    return position instanceof DecoratedKey ? partitionMapper.query((DecoratedKey) position)
            : tokenMapper.query(position.getToken());
}

From source file:com.stratio.cassandra.lucene.IndexServiceWide.java

License:Apache License

/** {@inheritDoc} */
@Override//from  w w  w  . jav  a  2 s . com
public Optional<Query> query(DataRange dataRange) {

    // Extract data range data
    PartitionPosition startPosition = dataRange.startKey();
    PartitionPosition stopPosition = dataRange.stopKey();
    Token startToken = startPosition.getToken();
    Token stopToken = stopPosition.getToken();
    Optional<ClusteringPrefix> maybeStartClustering = KeyMapper.startClusteringPrefix(dataRange);
    Optional<ClusteringPrefix> maybeStopClustering = KeyMapper.stopClusteringPrefix(dataRange);

    // Prepare query builder
    BooleanQuery.Builder builder = new BooleanQuery.Builder();

    // Add first partition filter
    maybeStartClustering.ifPresent(startClustering -> {
        DecoratedKey startKey = (DecoratedKey) startPosition;
        builder.add(keyMapper.query(startKey, startClustering, null, false, true), SHOULD);
    });

    // Add token range filter
    boolean includeStart = startPosition.kind() == MIN_BOUND && !maybeStartClustering.isPresent();
    boolean includeStop = stopPosition.kind() == MAX_BOUND && !maybeStopClustering.isPresent();
    tokenMapper.query(startToken, stopToken, includeStart, includeStop).ifPresent(x -> builder.add(x, SHOULD));

    // Add last partition filter
    maybeStopClustering.ifPresent(stopClustering -> {
        DecoratedKey stopKey = (DecoratedKey) stopPosition;
        builder.add(keyMapper.query(stopKey, null, stopClustering, true, false), SHOULD);
    });

    // Return query, or empty if there are no restrictions
    BooleanQuery query = builder.build();
    return query.clauses().isEmpty() ? Optional.empty() : Optional.of(query);
}

From source file:com.stratio.cassandra.lucene.key.TokenMapper.java

License:Apache License

/**
 * Returns a Lucene {@link Query} to find the {@link Document}s containing a {@link Token} inside the specified
 * {@link PartitionPosition}s./*from   w ww. j a  v  a2  s.c  o  m*/
 *
 * @param start the start position
 * @param stop the stop position
 * @return the query to find the documents containing a token inside the range
 */
public Optional<Query> query(PartitionPosition start, PartitionPosition stop) {
    return query(start.getToken(), stop.getToken(), includeStart(start), includeStop(stop));
}