Search in sources :

Example 21 with RowIterator

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

the class QueryPagerTest method query.

private static List<FilteredPartition> query(QueryPager pager, int toQuery, int expectedSize) {
    StringBuilder sb = new StringBuilder();
    List<FilteredPartition> partitionList = new ArrayList<>();
    int rows = 0;
    try (ReadExecutionController executionController = pager.executionController();
        PartitionIterator iterator = pager.fetchPageInternal(toQuery, executionController)) {
        while (iterator.hasNext()) {
            try (RowIterator rowIter = iterator.next()) {
                FilteredPartition partition = FilteredPartition.create(rowIter);
                sb.append(partition);
                partitionList.add(partition);
                rows += partition.rowCount();
            }
        }
    }
    assertEquals(sb.toString(), expectedSize, rows);
    return partitionList;
}
Also used : PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) RowIterator(org.apache.cassandra.db.rows.RowIterator) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition)

Example 22 with RowIterator

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

the class QueryPagerTest method queryAndVerifyCells.

private void queryAndVerifyCells(TableMetadata table, boolean reversed, String key) {
    ClusteringIndexFilter rowfilter = new ClusteringIndexSliceFilter(Slices.ALL, reversed);
    ReadCommand command = SinglePartitionReadCommand.create(table, nowInSec, Util.dk(key), ColumnFilter.all(table), rowfilter);
    QueryPager pager = command.getPager(null, ProtocolVersion.CURRENT);
    ColumnMetadata staticColumn = table.staticColumns().getSimple(0);
    assertEquals(staticColumn.name.toCQLString(), "st");
    for (int i = 0; i < 5; i++) {
        try (ReadExecutionController controller = pager.executionController();
            PartitionIterator partitions = pager.fetchPageInternal(1, controller)) {
            try (RowIterator partition = partitions.next()) {
                assertCell(partition.staticRow(), staticColumn, 4);
                Row row = partition.next();
                int cellIndex = !reversed ? i : 4 - i;
                assertEquals(row.clustering().bufferAt(0), ByteBufferUtil.bytes(cellIndex));
                assertCell(row, table.getColumn(new ColumnIdentifier("v1", false)), cellIndex);
                assertCell(row, table.getColumn(new ColumnIdentifier("v2", false)), cellIndex);
                // the partition/page should contain just a single regular row
                assertFalse(partition.hasNext());
            }
        }
    }
    // After processing the 5 rows there should be no more rows to return
    try (ReadExecutionController controller = pager.executionController();
        PartitionIterator partitions = pager.fetchPageInternal(1, controller)) {
        assertFalse(partitions.hasNext());
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) QueryPager(org.apache.cassandra.service.pager.QueryPager) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) RowIterator(org.apache.cassandra.db.rows.RowIterator) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) Row(org.apache.cassandra.db.rows.Row)

Example 23 with RowIterator

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

the class DataResolverTest method testResolveNewCollectionOverwritingDeleted.

@Test
public void testResolveNewCollectionOverwritingDeleted() {
    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 };
    // cleared map column
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(Clustering.EMPTY);
    builder.addComplexDeletion(m, new DeletionTime(ts[0] - 1, nowInSec));
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(cmd, peer1, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    // newer, overwritten map column
    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");
            ComplexColumnData cd = row.getComplexColumnData(m);
            assertEquals(Collections.singleton(expectedCell), Sets.newHashSet(cd));
        }
    }
    Row row = Iterators.getOnlyElement(readRepair.getForEndpoint(peer1).getPartitionUpdate(cfm2).iterator());
    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) Test(org.junit.Test)

Example 24 with RowIterator

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

the class DataResolverTest method testResolveWithOneEmpty.

@Test
public void testResolveWithOneEmpty() {
    EndpointsForRange replicas = makeReplicas(2);
    DataResolver resolver = new DataResolver(command, plan(replicas, ALL), readRepair, nanoTime());
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(command, peer1, iter(new RowUpdateBuilder(cfm, nowInSec, 1L, dk).clustering("1").add("c2", "v2").buildUpdate())));
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    resolver.preprocess(response(command, peer2, EmptyIterators.unfilteredPartition(cfm)));
    try (PartitionIterator data = resolver.resolve()) {
        try (RowIterator rows = Iterators.getOnlyElement(data)) {
            Row row = Iterators.getOnlyElement(rows);
            assertColumns(row, "c2");
            assertColumn(cfm, row, "c2", "v2", 1);
        }
    }
    assertEquals(1, readRepair.sent.size());
    // peer 2 needs the row from peer 1
    Mutation mutation = readRepair.getForEndpoint(peer2);
    assertRepairMetadata(mutation);
    assertRepairContainsNoDeletions(mutation);
    assertRepairContainsColumn(mutation, "1", "c2", "v2", 1);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) 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)

Example 25 with RowIterator

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

the class DataResolverTest method testResolveNewCollection.

@Test
public void testResolveNewCollection() {
    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 };
    // map column
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(Clustering.EMPTY);
    DeletionTime expectedCmplxDelete = new DeletionTime(ts[0] - 1, nowInSec);
    builder.addComplexDeletion(m, expectedCmplxDelete);
    Cell<?> expectedCell = mapCell(0, 0, ts[0]);
    builder.addCell(expectedCell);
    // empty map column
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    resolver.preprocess(response(cmd, peer1, iter(PartitionUpdate.singleRowUpdate(cfm2, dk, builder.build()))));
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    resolver.preprocess(response(cmd, peer2, iter(PartitionUpdate.emptyUpdate(cfm2, dk))));
    try (PartitionIterator data = resolver.resolve()) {
        try (RowIterator rows = Iterators.getOnlyElement(data)) {
            Row row = Iterators.getOnlyElement(rows);
            assertColumns(row, "m");
            ComplexColumnData cd = row.getComplexColumnData(m);
            assertEquals(Collections.singleton(expectedCell), Sets.newHashSet(cd));
        }
    }
    Assert.assertNull(readRepair.sent.get(peer1));
    Mutation mutation = readRepair.getForEndpoint(peer2);
    Iterator<Row> rowIter = mutation.getPartitionUpdate(cfm2).iterator();
    assertTrue(rowIter.hasNext());
    Row row = rowIter.next();
    assertFalse(rowIter.hasNext());
    ComplexColumnData cd = row.getComplexColumnData(m);
    assertEquals(Sets.newHashSet(expectedCell), Sets.newHashSet(cd));
    assertEquals(expectedCmplxDelete, cd.complexDeletion());
}
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

RowIterator (org.apache.cassandra.db.rows.RowIterator)25 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)16 Row (org.apache.cassandra.db.rows.Row)15 Test (org.junit.Test)12 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)10 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)9 BTreeRow (org.apache.cassandra.db.rows.BTreeRow)9 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)9 Mutation (org.apache.cassandra.db.Mutation)8 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)5 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)5 DeletionTime (org.apache.cassandra.db.DeletionTime)4 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 ByteBuffer (java.nio.ByteBuffer)3 ReadCommand (org.apache.cassandra.db.ReadCommand)3 FilteredPartition (org.apache.cassandra.db.partitions.FilteredPartition)3 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)3 ComplexColumnData (org.apache.cassandra.db.rows.ComplexColumnData)3 TestableReadRepair (org.apache.cassandra.service.reads.repair.TestableReadRepair)3