Search in sources :

Example 26 with PartitionUpdate

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"))));
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 27 with PartitionUpdate

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 28 with PartitionUpdate

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());
        }
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 29 with PartitionUpdate

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 30 with PartitionUpdate

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;
}
Also used : PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Aggregations

PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)40 Test (org.junit.Test)14 TableMetadata (org.apache.cassandra.schema.TableMetadata)7 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)3 Mutation (org.apache.cassandra.db.Mutation)3 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)3 Commit (org.apache.cassandra.service.paxos.Commit)3 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)2 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)2 TableId (org.apache.cassandra.schema.TableId)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1