private static ResultSet buildCasFailureResultSet(ByteBuffer key, ColumnFamily cf, Iterable<ColumnDefinition> columnsWithConditions, boolean isBatch, QueryOptions options) throws InvalidRequestException { CFMetaData cfm = cf.metadata(); Selection selection; if (columnsWithConditions == null) { selection = Selection.wildcard(cfm, false, null); } 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<ColumnDefinition> defs = new LinkedHashSet<>(); // Adding the partition key for batches to disambiguate if the conditions span multipe rows (we don't add them outside // of batches for compatibility sakes). if (isBatch) { defs.addAll(cfm.partitionKeyColumns()); defs.addAll(cfm.clusteringColumns()); } for (ColumnDefinition def : columnsWithConditions) defs.add(def); selection = Selection.forColumns(new ArrayList<>(defs)); } long now = System.currentTimeMillis(); Selection.ResultSetBuilder builder = selection.resultSetBuilder(now); SelectStatement.forSelection(cfm, selection).processColumnFamily(key, cf, options, now, builder); return builder.build(); }
private ResultSet process(List<Row> rows, QueryOptions options, int limit, long now) throws InvalidRequestException { Selection.ResultSetBuilder result = selection.resultSetBuilder(now); for (org.apache.cassandra.db.Row row : rows) { // Not columns match the query, skip if (row.cf == null) continue; processColumnFamily(row.key.getKey(), row.cf, options, now, result); } ResultSet cqlRows = result.build(); orderResults(cqlRows); // Internal calls always return columns in the comparator order, even when reverse was set if (isReversed) cqlRows.reverse(); // Trim result if needed to respect the user limit cqlRows.trim(limit); return cqlRows; }