Search in sources :

Example 11 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 12 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 13 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)

Example 14 with SlicePredicate

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

the class SerializationsTest method testRangeSliceCommandWrite.

private void testRangeSliceCommandWrite() throws IOException {
    ByteBuffer startCol = ByteBufferUtil.bytes("Start");
    ByteBuffer stopCol = ByteBufferUtil.bytes("Stop");
    ByteBuffer emptyCol = ByteBufferUtil.bytes("");
    SlicePredicate namesPred = new SlicePredicate();
    namesPred.column_names = Statics.NamedCols;
    SliceRange emptySliceRange = new SliceRange(emptyCol, emptyCol, false, 100);
    SliceRange nonEmptySliceRange = new SliceRange(startCol, stopCol, true, 100);
    SlicePredicate emptyRangePred = new SlicePredicate();
    emptyRangePred.slice_range = emptySliceRange;
    SlicePredicate nonEmptyRangePred = new SlicePredicate();
    nonEmptyRangePred.slice_range = nonEmptySliceRange;
    IPartitioner part = StorageService.getPartitioner();
    AbstractBounds<RowPosition> bounds = new Range<Token>(part.getRandomToken(), part.getRandomToken()).toRowBounds();
    Message namesCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, namesPred, bounds, 100).getMessage(MessagingService.version_);
    Message emptyRangeCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, emptyRangePred, bounds, 100).getMessage(MessagingService.version_);
    Message regRangeCmd = new RangeSliceCommand(Statics.KS, "Standard1", null, nonEmptyRangePred, bounds, 100).getMessage(MessagingService.version_);
    Message namesCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, namesPred, bounds, 100).getMessage(MessagingService.version_);
    Message emptyRangeCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, emptyRangePred, bounds, 100).getMessage(MessagingService.version_);
    Message regRangeCmdSup = new RangeSliceCommand(Statics.KS, "Super1", Statics.SC, nonEmptyRangePred, bounds, 100).getMessage(MessagingService.version_);
    DataOutputStream dout = getOutput("db.RangeSliceCommand.bin");
    messageSerializer.serialize(namesCmd, dout, getVersion());
    messageSerializer.serialize(emptyRangeCmd, dout, getVersion());
    messageSerializer.serialize(regRangeCmd, dout, getVersion());
    messageSerializer.serialize(namesCmdSup, dout, getVersion());
    messageSerializer.serialize(emptyRangeCmdSup, dout, getVersion());
    messageSerializer.serialize(regRangeCmdSup, dout, getVersion());
    dout.close();
}
Also used : Message(org.apache.cassandra.net.Message) SliceRange(org.apache.cassandra.thrift.SliceRange) DataOutputStream(java.io.DataOutputStream) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) Token(org.apache.cassandra.dht.Token) ByteBuffer(java.nio.ByteBuffer) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 15 with SlicePredicate

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

the class ColumnFamilyInputFormatTest method testSlicePredicate.

@Test
public void testSlicePredicate() {
    long columnValue = 1271253600000l;
    ByteBuffer columnBytes = ByteBufferUtil.bytes(columnValue);
    List<ByteBuffer> columnNames = new ArrayList<ByteBuffer>();
    columnNames.add(columnBytes);
    SlicePredicate originalPredicate = new SlicePredicate().setColumn_names(columnNames);
    Configuration conf = new Configuration();
    ConfigHelper.setInputSlicePredicate(conf, originalPredicate);
    SlicePredicate rtPredicate = ConfigHelper.getInputSlicePredicate(conf);
    assert rtPredicate.column_names.size() == 1;
    assert originalPredicate.column_names.get(0).equals(rtPredicate.column_names.get(0));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ArrayList(java.util.ArrayList) SlicePredicate(org.apache.cassandra.thrift.SlicePredicate) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

SlicePredicate (org.apache.cassandra.thrift.SlicePredicate)17 ByteBuffer (java.nio.ByteBuffer)5 SliceRange (org.apache.cassandra.thrift.SliceRange)5 ArrayList (java.util.ArrayList)3 CFMetaData (org.apache.cassandra.config.CFMetaData)2 IDiskAtomFilter (org.apache.cassandra.db.filter.IDiskAtomFilter)2 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)2 IsBootstrappingException (org.apache.cassandra.exceptions.IsBootstrappingException)2 RequestTimeoutException (org.apache.cassandra.exceptions.RequestTimeoutException)2 UnavailableException (org.apache.cassandra.exceptions.UnavailableException)2 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 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 Token (org.apache.cassandra.dht.Token)1