use of org.apache.cassandra.cql3.selection.ResultSetBuilder 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;
}
use of org.apache.cassandra.cql3.selection.ResultSetBuilder 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();
}
use of org.apache.cassandra.cql3.selection.ResultSetBuilder in project cassandra by apache.
the class QueryProcessor method executeAsync.
public static Future<UntypedResultSet> executeAsync(InetAddressAndPort address, String query, Object... values) {
Prepared prepared = prepareInternal(query);
QueryOptions options = makeInternalOptions(prepared.statement, values);
if (prepared.statement instanceof SelectStatement) {
SelectStatement select = (SelectStatement) prepared.statement;
int nowInSec = FBUtilities.nowInSeconds();
ReadQuery readQuery = select.getQuery(options, nowInSec);
List<ReadCommand> commands;
if (readQuery instanceof ReadCommand) {
commands = Collections.singletonList((ReadCommand) readQuery);
} else if (readQuery instanceof SinglePartitionReadQuery.Group) {
List<? extends SinglePartitionReadQuery> queries = ((SinglePartitionReadQuery.Group<? extends SinglePartitionReadQuery>) readQuery).queries;
queries.forEach(a -> {
if (!(a instanceof ReadCommand))
throw new IllegalArgumentException("Queries found which are not ReadCommand: " + a.getClass());
});
commands = (List<ReadCommand>) (List<?>) queries;
} else {
throw new IllegalArgumentException("Unable to handle; only expected ReadCommands but given " + readQuery.getClass());
}
Future<List<Message<ReadResponse>>> future = FutureCombiner.allOf(commands.stream().map(rc -> Message.out(rc.verb(), rc)).map(m -> MessagingService.instance().<ReadResponse>sendWithResult(m, address)).collect(Collectors.toList()));
ResultSetBuilder result = new ResultSetBuilder(select.getResultMetadata(), select.getSelection().newSelectors(options), null);
return future.map(list -> {
int i = 0;
for (Message<ReadResponse> m : list) {
ReadResponse rsp = m.payload;
try (PartitionIterator it = UnfilteredPartitionIterators.filter(rsp.makeIterator(commands.get(i++)), nowInSec)) {
while (it.hasNext()) {
try (RowIterator partition = it.next()) {
select.processPartition(partition, options, result, nowInSec);
}
}
}
}
return result.build();
}).map(UntypedResultSet::create);
}
throw new IllegalArgumentException("Unable to execute query; only SELECT supported but given: " + query);
}
Aggregations