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());
}
}
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;
}
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;
}
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());
}
}
}
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());
}
}
}
Aggregations