Example usage for org.apache.cassandra.cql3.statements SelectStatement getLimit

List of usage examples for org.apache.cassandra.cql3.statements SelectStatement getLimit

Introduction

In this page you can find the example usage for org.apache.cassandra.cql3.statements SelectStatement getLimit.

Prototype

public int getLimit(QueryOptions options) 

Source Link

Document

Returns the limit specified by the user.

Usage

From source file:com.stratio.cassandra.lucene.IndexQueryHandler.java

License:Apache License

private ResultMessage process(SelectStatement select, QueryState state, QueryOptions options,
        RowFilter.CustomExpression expression) throws ReflectiveOperationException {

    // Validate expression
    ColumnFamilyStore cfs = Keyspace.open(select.keyspace()).getColumnFamilyStore(select.columnFamily());
    Index index = (Index) cfs.indexManager.getIndex(expression.getTargetIndex());
    Search search = index.validate(expression);

    // Check paging
    int limit = select.getLimit(options);
    int page = getPageSize(select, options);
    if (search.isTopK()) {
        if (limit == Integer.MAX_VALUE) { // Avoid unlimited
            throw new InvalidRequestException(
                    "Top-k searches don't support paging, so a cautious LIMIT clause should be provided "
                            + "to prevent excessive memory consumption.");
        } else if (page < limit) {
            String json = UTF8Type.instance.compose(expression.getValue());
            logger.warn("Disabling paging of {} rows per page for top-k search requesting {} rows: {}", page,
                    limit, json);//from   w ww.  j av a  2  s. c o m
            return executeWithoutPaging(select, state, options);
        }
    }

    // Process
    return execute(select, state, options);
}

From source file:com.stratio.cassandra.lucene.IndexQueryHandler.java

License:Apache License

public ResultMessage.Rows executeWithoutPaging(SelectStatement select, QueryState state, QueryOptions options)
        throws ReflectiveOperationException {

    ConsistencyLevel cl = options.getConsistency();
    checkNotNull(cl, "Invalid empty consistency level");

    cl.validateForRead(select.keyspace());

    int nowInSec = FBUtilities.nowInSeconds();
    int userLimit = select.getLimit(options);
    ReadQuery query = select.getQuery(options, nowInSec, userLimit);

    Method method = select.getClass().getDeclaredMethod("execute", ReadQuery.class, QueryOptions.class,
            QueryState.class, int.class, int.class);
    method.setAccessible(true);//from  w  w w .jav  a  2s  .com
    return (ResultMessage.Rows) method.invoke(select, query, options, state, nowInSec, userLimit);
}