use of org.apache.cassandra.thrift.Mutation 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;
}
use of org.apache.cassandra.thrift.Mutation in project scale7-pelops by s7.
the class MutatorIntegrationTest method testWriteColumnsWithDeleteIfNullFromConstructor.
@Test
public void testWriteColumnsWithDeleteIfNullFromConstructor() throws Exception {
IThriftPool pool = new DebuggingPool(getCluster(), KEYSPACE, new OperandPolicy(3, true));
Bytes rowKey = Bytes.fromLong(Long.MAX_VALUE);
Bytes colName1 = Bytes.fromInt(1);
Bytes colName2 = Bytes.fromInt(2);
Mutator mutator = pool.createMutator();
assertTrue("Mutator is not in a valid state for this test", mutator.deleteIfNull);
List<Column> columns = mutator.newColumnList(mutator.newColumn(colName1, (Bytes) null), mutator.newColumn(colName2, Bytes.fromInt(1)));
mutator.writeColumns(CF, rowKey, columns);
// make sure there is at least one deletion
boolean isOneDeletion = false;
for (Mutation mutation : mutator.getMutationList(CF, rowKey)) {
if (mutation.isSetDeletion()) {
isOneDeletion = true;
break;
}
}
assertTrue("There should be one deletion", isOneDeletion);
pool.shutdown();
}
use of org.apache.cassandra.thrift.Mutation in project eiger by wlloyd.
the class ColumnFamilyRecordWriter method write.
/**
* If the key is to be associated with a valid value, a mutation is created
* for it with the given column family and columns. In the event the value
* in the column is missing (i.e., null), then it is marked for
* {@link Deletion}. Similarly, if the entire value for a key is missing
* (i.e., null), then the entire key is marked for {@link Deletion}.
* </p>
*
* @param keybuff
* the key to write.
* @param value
* the value to write.
* @throws IOException
*/
@Override
public void write(ByteBuffer keybuff, List<Mutation> value) throws IOException {
Range<Token> range = ringCache.getRange(keybuff);
// get the client for the given range, or create a new one
RangeClient client = clients.get(range);
if (client == null) {
// haven't seen keys for this range: create new client
client = new RangeClient(ringCache.getEndpoint(range));
client.start();
clients.put(range, client);
}
for (Mutation amut : value) client.put(new Pair<ByteBuffer, Mutation>(keybuff, amut));
}
use of org.apache.cassandra.thrift.Mutation in project eiger by wlloyd.
the class FacebookPopulator method getColumnsMutationMap.
private Map<String, List<Mutation>> getColumnsMutationMap(List<Column> columns) {
List<Mutation> mutations = new ArrayList<Mutation>();
Map<String, List<Mutation>> mutationMap = new HashMap<String, List<Mutation>>();
for (Column c : columns) {
ColumnOrSuperColumn column = new ColumnOrSuperColumn().setColumn(c);
mutations.add(new Mutation().setColumn_or_supercolumn(column));
}
mutationMap.put("Standard1", mutations);
return mutationMap;
}
use of org.apache.cassandra.thrift.Mutation in project eiger by wlloyd.
the class BatchMutateTransactionUtil method convertToInternalMutations.
public static List<IMutation> convertToInternalMutations(String keyspace, Map<ByteBuffer, Map<String, List<Mutation>>> mutation_map, ByteBuffer coordinatorKey) throws InvalidRequestException {
//the timestamp and localCommitTime are set when we apply the transaction, so we'll set them to invalid values here
long timestamp = Long.MIN_VALUE;
long localCommitTime = Long.MIN_VALUE;
List<IMutation> rowMutations = new ArrayList<IMutation>();
//Note, permission was checked when the thrift interface received the transaction.
for (Map.Entry<ByteBuffer, Map<String, List<Mutation>>> mutationEntry : mutation_map.entrySet()) {
ByteBuffer key = mutationEntry.getKey();
// We need to separate row mutation for standard cf and counter cf (that will be encapsulated in a
// CounterMutation) because it doesn't follow the same code path
RowMutation rmStandard = null;
RowMutation rmCounter = null;
Map<String, List<Mutation>> columnFamilyToMutations = mutationEntry.getValue();
for (Map.Entry<String, List<Mutation>> columnFamilyMutations : columnFamilyToMutations.entrySet()) {
String cfName = columnFamilyMutations.getKey();
CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace, cfName);
ThriftValidation.validateKey(metadata, key);
RowMutation rm;
if (metadata.getDefaultValidator().isCommutative()) {
ThriftValidation.validateCommutativeForWrite(metadata, ConsistencyLevel.ONE);
rmCounter = rmCounter == null ? new RowMutation(keyspace, key) : rmCounter;
rm = rmCounter;
} else {
rmStandard = rmStandard == null ? new RowMutation(keyspace, key) : rmStandard;
rm = rmStandard;
}
for (Mutation mutation : columnFamilyMutations.getValue()) {
ThriftValidation.validateMutation(metadata, mutation);
if (mutation.deletion != null) {
rm.deleteColumnOrSuperColumn(cfName, mutation.deletion, timestamp, localCommitTime, coordinatorKey);
}
if (mutation.column_or_supercolumn != null) {
rm.addColumnOrSuperColumn(cfName, mutation.column_or_supercolumn, timestamp, localCommitTime, coordinatorKey);
}
}
}
if (rmStandard != null && !rmStandard.isEmpty())
rowMutations.add(rmStandard);
if (rmCounter != null && !rmCounter.isEmpty())
rowMutations.add(new org.apache.cassandra.db.CounterMutation(rmCounter, ConsistencyLevel.ONE));
}
logger.debug("Mutations are {}", rowMutations);
return rowMutations;
}
Aggregations