Search in sources :

Example 1 with ComplexColumnData

use of org.apache.cassandra.db.rows.ComplexColumnData in project cassandra by apache.

the class DataResolverTest method testResolveDeletedCollection.

@Test
public void testResolveDeletedCollection() {
    EndpointsForRange replicas = makeReplicas(2);
    ReadCommand cmd = Util.cmd(cfs2, dk).withNowInSeconds(nowInSec).build();
    TestableReadRepair readRepair = new TestableReadRepair(cmd);
    DataResolver resolver = new DataResolver(cmd, plan(replicas, ALL), readRepair, nanoTime());
    long[] ts = { 100, 200 };
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(Clustering.EMPTY);
    builder.addComplexDeletion(m, new DeletionTime(ts[0] - 1, nowInSec));
    builder.addCell(mapCell(0, 0, ts[0]));
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(cmd, peer1, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    builder.newRow(Clustering.EMPTY);
    DeletionTime expectedCmplxDelete = new DeletionTime(ts[1] - 1, nowInSec);
    builder.addComplexDeletion(m, expectedCmplxDelete);
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    resolver.preprocess(response(cmd, peer2, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    try (PartitionIterator data = resolver.resolve()) {
        assertFalse(data.hasNext());
    }
    Mutation mutation = readRepair.getForEndpoint(peer1);
    Iterator<Row> rowIter = mutation.getPartitionUpdate(cfm2).iterator();
    assertTrue(rowIter.hasNext());
    Row row = rowIter.next();
    assertFalse(rowIter.hasNext());
    ComplexColumnData cd = row.getComplexColumnData(m);
    assertEquals(Collections.emptySet(), Sets.newHashSet(cd));
    assertEquals(expectedCmplxDelete, cd.complexDeletion());
    Assert.assertNull(readRepair.sent.get(peer2));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TestableReadRepair(org.apache.cassandra.service.reads.repair.TestableReadRepair) DeletionTime(org.apache.cassandra.db.DeletionTime) ReadCommand(org.apache.cassandra.db.ReadCommand) ComplexColumnData(org.apache.cassandra.db.rows.ComplexColumnData) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) BTreeRow(org.apache.cassandra.db.rows.BTreeRow) Row(org.apache.cassandra.db.rows.Row) Mutation(org.apache.cassandra.db.Mutation) Test(org.junit.Test)

Example 2 with ComplexColumnData

use of org.apache.cassandra.db.rows.ComplexColumnData in project cassandra by apache.

the class SelectStatement method addValue.

private static void addValue(Selection.ResultSetBuilder result, ColumnMetadata def, Row row, int nowInSec, ProtocolVersion protocolVersion) {
    if (def.isComplex()) {
        assert def.type.isMultiCell();
        ComplexColumnData complexData = row.getComplexColumnData(def);
        if (complexData == null)
            result.add(null);
        else if (def.type.isCollection())
            result.add(((CollectionType) def.type).serializeForNativeProtocol(complexData.iterator(), protocolVersion));
        else
            result.add(((UserType) def.type).serializeForNativeProtocol(complexData.iterator(), protocolVersion));
    } else {
        result.add(row.getCell(def), nowInSec);
    }
}
Also used : ComplexColumnData(org.apache.cassandra.db.rows.ComplexColumnData)

Example 3 with ComplexColumnData

use of org.apache.cassandra.db.rows.ComplexColumnData in project cassandra by apache.

the class JsonTransformer method serializeColumnData.

private void serializeColumnData(ColumnData cd, LivenessInfo liveInfo) {
    if (cd.column().isSimple()) {
        serializeCell((Cell<?>) cd, liveInfo);
    } else {
        ComplexColumnData complexData = (ComplexColumnData) cd;
        if (!complexData.complexDeletion().isLive()) {
            try {
                objectIndenter.setCompact(true);
                json.writeStartObject();
                json.writeFieldName("name");
                json.writeString(cd.column().name.toCQLString());
                serializeDeletion(complexData.complexDeletion());
                objectIndenter.setCompact(true);
                json.writeEndObject();
                objectIndenter.setCompact(false);
            } catch (IOException e) {
                logger.error("Failure parsing ColumnData.", e);
            }
        }
        for (Cell<?> cell : complexData) {
            serializeCell(cell, liveInfo);
        }
    }
}
Also used : ComplexColumnData(org.apache.cassandra.db.rows.ComplexColumnData) IOException(java.io.IOException)

Example 4 with ComplexColumnData

use of org.apache.cassandra.db.rows.ComplexColumnData in project cassandra by apache.

the class SelectStatement method addValue.

private static void addValue(ResultSetBuilder result, ColumnMetadata def, Row row, int nowInSec, ProtocolVersion protocolVersion) {
    if (def.isComplex()) {
        assert def.type.isMultiCell();
        ComplexColumnData complexData = row.getComplexColumnData(def);
        if (complexData == null)
            result.add(null);
        else if (def.type.isCollection())
            result.add(((CollectionType) def.type).serializeForNativeProtocol(complexData.iterator(), protocolVersion));
        else
            result.add(((UserType) def.type).serializeForNativeProtocol(complexData.iterator(), protocolVersion));
    } else {
        result.add(row.getCell(def), nowInSec);
    }
}
Also used : ComplexColumnData(org.apache.cassandra.db.rows.ComplexColumnData)

Example 5 with ComplexColumnData

use of org.apache.cassandra.db.rows.ComplexColumnData in project cassandra by apache.

the class DataResolverTest method testResolveComplexDelete.

@Test
public void testResolveComplexDelete() {
    EndpointsForRange replicas = makeReplicas(2);
    ReadCommand cmd = Util.cmd(cfs2, dk).withNowInSeconds(nowInSec).build();
    TestableReadRepair readRepair = new TestableReadRepair(cmd);
    DataResolver resolver = new DataResolver(cmd, plan(replicas, ALL), readRepair, nanoTime());
    long[] ts = { 100, 200 };
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(Clustering.EMPTY);
    builder.addComplexDeletion(m, new DeletionTime(ts[0] - 1, nowInSec));
    builder.addCell(mapCell(0, 0, ts[0]));
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(cmd, peer1, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    builder.newRow(Clustering.EMPTY);
    DeletionTime expectedCmplxDelete = new DeletionTime(ts[1] - 1, nowInSec);
    builder.addComplexDeletion(m, expectedCmplxDelete);
    Cell<?> expectedCell = mapCell(1, 1, ts[1]);
    builder.addCell(expectedCell);
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    resolver.preprocess(response(cmd, peer2, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    try (PartitionIterator data = resolver.resolve()) {
        try (RowIterator rows = Iterators.getOnlyElement(data)) {
            Row row = Iterators.getOnlyElement(rows);
            assertColumns(row, "m");
            Assert.assertNull(row.getCell(m, CellPath.create(bb(0))));
            Assert.assertNotNull(row.getCell(m, CellPath.create(bb(1))));
        }
    }
    Mutation mutation = readRepair.getForEndpoint(peer1);
    Iterator<Row> rowIter = mutation.getPartitionUpdate(cfm2).iterator();
    assertTrue(rowIter.hasNext());
    Row row = rowIter.next();
    assertFalse(rowIter.hasNext());
    ComplexColumnData cd = row.getComplexColumnData(m);
    assertEquals(Collections.singleton(expectedCell), Sets.newHashSet(cd));
    assertEquals(expectedCmplxDelete, cd.complexDeletion());
    Assert.assertNull(readRepair.sent.get(peer2));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TestableReadRepair(org.apache.cassandra.service.reads.repair.TestableReadRepair) DeletionTime(org.apache.cassandra.db.DeletionTime) ReadCommand(org.apache.cassandra.db.ReadCommand) ComplexColumnData(org.apache.cassandra.db.rows.ComplexColumnData) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) RowIterator(org.apache.cassandra.db.rows.RowIterator) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) BTreeRow(org.apache.cassandra.db.rows.BTreeRow) Row(org.apache.cassandra.db.rows.Row) Mutation(org.apache.cassandra.db.Mutation) Test(org.junit.Test)

Aggregations

ComplexColumnData (org.apache.cassandra.db.rows.ComplexColumnData)7 DeletionTime (org.apache.cassandra.db.DeletionTime)4 ReadCommand (org.apache.cassandra.db.ReadCommand)4 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)4 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)4 BTreeRow (org.apache.cassandra.db.rows.BTreeRow)4 Row (org.apache.cassandra.db.rows.Row)4 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)4 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)4 TestableReadRepair (org.apache.cassandra.service.reads.repair.TestableReadRepair)4 Test (org.junit.Test)4 Mutation (org.apache.cassandra.db.Mutation)3 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 IOException (java.io.IOException)1