Search in sources :

Example 1 with SliceRange

use of org.apache.cassandra.thrift.SliceRange in project scale7-pelops by s7.

the class Selector method newColumnsPredicateAll.

/**
     * Create a new <code>SlicePredicate</code> instance that selects "all" columns
     * @param reversed                        Whether the results should be returned in reverse order
     * @param maxColCount                     The maximum number of columns to return
     * @return                                The new <code>SlicePredicate</code>
     */
public static SlicePredicate newColumnsPredicateAll(boolean reversed, int maxColCount) {
    SlicePredicate predicate = new SlicePredicate();
    predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(), Bytes.EMPTY.getBytes(), reversed, maxColCount));
    return predicate;
}
Also used : SliceRange(org.apache.cassandra.thrift.SliceRange) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate)

Example 2 with SliceRange

use of org.apache.cassandra.thrift.SliceRange in project titan by thinkaurelius.

the class CassandraBinaryInputFormat method getSliceRange.

private SliceRange getSliceRange(final SliceQuery slice, final int limit) {
    final SliceRange sliceRange = new SliceRange();
    sliceRange.setStart(slice.getSliceStart().asByteBuffer());
    sliceRange.setFinish(slice.getSliceEnd().asByteBuffer());
    sliceRange.setCount(Math.min(limit, slice.getLimit()));
    return sliceRange;
}
Also used : SliceRange(org.apache.cassandra.thrift.SliceRange)

Example 3 with SliceRange

use of org.apache.cassandra.thrift.SliceRange in project eiger by wlloyd.

the class QueryFilter method getFilter.

public static IFilter getFilter(SlicePredicate predicate, AbstractType comparator) {
    if (predicate.column_names != null) {
        final SortedSet<ByteBuffer> columnNameSet = new TreeSet<ByteBuffer>(comparator);
        columnNameSet.addAll(predicate.column_names);
        return new NamesQueryFilter(columnNameSet);
    }
    SliceRange range = predicate.slice_range;
    return new SliceQueryFilter(range.start, range.finish, range.reversed, range.count);
}
Also used : SliceRange(org.apache.cassandra.thrift.SliceRange) ByteBuffer(java.nio.ByteBuffer)

Example 4 with SliceRange

use of org.apache.cassandra.thrift.SliceRange in project scale7-pelops by s7.

the class Selector method newColumnsPredicate.

/**
     * Create a new <code>SlicePredicate</code> instance.
     * @param startName                       The inclusive column start name of the range to select in the slice
     * @param finishName                      The inclusive column end name of the range to select in the slice
     * @param reversed                        Whether the results should be returned in reverse order
     * @param maxColCount                     The maximum number of columns to return
     * @return                                The new <code>SlicePredicate</code>
     */
public static SlicePredicate newColumnsPredicate(Bytes startName, Bytes finishName, boolean reversed, int maxColCount) {
    SlicePredicate predicate = new SlicePredicate();
    predicate.setSlice_range(new SliceRange(nullSafeGet(startName), nullSafeGet(finishName), reversed, maxColCount));
    return predicate;
}
Also used : SliceRange(org.apache.cassandra.thrift.SliceRange) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate)

Example 5 with SliceRange

use of org.apache.cassandra.thrift.SliceRange in project titan by thinkaurelius.

the class CassandraEmbeddedKeyColumnValueStore method getKeySlice.

/**
     * Create a RangeSliceCommand and run it against the StorageProxy.
     * <p>
     * To match the behavior of the standard Cassandra thrift API endpoint, the
     * {@code nowMillis} argument should be the number of milliseconds since the
     * UNIX Epoch (e.g. System.currentTimeMillis() or equivalent obtained
     * through a {@link TimestampProvider}). This is per
     * {@link org.apache.cassandra.thrift.CassandraServer#get_range_slices(ColumnParent, SlicePredicate, KeyRange, ConsistencyLevel)},
     * which passes the server's System.currentTimeMillis() to the
     * {@code RangeSliceCommand} constructor.
     */
private List<Row> getKeySlice(Token start, Token end, @Nullable SliceQuery sliceQuery, int pageSize, long nowMillis) throws BackendException {
    IPartitioner partitioner = StorageService.getPartitioner();
    SliceRange columnSlice = new SliceRange();
    if (sliceQuery == null) {
        columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5);
    } else {
        columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer()).setFinish(sliceQuery.getSliceEnd().asByteBuffer()).setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE);
    }
    /* Note: we need to fetch columns for each row as well to remove "range ghosts" */
    SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
    RowPosition startPosition = start.minKeyBound(partitioner);
    RowPosition endPosition = end.minKeyBound(partitioner);
    List<Row> rows;
    try {
        CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily);
        IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null);
        RangeSliceCommand cmd = new RangeSliceCommand(keyspace, columnFamily, nowMillis, filter, new Bounds<RowPosition>(startPosition, endPosition), pageSize);
        rows = StorageProxy.getRangeSlice(cmd, ConsistencyLevel.QUORUM);
    } catch (Exception e) {
        throw new PermanentBackendException(e);
    }
    return rows;
}
Also used : IDiskAtomFilter(org.apache.cassandra.db.filter.IDiskAtomFilter) SliceRange(org.apache.cassandra.thrift.SliceRange) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) CFMetaData(org.apache.cassandra.config.CFMetaData) IsBootstrappingException(org.apache.cassandra.exceptions.IsBootstrappingException) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) RequestTimeoutException(org.apache.cassandra.exceptions.RequestTimeoutException) UnavailableException(org.apache.cassandra.exceptions.UnavailableException)

Aggregations

SliceRange (org.apache.cassandra.thrift.SliceRange)6 SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)4 ByteBuffer (java.nio.ByteBuffer)2 DataOutputStream (java.io.DataOutputStream)1 CFMetaData (org.apache.cassandra.config.CFMetaData)1 IDiskAtomFilter (org.apache.cassandra.db.filter.IDiskAtomFilter)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 Token (org.apache.cassandra.dht.Token)1 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)1 IsBootstrappingException (org.apache.cassandra.exceptions.IsBootstrappingException)1 RequestTimeoutException (org.apache.cassandra.exceptions.RequestTimeoutException)1 UnavailableException (org.apache.cassandra.exceptions.UnavailableException)1 Message (org.apache.cassandra.net.Message)1