use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class TriggerExecutorTest method differentKeyRowMutations.
@Test
public void differentKeyRowMutations() throws ConfigurationException, InvalidRequestException {
TableMetadata metadata = makeTableMetadata("ks1", "cf1", TriggerMetadata.create("test", DifferentKeyTrigger.class.getName()));
PartitionUpdate cf1 = makeCf(metadata, "k1", "v1", null);
Mutation rm = new Mutation("ks1", cf1.partitionKey()).add(cf1);
List<? extends IMutation> tmutations = new ArrayList<>(TriggerExecutor.instance.execute(Arrays.asList(rm)));
assertEquals(2, tmutations.size());
Collections.sort(tmutations, new RmComparator());
assertEquals(bytes("k1"), tmutations.get(0).key().getKey());
assertEquals(bytes("otherKey"), tmutations.get(1).key().getKey());
List<PartitionUpdate> mutatedCFs = new ArrayList<>(tmutations.get(0).getPartitionUpdates());
assertEquals(1, mutatedCFs.size());
Row row = mutatedCFs.get(0).iterator().next();
assertEquals(bytes("v1"), row.getCell(metadata.getColumn(bytes("c1"))).value());
assertNull(row.getCell(metadata.getColumn(bytes("c2"))));
mutatedCFs = new ArrayList<>(tmutations.get(1).getPartitionUpdates());
assertEquals(1, mutatedCFs.size());
row = mutatedCFs.get(0).iterator().next();
assertEquals(bytes("trigger"), row.getCell(metadata.getColumn(bytes("c2"))).value());
assertNull(row.getCell(metadata.getColumn(bytes("c1"))));
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class TriggerExecutorTest method sameKeySameCfRowMutations.
@Test
public void sameKeySameCfRowMutations() throws ConfigurationException, InvalidRequestException {
TableMetadata metadata = makeTableMetadata("ks1", "cf1", TriggerMetadata.create("test", SameKeySameCfTrigger.class.getName()));
PartitionUpdate cf1 = makeCf(metadata, "k1", "k1v1", null);
PartitionUpdate cf2 = makeCf(metadata, "k2", "k2v1", null);
Mutation rm1 = new Mutation("ks1", cf1.partitionKey()).add(cf1);
Mutation rm2 = new Mutation("ks1", cf2.partitionKey()).add(cf2);
List<? extends IMutation> tmutations = new ArrayList<>(TriggerExecutor.instance.execute(Arrays.asList(rm1, rm2)));
assertEquals(2, tmutations.size());
Collections.sort(tmutations, new RmComparator());
List<PartitionUpdate> mutatedCFs = new ArrayList<>(tmutations.get(0).getPartitionUpdates());
assertEquals(1, mutatedCFs.size());
Row row = mutatedCFs.get(0).iterator().next();
assertEquals(bytes("k1v1"), row.getCell(metadata.getColumn(bytes("c1"))).value());
assertEquals(bytes("trigger"), row.getCell(metadata.getColumn(bytes("c2"))).value());
mutatedCFs = new ArrayList<>(tmutations.get(1).getPartitionUpdates());
assertEquals(1, mutatedCFs.size());
row = mutatedCFs.get(0).iterator().next();
assertEquals(bytes("k2v1"), row.getCell(metadata.getColumn(bytes("c1"))).value());
assertEquals(bytes("trigger"), row.getCell(metadata.getColumn(bytes("c2"))).value());
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class TriggerExecutorTest method sameKeyDifferentCfRowMutations.
@Test
public void sameKeyDifferentCfRowMutations() throws ConfigurationException, InvalidRequestException {
TableMetadata metadata = makeTableMetadata("ks1", "cf1", TriggerMetadata.create("test", SameKeyDifferentCfTrigger.class.getName()));
PartitionUpdate cf1 = makeCf(metadata, "k1", "k1v1", null);
PartitionUpdate cf2 = makeCf(metadata, "k2", "k2v1", null);
Mutation rm1 = new Mutation("ks1", cf1.partitionKey()).add(cf1);
Mutation rm2 = new Mutation("ks1", cf2.partitionKey()).add(cf2);
List<? extends IMutation> tmutations = new ArrayList<>(TriggerExecutor.instance.execute(Arrays.asList(rm1, rm2)));
assertEquals(2, tmutations.size());
Collections.sort(tmutations, new RmComparator());
List<PartitionUpdate> mutatedCFs = new ArrayList<>(tmutations.get(0).getPartitionUpdates());
assertEquals(2, mutatedCFs.size());
for (PartitionUpdate update : mutatedCFs) {
if (update.metadata().name.equals("cf1")) {
Row row = update.iterator().next();
assertEquals(bytes("k1v1"), row.getCell(metadata.getColumn(bytes("c1"))).value());
assertNull(row.getCell(metadata.getColumn(bytes("c2"))));
} else {
Row row = update.iterator().next();
assertNull(row.getCell(metadata.getColumn(bytes("c1"))));
assertEquals(bytes("trigger"), row.getCell(metadata.getColumn(bytes("c2"))).value());
}
}
mutatedCFs = new ArrayList<>(tmutations.get(1).getPartitionUpdates());
assertEquals(2, mutatedCFs.size());
for (PartitionUpdate update : mutatedCFs) {
if (update.metadata().name.equals("cf1")) {
Row row = update.iterator().next();
assertEquals(bytes("k2v1"), row.getCell(metadata.getColumn(bytes("c1"))).value());
assertNull(row.getCell(metadata.getColumn(bytes("c2"))));
} else {
Row row = update.iterator().next();
assertNull(row.getCell(metadata.getColumn(bytes("c1"))));
assertEquals(bytes("trigger"), row.getCell(metadata.getColumn(bytes("c2"))).value());
}
}
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class TriggerExecutorTest method sameKeySameCfPartialRowMutations.
@Test
public void sameKeySameCfPartialRowMutations() throws ConfigurationException, InvalidRequestException {
TableMetadata metadata = makeTableMetadata("ks1", "cf1", TriggerMetadata.create("test", SameKeySameCfPartialTrigger.class.getName()));
PartitionUpdate cf1 = makeCf(metadata, "k1", "k1v1", null);
PartitionUpdate cf2 = makeCf(metadata, "k2", "k2v1", null);
Mutation rm1 = new Mutation("ks1", cf1.partitionKey()).add(cf1);
Mutation rm2 = new Mutation("ks1", cf2.partitionKey()).add(cf2);
List<? extends IMutation> tmutations = new ArrayList<>(TriggerExecutor.instance.execute(Arrays.asList(rm1, rm2)));
assertEquals(2, tmutations.size());
Collections.sort(tmutations, new RmComparator());
List<PartitionUpdate> mutatedCFs = new ArrayList<>(tmutations.get(0).getPartitionUpdates());
assertEquals(1, mutatedCFs.size());
Row row = mutatedCFs.get(0).iterator().next();
assertEquals(bytes("k1v1"), row.getCell(metadata.getColumn(bytes("c1"))).value());
assertNull(row.getCell(metadata.getColumn(bytes("c2"))));
mutatedCFs = new ArrayList<>(tmutations.get(1).getPartitionUpdates());
assertEquals(1, mutatedCFs.size());
row = mutatedCFs.get(0).iterator().next();
assertEquals(bytes("k2v1"), row.getCell(metadata.getColumn(bytes("c1"))).value());
assertEquals(bytes("trigger"), row.getCell(metadata.getColumn(bytes("c2"))).value());
}
use of org.apache.cassandra.db.partitions.PartitionUpdate in project cassandra by apache.
the class SSTableSimpleUnsortedWriter method getUpdateFor.
PartitionUpdate getUpdateFor(DecoratedKey key) {
assert key != null;
PartitionUpdate previous = buffer.get(key);
if (previous == null) {
previous = createPartitionUpdate(key);
currentSize += PartitionUpdate.serializer.serializedSize(previous, formatType.info.getLatestVersion().correspondingMessagingVersion());
previous.allowNewUpdates();
buffer.put(key, previous);
}
return previous;
}
Aggregations