use of org.apache.cassandra.db.Row in project brisk by riptano.
the class BriskDBUtil method validateAndGetColumn.
/**
* Validates that the result is not empty and get the value for the <code>columnName</code> column.
* @param rows the raw result from StorageProxy.read(....)
* @param columnName column name
* @return the Column that was requested if it exists.
* @throws NotFoundException if the result doesn't exist (including if the value holds a tumbstone)
*/
public static IColumn validateAndGetColumn(List<Row> rows, ByteBuffer columnName) throws NotFoundException {
if (rows.isEmpty())
throw new NotFoundException();
if (rows.size() > 1)
throw new RuntimeException("Block id returned more than one row");
Row row = rows.get(0);
if (row.cf == null)
throw new NotFoundException();
IColumn col = row.cf.getColumn(columnName);
if (col == null || !col.isLive())
throw new NotFoundException();
return col;
}
use of org.apache.cassandra.db.Row in project stargate-core by tuplejump.
the class MatchPartition method getAllMatches.
private List<Tuple> getAllMatches(ResultMapper resultMapper, Map<String, Integer> positions) {
List<Tuple> allMatches = new ArrayList<>();
TreeMultimap<DecoratedKey, IndexEntryCollector.IndexEntry> docs = resultMapper.docsByRowKey();
for (final DecoratedKey dk : docs.keySet()) {
List<IndexEntryCollector.IndexEntry> entries = new ArrayList<>(docs.get(dk));
final Map<CellName, ColumnFamily> fullSlice = resultMapper.fetchRangeSlice(entries, dk);
List<Tuple> tuples = new ArrayList<>(fullSlice.size());
for (IndexEntryCollector.IndexEntry entry : entries) {
CellName cellName = entry.clusteringKey;
ColumnFamily cf = fullSlice.get(cellName);
if (cf != null) {
Tuple tuple = aggregateFunction.createTuple(options);
resultMapper.tableMapper.load(positions, tuple, new Row(dk, cf));
tuples.add(tuple);
}
}
int splice = Math.min(tuples.size(), maxMatches);
allMatches.addAll(matchPartition(tuples.subList(0, splice)));
}
return allMatches;
}
use of org.apache.cassandra.db.Row in project eiger by wlloyd.
the class RangeSliceResponseResolver method resolve.
// Note: this would deserialize the response a 2nd time if getData was called first.
// (this is not currently an issue since we don't do read repair for range queries.)
public Iterable<Row> resolve() throws IOException {
ArrayList<RowIterator> iters = new ArrayList<RowIterator>(responses.size());
int n = 0;
for (Message response : responses) {
RangeSliceReply reply = RangeSliceReply.read(response.getMessageBody(), response.getVersion());
n = Math.max(n, reply.rows.size());
iters.add(new RowIterator(reply.rows.iterator(), response.getFrom()));
}
// for each row, compute the combination of all different versions seen, and repair incomplete versions
// TODO do we need to call close?
CloseableIterator<Row> iter = MergeIterator.get(iters, pairComparator, new Reducer());
List<Row> resolvedRows = new ArrayList<Row>(n);
while (iter.hasNext()) resolvedRows.add(iter.next());
return resolvedRows;
}
use of org.apache.cassandra.db.Row in project brisk by riptano.
the class TrackerManager method getCurrentJobtrackerLocation.
/**
* Retrieves the current job tracker IP.
*
* @return the current job tracker IP
* @throws TrackerManagerException
*/
public static InetAddress getCurrentJobtrackerLocation() throws TrackerManagerException {
ReadCommand rc = new SliceByNamesReadCommand(BriskSchema.KEYSPACE_NAME, currentJobtrackerKey, cp, Arrays.asList(columnName));
String result;
try {
List<Row> rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.QUORUM);
IColumn col = validateAndGetColumn(rows, columnName);
// ByteBuffer util duplicates for us the value.
result = ByteBufferUtil.string(col.value());
return InetAddress.getByName(result);
} catch (NotFoundException e) {
return null;
} catch (Exception e) {
throw new TrackerManagerException(e);
}
}
use of org.apache.cassandra.db.Row in project stargate-core by tuplejump.
the class AggregateFunction method process.
@Override
public List<Row> process(ResultMapper resultMapper, ColumnFamilyStore table, RowIndex currentIndex) throws Exception {
Options options = resultMapper.searchSupport.getOptions();
if (aggregates.length == 1 && !aggregates[0].distinct && "count".equalsIgnoreCase(aggregates[0].getType()) && groupBy == null) {
//this means it is a count-star. we can simply return the size of the index results
Count count = new Count(aggregates[0], false);
count.count = resultMapper.collector.docs().size();
group.groups.put(new Tuple(options.nestedFields, Collections.EMPTY_MAP, simpleExpressions), count);
Row row = resultMapper.tableMapper.getRowWithMetaColumn(group.toByteBuffer());
return Collections.singletonList(row);
}
Tuple tuple = createTuple(options);
if (resultMapper.collector.canByPassRowFetch()) {
for (IndexEntryCollector.IndexEntry indexEntry : resultMapper.collector.docs()) {
load(tuple, indexEntry);
group.addTuple(tuple);
}
} else {
RowFetcher rowFetcher = new RowFetcher(resultMapper);
for (Row row : rowFetcher.fetchRows()) {
resultMapper.tableMapper.load(positions, tuple, row);
group.addTuple(tuple);
}
}
Utils.SimpleTimer timer3 = Utils.getStartedTimer(SearchSupport.logger);
ByteBuffer groupBuffer = group.toByteBuffer();
timer3.endLogTime("Aggregation serialization [" + group.groups.size() + "] results");
Row row = resultMapper.tableMapper.getRowWithMetaColumn(groupBuffer);
return Collections.singletonList(row);
}
Aggregations