Search in sources :

Example 6 with SlicePredicate

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

the class Selector method getPageOfSuperColumnsFromRow.

/**
     * Retrieve a page of super columns composed from a segment of the sequence of super columns in a row.
     * @param columnFamily                  The name of the column family containing the super columns
     * @param rowKey                        The key of the row
     * @param startBeyondName               The sequence of super columns must begin with the smallest super column name greater than this value. Pass <code>null</code> to start at the beginning of the sequence.
     * @param reversed                      Whether the scan should proceed in descending super column name order
     * @param count                         The maximum number of super columns that can be retrieved by the scan
     * @param cLevel                        The Cassandra consistency level with which to perform the operation
     * @return                              A page of super columns
     * @throws PelopsException if an error occurs
     */
public List<SuperColumn> getPageOfSuperColumnsFromRow(String columnFamily, Bytes rowKey, Bytes startBeyondName, boolean reversed, int count, ConsistencyLevel cLevel) throws PelopsException {
    if (Bytes.nullSafeGet(startBeyondName) == null) {
        SlicePredicate predicate = Selector.newColumnsPredicateAll(reversed, count);
        return getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
    } else {
        // cassandra will return the start row but the user is expecting a page of results beyond that point
        int incrementedCount = count + 1;
        SlicePredicate predicate = Selector.newColumnsPredicate(startBeyondName, Bytes.EMPTY, reversed, incrementedCount);
        List<SuperColumn> columns = getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
        if (columns.size() > 0) {
            SuperColumn first = columns.get(0);
            if (first.name.equals(startBeyondName.getBytes()))
                return columns.subList(1, columns.size());
            else if (columns.size() == incrementedCount)
                return columns.subList(0, columns.size() - 1);
        }
        return columns;
    }
}
Also used : SuperColumn(org.apache.cassandra.thrift.SuperColumn) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate)

Example 7 with SlicePredicate

use of org.apache.cassandra.thrift.SlicePredicate 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 8 with SlicePredicate

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

the class Selector method newColumnsPredicate.

/**
     * Create a new <code>SlicePredicate</code> instance.
     * @param colNames                        The specific columns names to select in the slice
     * @return                                The new <code>SlicePredicate</code>
     */
public static SlicePredicate newColumnsPredicate(Bytes... colNames) {
    List<ByteBuffer> asList = new ArrayList<ByteBuffer>(32);
    for (Bytes colName : colNames) asList.add(nullSafeGet(colName));
    SlicePredicate predicate = new SlicePredicate();
    predicate.setColumn_names(asList);
    return predicate;
}
Also used : ArrayList(java.util.ArrayList) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) ByteBuffer(java.nio.ByteBuffer) Bytes.fromByteBuffer(org.scale7.cassandra.pelops.Bytes.fromByteBuffer)

Example 9 with SlicePredicate

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

the class Mutator method deleteColumns.

/**
     * Delete a list of columns or super columns.
     * @param colFamily                 The column family
     * @param rowKey                    The key of the row to modify
     * @param colNames                  The column and/or super column names to delete
     */
public Mutator deleteColumns(String colFamily, Bytes rowKey, List<Bytes> colNames) {
    safeGetRowKey(rowKey);
    validateColumnNames(colNames);
    SlicePredicate pred = new SlicePredicate();
    pred.setColumn_names(Bytes.transformBytesToList(colNames));
    Deletion deletion = new Deletion();
    deletion.setTimestamp(timestamp);
    deletion.setPredicate(pred);
    Mutation mutation = new Mutation();
    mutation.setDeletion(deletion);
    getMutationList(colFamily, rowKey).add(mutation);
    return this;
}
Also used : Deletion(org.apache.cassandra.thrift.Deletion) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) Mutation(org.apache.cassandra.thrift.Mutation)

Example 10 with SlicePredicate

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

the class Mutator method deleteSubColumns.

/**
     * Delete a list of sub-columns
     * @param colFamily                 The column family
     * @param rowKey                    The key of the row to modify
     * @param colName               	The name of the super column to modify
     * @param subColNames               The sub-column names to delete
     */
public Mutator deleteSubColumns(String colFamily, Bytes rowKey, Bytes colName, List<Bytes> subColNames) {
    safeGetRowKey(rowKey);
    validateColumnName(colName);
    validateColumnNames(subColNames);
    Deletion deletion = new Deletion();
    deletion.setTimestamp(timestamp);
    deletion.setSuper_column(nullSafeGet(colName));
    // CASSANDRA-1027 allows for a null predicate
    deletion.setPredicate(subColNames != null && !subColNames.isEmpty() ? new SlicePredicate().setColumn_names(Bytes.transformBytesToList(subColNames)) : null);
    Mutation mutation = new Mutation();
    mutation.setDeletion(deletion);
    getMutationList(colFamily, rowKey).add(mutation);
    return this;
}
Also used : Deletion(org.apache.cassandra.thrift.Deletion) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) Mutation(org.apache.cassandra.thrift.Mutation)

Aggregations

SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)15 ByteBuffer (java.nio.ByteBuffer)5 SliceRange (org.apache.cassandra.thrift.SliceRange)4 ArrayList (java.util.ArrayList)3 ColumnOrSuperColumn (org.apache.cassandra.thrift.ColumnOrSuperColumn)2 Deletion (org.apache.cassandra.thrift.Deletion)2 Mutation (org.apache.cassandra.thrift.Mutation)2 SuperColumn (org.apache.cassandra.thrift.SuperColumn)2 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)2 TDeserializer (org.apache.thrift.TDeserializer)2 Bytes.fromByteBuffer (org.scale7.cassandra.pelops.Bytes.fromByteBuffer)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