Search in sources :

Example 1 with Row

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;
}
Also used : IColumn(org.apache.cassandra.db.IColumn) NotFoundException(org.apache.cassandra.thrift.NotFoundException) Row(org.apache.cassandra.db.Row)

Example 2 with Row

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;
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) CellName(org.apache.cassandra.db.composites.CellName) ColumnFamily(org.apache.cassandra.db.ColumnFamily) IndexEntryCollector(com.tuplejump.stargate.lucene.IndexEntryCollector) Row(org.apache.cassandra.db.Row)

Example 3 with Row

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;
}
Also used : Message(org.apache.cassandra.net.Message) RangeSliceReply(org.apache.cassandra.db.RangeSliceReply) Row(org.apache.cassandra.db.Row)

Example 4 with Row

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);
    }
}
Also used : IColumn(org.apache.cassandra.db.IColumn) SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) ReadCommand(org.apache.cassandra.db.ReadCommand) SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) NotFoundException(org.apache.cassandra.thrift.NotFoundException) Row(org.apache.cassandra.db.Row) NotFoundException(org.apache.cassandra.thrift.NotFoundException)

Example 5 with Row

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);
}
Also used : RowFetcher(com.tuplejump.stargate.cassandra.RowFetcher) Utils(com.tuplejump.stargate.Utils) Row(org.apache.cassandra.db.Row) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Row (org.apache.cassandra.db.Row)7 ByteBuffer (java.nio.ByteBuffer)2 ColumnFamily (org.apache.cassandra.db.ColumnFamily)2 IColumn (org.apache.cassandra.db.IColumn)2 Message (org.apache.cassandra.net.Message)2 NotFoundException (org.apache.cassandra.thrift.NotFoundException)2 Utils (com.tuplejump.stargate.Utils)1 RowFetcher (com.tuplejump.stargate.cassandra.RowFetcher)1 IndexEntryCollector (com.tuplejump.stargate.lucene.IndexEntryCollector)1 Map (java.util.Map)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 RangeSliceReply (org.apache.cassandra.db.RangeSliceReply)1 ReadCommand (org.apache.cassandra.db.ReadCommand)1 ReadResponse (org.apache.cassandra.db.ReadResponse)1 SliceByNamesReadCommand (org.apache.cassandra.db.SliceByNamesReadCommand)1 CellName (org.apache.cassandra.db.composites.CellName)1