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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations