Search in sources :

Example 31 with Row

use of org.apache.cassandra.cql3.UntypedResultSet.Row in project cassandra by apache.

the class SystemKeyspace method loadDcRackInfo.

/**
     * Return a map of IP addresses containing a map of dc and rack info
     */
public static Map<InetAddress, Map<String, String>> loadDcRackInfo() {
    Map<InetAddress, Map<String, String>> result = new HashMap<>();
    for (UntypedResultSet.Row row : executeInternal("SELECT peer, data_center, rack from system." + PEERS)) {
        InetAddress peer = row.getInetAddress("peer");
        if (row.has("data_center") && row.has("rack")) {
            Map<String, String> dcRack = new HashMap<>();
            dcRack.put("data_center", row.getString("data_center"));
            dcRack.put("rack", row.getString("rack"));
            result.put(peer, dcRack);
        }
    }
    return result;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) InetAddress(java.net.InetAddress) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 32 with Row

use of org.apache.cassandra.cql3.UntypedResultSet.Row 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 33 with Row

use of org.apache.cassandra.cql3.UntypedResultSet.Row in project cassandra by apache.

the class SystemKeyspace method getViewBuildStatus.

public static Pair<Integer, Token> getViewBuildStatus(String ksname, String viewName) {
    String req = "SELECT generation_number, last_token FROM system.%s WHERE keyspace_name = ? AND view_name = ?";
    UntypedResultSet queryResultSet = executeInternal(format(req, VIEWS_BUILDS_IN_PROGRESS), ksname, viewName);
    if (queryResultSet == null || queryResultSet.isEmpty())
        return null;
    UntypedResultSet.Row row = queryResultSet.one();
    Integer generation = null;
    Token lastKey = null;
    if (row.has("generation_number"))
        generation = row.getInt("generation_number");
    if (row.has("last_key")) {
        Token.TokenFactory factory = ViewsBuildsInProgress.partitioner.getTokenFactory();
        lastKey = factory.fromString(row.getString("last_key"));
    }
    return Pair.create(generation, lastKey);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 34 with Row

use of org.apache.cassandra.cql3.UntypedResultSet.Row in project cassandra by apache.

the class SystemKeyspace method getAvailableRanges.

public static synchronized Set<Range<Token>> getAvailableRanges(String keyspace, IPartitioner partitioner) {
    Set<Range<Token>> result = new HashSet<>();
    String query = "SELECT * FROM system.%s WHERE keyspace_name=?";
    UntypedResultSet rs = executeInternal(format(query, AVAILABLE_RANGES), keyspace);
    for (UntypedResultSet.Row row : rs) {
        Set<ByteBuffer> rawRanges = row.getSet("ranges", BytesType.instance);
        for (ByteBuffer rawRange : rawRanges) {
            result.add(byteBufferToRange(rawRange, partitioner));
        }
    }
    return ImmutableSet.copyOf(result);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ByteBuffer(java.nio.ByteBuffer)

Example 35 with Row

use of org.apache.cassandra.cql3.UntypedResultSet.Row in project cassandra by apache.

the class CQLSSTableWriter method addRow.

/**
     * Adds a new row to the writer.
     * <p>
     * This is equivalent to the other addRow methods, but takes a map whose
     * keys are the names of the columns to add instead of taking a list of the
     * values in the order of the insert statement used during construction of
     * this write.
     * <p>
     * Please note that the column names in the map keys must be in lowercase unless
     * the declared column name is a
     * <a href="http://cassandra.apache.org/doc/cql3/CQL.html#identifiers">case-sensitive quoted identifier</a>
     * (in which case the map key must use the exact case of the column).
     *
     * @param values a map of colum name to column values representing the new
     * row to add. Note that if a column is not part of the map, it's value will
     * be {@code null}. If the map contains keys that does not correspond to one
     * of the column of the insert statement used when creating this writer, the
     * the corresponding value is ignored.
     * @return this writer.
     */
public CQLSSTableWriter addRow(Map<String, Object> values) throws InvalidRequestException, IOException {
    int size = boundNames.size();
    List<ByteBuffer> rawValues = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        ColumnSpecification spec = boundNames.get(i);
        Object value = values.get(spec.name.toString());
        rawValues.add(serialize(value, typeCodecs.get(i)));
    }
    return rawAddRow(rawValues);
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)33 Test (org.junit.Test)29 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)18 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)15 ByteBuffer (java.nio.ByteBuffer)10 Row (org.apache.cassandra.db.rows.Row)8 FunctionName (org.apache.cassandra.cql3.functions.FunctionName)6 TableMetadata (org.apache.cassandra.schema.TableMetadata)6 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)5 java.util (java.util)4 ProtocolVersion (org.apache.cassandra.transport.ProtocolVersion)4 InetAddress (java.net.InetAddress)3 ColumnSpecification (org.apache.cassandra.cql3.ColumnSpecification)3 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)3 Cell (org.apache.cassandra.db.rows.Cell)3 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3 Row (com.datastax.driver.core.Row)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2