Search in sources :

Example 1 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class ModificationStatement method buildCasFailureResultSet.

private static ResultSet buildCasFailureResultSet(RowIterator partition, Iterable<ColumnMetadata> columnsWithConditions, boolean isBatch, QueryOptions options) throws InvalidRequestException {
    TableMetadata metadata = partition.metadata();
    Selection selection;
    if (columnsWithConditions == null) {
        selection = Selection.wildcard(metadata);
    } 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));
    }
    Selection.ResultSetBuilder builder = selection.resultSetBuilder(options, false);
    SelectStatement.forSelection(metadata, selection).processPartition(partition, options, builder, FBUtilities.nowInSeconds());
    return builder.build();
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) Selection(org.apache.cassandra.cql3.selection.Selection)

Example 2 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class SelectStatement method process.

private ResultSet process(PartitionIterator partitions, QueryOptions options, int nowInSec, int userLimit) throws InvalidRequestException {
    Selection.ResultSetBuilder result = selection.resultSetBuilder(options, parameters.isJson, aggregationSpec);
    while (partitions.hasNext()) {
        try (RowIterator partition = partitions.next()) {
            processPartition(partition, options, result, nowInSec);
        }
    }
    ResultSet cqlRows = result.build();
    orderResults(cqlRows);
    cqlRows.trim(userLimit);
    return cqlRows;
}
Also used : Selection(org.apache.cassandra.cql3.selection.Selection) RowIterator(org.apache.cassandra.db.rows.RowIterator)

Example 3 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class SystemKeyspace method loadPreparedStatements.

public static List<Pair<String, String>> loadPreparedStatements() {
    String query = format("SELECT logged_keyspace, query_string FROM %s", PreparedStatements.toString());
    UntypedResultSet resultSet = executeOnceInternal(query);
    List<Pair<String, String>> r = new ArrayList<>();
    for (UntypedResultSet.Row row : resultSet) r.add(Pair.create(row.has("logged_keyspace") ? row.getString("logged_keyspace") : null, row.getString("query_string")));
    return r;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 4 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class CompactionHistoryTabularData method from.

public static TabularData from(UntypedResultSet resultSet) throws OpenDataException {
    TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE);
    for (UntypedResultSet.Row row : resultSet) {
        UUID id = row.getUUID(ITEM_NAMES[0]);
        String ksName = row.getString(ITEM_NAMES[1]);
        String cfName = row.getString(ITEM_NAMES[2]);
        long compactedAt = row.getLong(ITEM_NAMES[3]);
        long bytesIn = row.getLong(ITEM_NAMES[4]);
        long bytesOut = row.getLong(ITEM_NAMES[5]);
        Map<Integer, Long> rowMerged = row.getMap(ITEM_NAMES[6], Int32Type.instance, LongType.instance);
        result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[] { id.toString(), ksName, cfName, compactedAt, bytesIn, bytesOut, "{" + FBUtilities.toString(rowMerged) + "}" }));
    }
    return result;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) UUID(java.util.UUID)

Example 5 with ResultSet

use of org.apache.cassandra.cql3.ResultSet 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)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)9 Test (org.junit.Test)8 ResultSet (com.google.spanner.v1.ResultSet)5 ResultSet (com.datastax.driver.core.ResultSet)4 Session (com.datastax.driver.core.Session)4 Statement (com.google.cloud.spanner.Statement)4 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)3 Row (org.apache.cassandra.cql3.UntypedResultSet.Row)3 Selection (org.apache.cassandra.cql3.selection.Selection)3 SimpleStatement (com.datastax.driver.core.SimpleStatement)2 Statement (com.datastax.driver.core.Statement)2 ByteBuffer (java.nio.ByteBuffer)2 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)2 CQLStatement (org.apache.cassandra.cql3.CQLStatement)2 ColumnSpecification (org.apache.cassandra.cql3.ColumnSpecification)2 ResultSet (org.apache.cassandra.cql3.ResultSet)2 ResultSetBuilder (org.apache.cassandra.cql3.selection.ResultSetBuilder)2 Selectors (org.apache.cassandra.cql3.selection.Selection.Selectors)2 RowIterator (org.apache.cassandra.db.rows.RowIterator)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2