Search in sources :

Example 6 with PartitionIterator

use of org.apache.cassandra.db.partitions.PartitionIterator in project cassandra by apache.

the class QueryPagerTest method queryAndVerifyCells.

private void queryAndVerifyCells(TableMetadata table, boolean reversed, String key) throws Exception {
    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().get(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 7 with PartitionIterator

use of org.apache.cassandra.db.partitions.PartitionIterator in project cassandra by apache.

the class SelectStatement method execute.

private ResultMessage.Rows execute(Pager pager, QueryOptions options, int pageSize, int nowInSec, int userLimit, long queryStartNanoTime) throws RequestValidationException, RequestExecutionException {
    if (aggregationSpec != null) {
        if (!restrictions.hasPartitionKeyRestrictions()) {
            warn("Aggregation query used without partition key");
        } else if (restrictions.keyIsInRelation()) {
            warn("Aggregation query used on multiple partition keys (IN restriction)");
        }
    }
    // We can't properly do post-query ordering if we page (see #6722)
    // For GROUP BY or aggregation queries we always page internally even if the user has turned paging off
    checkFalse(pageSize > 0 && needsPostQueryOrdering(), "Cannot page queries with both ORDER BY and a IN restriction on the partition key;" + " you must either remove the ORDER BY or the IN and sort client side, or disable paging for this query");
    ResultMessage.Rows msg;
    try (PartitionIterator page = pager.fetchPage(pageSize, queryStartNanoTime)) {
        msg = processResults(page, options, nowInSec, userLimit);
    }
    // shouldn't be moved inside the 'try' above.
    if (!pager.isExhausted())
        msg.result.metadata.setHasMorePages(pager.state());
    return msg;
}
Also used : PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage)

Example 8 with PartitionIterator

use of org.apache.cassandra.db.partitions.PartitionIterator in project cassandra by apache.

the class ReadCallback method get.

public PartitionIterator get() throws ReadFailureException, ReadTimeoutException, DigestMismatchException {
    awaitResults();
    PartitionIterator result = blockfor == 1 ? resolver.getData() : resolver.resolve();
    if (logger.isTraceEnabled())
        logger.trace("Read: {} ms.", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - queryStartNanoTime));
    return result;
}
Also used : PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator)

Example 9 with PartitionIterator

use of org.apache.cassandra.db.partitions.PartitionIterator in project cassandra by apache.

the class KeyspaceTest method assertRowsInSlice.

private static void assertRowsInSlice(ColumnFamilyStore cfs, String key, int sliceStart, int sliceEnd, int limit, boolean reversed, String columnValuePrefix) {
    Clustering startClustering = Clustering.make(ByteBufferUtil.bytes(sliceStart));
    Clustering endClustering = Clustering.make(ByteBufferUtil.bytes(sliceEnd));
    Slices slices = Slices.with(cfs.getComparator(), Slice.make(startClustering, endClustering));
    ClusteringIndexSliceFilter filter = new ClusteringIndexSliceFilter(slices, reversed);
    SinglePartitionReadCommand command = singlePartitionSlice(cfs, key, filter, limit);
    try (ReadExecutionController executionController = command.executionController();
        PartitionIterator iterator = command.executeInternal(executionController)) {
        try (RowIterator rowIterator = iterator.next()) {
            if (reversed) {
                for (int i = sliceEnd; i >= sliceStart; i--) {
                    Row row = rowIterator.next();
                    Cell cell = row.getCell(cfs.metadata().getColumn(new ColumnIdentifier("c", false)));
                    assertEquals(ByteBufferUtil.bytes(columnValuePrefix + i), cell.value());
                }
            } else {
                for (int i = sliceStart; i <= sliceEnd; i++) {
                    Row row = rowIterator.next();
                    Cell cell = row.getCell(cfs.metadata().getColumn(new ColumnIdentifier("c", false)));
                    assertEquals(ByteBufferUtil.bytes(columnValuePrefix + i), cell.value());
                }
            }
            assertFalse(rowIterator.hasNext());
        }
    }
}
Also used : 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) Cell(org.apache.cassandra.db.rows.Cell)

Example 10 with PartitionIterator

use of org.apache.cassandra.db.partitions.PartitionIterator in project cassandra by apache.

the class KeyspaceTest method assertRowsInResult.

private static void assertRowsInResult(ColumnFamilyStore cfs, SinglePartitionReadCommand command, int... columnValues) {
    try (ReadExecutionController executionController = command.executionController();
        PartitionIterator iterator = command.executeInternal(executionController)) {
        if (columnValues.length == 0) {
            if (iterator.hasNext())
                fail("Didn't expect any results, but got rows starting with: " + iterator.next().next().toString(cfs.metadata()));
            return;
        }
        try (RowIterator rowIterator = iterator.next()) {
            for (int expected : columnValues) {
                Row row = rowIterator.next();
                Cell cell = row.getCell(cfs.metadata().getColumn(new ColumnIdentifier("c", false)));
                assertEquals(String.format("Expected %s, but got %s", ByteBufferUtil.bytesToHex(ByteBufferUtil.bytes(expected)), ByteBufferUtil.bytesToHex(cell.value())), ByteBufferUtil.bytes(expected), cell.value());
            }
            assertFalse(rowIterator.hasNext());
        }
    }
}
Also used : 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) Cell(org.apache.cassandra.db.rows.Cell)

Aggregations

PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)10 RowIterator (org.apache.cassandra.db.rows.RowIterator)6 Row (org.apache.cassandra.db.rows.Row)5 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)4 Cell (org.apache.cassandra.db.rows.Cell)3 QueryPager (org.apache.cassandra.service.pager.QueryPager)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ClusteringIndexSliceFilter (org.apache.cassandra.db.filter.ClusteringIndexSliceFilter)1 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)1 RowFilter (org.apache.cassandra.db.filter.RowFilter)1 FilteredPartition (org.apache.cassandra.db.partitions.FilteredPartition)1 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)1 UnfilteredPartitionIterators (org.apache.cassandra.db.partitions.UnfilteredPartitionIterators)1 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)1 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)1 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1 AggregationQueryPager (org.apache.cassandra.service.pager.AggregationQueryPager)1