Search in sources :

Example 6 with Row

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

the class SystemKeyspace method isViewStatusReplicated.

public static boolean isViewStatusReplicated(String keyspaceName, String viewName) {
    String req = "SELECT status_replicated FROM %s.\"%s\" WHERE keyspace_name=? AND view_name=?";
    UntypedResultSet result = executeInternal(format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName);
    if (result.isEmpty())
        return false;
    UntypedResultSet.Row row = result.one();
    return row.has("status_replicated") && row.getBoolean("status_replicated");
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 7 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 8 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 9 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 10 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)

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