Search in sources :

Example 1 with Selectors

use of org.apache.cassandra.cql3.selection.Selection.Selectors in project cassandra by apache.

the class SelectStatement method process.

private ResultSet process(PartitionIterator partitions, QueryOptions options, Selectors selectors, int nowInSec, int userLimit) throws InvalidRequestException {
    GroupMaker groupMaker = aggregationSpec == null ? null : aggregationSpec.newGroupMaker();
    ResultSetBuilder result = new ResultSetBuilder(getResultMetadata(), selectors, groupMaker);
    while (partitions.hasNext()) {
        try (RowIterator partition = partitions.next()) {
            processPartition(partition, options, result, nowInSec);
        }
    }
    ResultSet cqlRows = result.build();
    maybeWarn(result, options);
    orderResults(cqlRows);
    cqlRows.trim(userLimit);
    return cqlRows;
}
Also used : ResultSetBuilder(org.apache.cassandra.cql3.selection.ResultSetBuilder) RowIterator(org.apache.cassandra.db.rows.RowIterator) GroupMaker(org.apache.cassandra.db.aggregation.GroupMaker)

Example 2 with Selectors

use of org.apache.cassandra.cql3.selection.Selection.Selectors in project cassandra by apache.

the class ModificationStatement method buildCasFailureResultSet.

private static ResultSet buildCasFailureResultSet(RowIterator partition, Iterable<ColumnMetadata> columnsWithConditions, boolean isBatch, QueryOptions options, int nowInSeconds) {
    TableMetadata metadata = partition.metadata();
    Selection selection;
    if (columnsWithConditions == null) {
        selection = Selection.wildcard(metadata, false, false);
    } else {
        // We can have multiple conditions on the same columns (for collections) so use a set
        // to avoid duplicate, but preserve the order just to it follows the order of IF in the query in general
        Set<ColumnMetadata> defs = new LinkedHashSet<>();
        // of batches for compatibility sakes).
        if (isBatch)
            Iterables.addAll(defs, metadata.primaryKeyColumns());
        Iterables.addAll(defs, columnsWithConditions);
        selection = Selection.forColumns(metadata, new ArrayList<>(defs), false);
    }
    Selectors selectors = selection.newSelectors(options);
    ResultSetBuilder builder = new ResultSetBuilder(selection.getResultMetadata(), selectors);
    SelectStatement.forSelection(metadata, selection).processPartition(partition, options, builder, nowInSeconds);
    return builder.build();
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ResultSetBuilder(org.apache.cassandra.cql3.selection.ResultSetBuilder) Selection(org.apache.cassandra.cql3.selection.Selection) Selectors(org.apache.cassandra.cql3.selection.Selection.Selectors)

Example 3 with Selectors

use of org.apache.cassandra.cql3.selection.Selection.Selectors 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();
    Selectors selectors = selection.newSelectors(options);
    ReadQuery query = getQuery(options, state.getClientState(), selectors.getColumnFilter(), 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, selectors, nowInSec, userLimit);
            }
        }
        QueryPager pager = getPager(query, options);
        return execute(state, Pager.forInternalQuery(pager, executionController), options, selectors, 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) Selectors(org.apache.cassandra.cql3.selection.Selection.Selectors)

Example 4 with Selectors

use of org.apache.cassandra.cql3.selection.Selection.Selectors in project cassandra by apache.

the class SelectStatement method execute.

public ResultMessage.Rows execute(QueryState state, QueryOptions options, long queryStartNanoTime) {
    ConsistencyLevel cl = options.getConsistency();
    checkNotNull(cl, "Invalid empty consistency level");
    cl.validateForRead();
    int nowInSec = options.getNowInSeconds(state);
    int userLimit = getLimit(options);
    int userPerPartitionLimit = getPerPartitionLimit(options);
    int pageSize = options.getPageSize();
    Selectors selectors = selection.newSelectors(options);
    ReadQuery query = getQuery(options, state.getClientState(), selectors.getColumnFilter(), nowInSec, userLimit, userPerPartitionLimit, pageSize);
    if (options.isTrackWarningsEnabled())
        query.trackWarnings();
    if (aggregationSpec == null && (pageSize <= 0 || (query.limits().count() <= pageSize)))
        return execute(query, options, state, selectors, nowInSec, userLimit, queryStartNanoTime);
    QueryPager pager = getPager(query, options);
    return execute(state, Pager.forDistributedQuery(pager, cl, state.getClientState()), options, selectors, pageSize, nowInSec, userLimit, queryStartNanoTime);
}
Also used : AggregationQueryPager(org.apache.cassandra.service.pager.AggregationQueryPager) QueryPager(org.apache.cassandra.service.pager.QueryPager) Selectors(org.apache.cassandra.cql3.selection.Selection.Selectors)

Example 5 with Selectors

use of org.apache.cassandra.cql3.selection.Selection.Selectors in project cassandra by apache.

the class SelectStatement method process.

public ResultSet process(PartitionIterator partitions, int nowInSec) throws InvalidRequestException {
    QueryOptions options = QueryOptions.DEFAULT;
    Selectors selectors = selection.newSelectors(options);
    return process(partitions, options, selectors, nowInSec, getLimit(options));
}
Also used : Selectors(org.apache.cassandra.cql3.selection.Selection.Selectors)

Aggregations

Selectors (org.apache.cassandra.cql3.selection.Selection.Selectors)4 ResultSetBuilder (org.apache.cassandra.cql3.selection.ResultSetBuilder)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 AggregationQueryPager (org.apache.cassandra.service.pager.AggregationQueryPager)2 QueryPager (org.apache.cassandra.service.pager.QueryPager)2 List (java.util.List)1 ColumnSpecification (org.apache.cassandra.cql3.ColumnSpecification)1 QueryOptions (org.apache.cassandra.cql3.QueryOptions)1 Selection (org.apache.cassandra.cql3.selection.Selection)1 GroupMaker (org.apache.cassandra.db.aggregation.GroupMaker)1 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)1 RowIterator (org.apache.cassandra.db.rows.RowIterator)1 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1 StrBuilder (org.apache.commons.lang3.text.StrBuilder)1