Search in sources :

Example 1 with QueryPager

use of org.apache.cassandra.service.pager.QueryPager in project cassandra by apache.

the class QueryProcessor method executeInternalWithPaging.

public static UntypedResultSet executeInternalWithPaging(String query, int pageSize, Object... values) {
    ParsedStatement.Prepared prepared = prepareInternal(query);
    if (!(prepared.statement instanceof SelectStatement))
        throw new IllegalArgumentException("Only SELECTs can be paged");
    SelectStatement select = (SelectStatement) prepared.statement;
    QueryPager pager = select.getQuery(makeInternalOptions(prepared, values), FBUtilities.nowInSeconds()).getPager(null, ProtocolVersion.CURRENT);
    return UntypedResultSet.create(select, pager, pageSize);
}
Also used : QueryPager(org.apache.cassandra.service.pager.QueryPager)

Example 2 with QueryPager

use of org.apache.cassandra.service.pager.QueryPager in project cassandra by apache.

the class SelectStatement method executeInternal.

public ResultMessage.Rows executeInternal(QueryState state, QueryOptions options, int nowInSec, long queryStartNanoTime) throws RequestExecutionException, RequestValidationException {
    int userLimit = getLimit(options);
    int userPerPartitionLimit = getPerPartitionLimit(options);
    int pageSize = options.getPageSize();
    ReadQuery query = getQuery(options, nowInSec, userLimit, userPerPartitionLimit, pageSize);
    try (ReadExecutionController executionController = query.executionController()) {
        if (aggregationSpec == null && (pageSize <= 0 || (query.limits().count() <= pageSize))) {
            try (PartitionIterator data = query.executeInternal(executionController)) {
                return processResults(data, options, nowInSec, userLimit);
            }
        } else {
            QueryPager pager = getPager(query, options);
            return execute(Pager.forInternalQuery(pager, executionController), options, pageSize, nowInSec, userLimit, queryStartNanoTime);
        }
    }
}
Also used : AggregationQueryPager(org.apache.cassandra.service.pager.AggregationQueryPager) QueryPager(org.apache.cassandra.service.pager.QueryPager) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator)

Example 3 with QueryPager

use of org.apache.cassandra.service.pager.QueryPager in project cassandra by apache.

the class SelectStatement method execute.

public ResultMessage.Rows execute(QueryState state, QueryOptions options, long queryStartNanoTime) throws RequestExecutionException, RequestValidationException {
    ConsistencyLevel cl = options.getConsistency();
    checkNotNull(cl, "Invalid empty consistency level");
    cl.validateForRead(keyspace());
    int nowInSec = FBUtilities.nowInSeconds();
    int userLimit = getLimit(options);
    int userPerPartitionLimit = getPerPartitionLimit(options);
    int pageSize = options.getPageSize();
    ReadQuery query = getQuery(options, nowInSec, userLimit, userPerPartitionLimit, pageSize);
    if (aggregationSpec == null && (pageSize <= 0 || (query.limits().count() <= pageSize)))
        return execute(query, options, state, nowInSec, userLimit, queryStartNanoTime);
    QueryPager pager = getPager(query, options);
    return execute(Pager.forDistributedQuery(pager, cl, state.getClientState()), options, pageSize, nowInSec, userLimit, queryStartNanoTime);
}
Also used : AggregationQueryPager(org.apache.cassandra.service.pager.AggregationQueryPager) QueryPager(org.apache.cassandra.service.pager.QueryPager)

Example 4 with QueryPager

use of org.apache.cassandra.service.pager.QueryPager in project cassandra by apache.

the class QueryPagerTest method namesQueryTest.

@Test
public void namesQueryTest() throws Exception {
    QueryPager pager = namesQuery("k0", "c1", "c5", "c7", "c8").getPager(null, ProtocolVersion.CURRENT);
    assertFalse(pager.isExhausted());
    List<FilteredPartition> partition = query(pager, 5, 4);
    assertRow(partition.get(0), "k0", "c1", "c5", "c7", "c8");
    assertTrue(pager.isExhausted());
}
Also used : QueryPager(org.apache.cassandra.service.pager.QueryPager) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition) Test(org.junit.Test)

Example 5 with QueryPager

use of org.apache.cassandra.service.pager.QueryPager in project cassandra by apache.

the class QueryPagerTest method rangeSliceQueryTest.

public void rangeSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) throws Exception {
    ReadCommand command = rangeSliceQuery("k1", "k5", 100, "c1", "c7");
    QueryPager pager = command.getPager(null, protocolVersion);
    assertFalse(pager.isExhausted());
    List<FilteredPartition> partitions = query(pager, 5);
    assertRow(partitions.get(0), "k2", "c1", "c2", "c3", "c4", "c5");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partitions = query(pager, 4);
    assertRow(partitions.get(0), "k2", "c6", "c7");
    assertRow(partitions.get(1), "k3", "c1", "c2");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partitions = query(pager, 6);
    assertRow(partitions.get(0), "k3", "c3", "c4", "c5", "c6", "c7");
    assertRow(partitions.get(1), "k4", "c1");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partitions = query(pager, 5);
    assertRow(partitions.get(0), "k4", "c2", "c3", "c4", "c5", "c6");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partitions = query(pager, 5);
    assertRow(partitions.get(0), "k4", "c7");
    assertRow(partitions.get(1), "k5", "c1", "c2", "c3", "c4");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partitions = query(pager, 5, 3);
    assertRow(partitions.get(0), "k5", "c5", "c6", "c7");
    assertTrue(pager.isExhausted());
}
Also used : QueryPager(org.apache.cassandra.service.pager.QueryPager) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition)

Aggregations

QueryPager (org.apache.cassandra.service.pager.QueryPager)11 FilteredPartition (org.apache.cassandra.db.partitions.FilteredPartition)7 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)2 AggregationQueryPager (org.apache.cassandra.service.pager.AggregationQueryPager)2 Test (org.junit.Test)2 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 Row (org.apache.cassandra.db.rows.Row)1 RowIterator (org.apache.cassandra.db.rows.RowIterator)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1