Search in sources :

Example 1 with StartTsResultsCollector

use of com.palantir.atlasdb.keyvalue.cassandra.CqlKeyValueServices.StartTsResultsCollector in project atlasdb by palantir.

the class CqlKeyValueService method get.

@Override
public Map<Cell, Value> get(TableReference tableRef, Map<Cell, Long> timestampByCell) {
    if (timestampByCell.isEmpty()) {
        log.info("Attempted get on '{}' table with empty cells", tableRef);
        return ImmutableMap.of();
    }
    try {
        long firstTs = timestampByCell.values().iterator().next();
        if (Iterables.all(timestampByCell.values(), Predicates.equalTo(firstTs))) {
            StartTsResultsCollector collector = new StartTsResultsCollector(firstTs);
            loadWithTs(tableRef, timestampByCell.keySet(), firstTs, false, collector, readConsistency);
            return collector.getCollectedResults();
        }
        SetMultimap<Long, Cell> cellsByTs = HashMultimap.create();
        Multimaps.invertFrom(Multimaps.forMap(timestampByCell), cellsByTs);
        Builder<Cell, Value> builder = ImmutableMap.builder();
        for (long ts : cellsByTs.keySet()) {
            StartTsResultsCollector collector = new StartTsResultsCollector(ts);
            loadWithTs(tableRef, cellsByTs.get(ts), ts, false, collector, readConsistency);
            builder.putAll(collector.getCollectedResults());
        }
        return builder.build();
    } catch (Throwable t) {
        throw Throwables.throwUncheckedException(t);
    }
}
Also used : StartTsResultsCollector(com.palantir.atlasdb.keyvalue.cassandra.CqlKeyValueServices.StartTsResultsCollector) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 2 with StartTsResultsCollector

use of com.palantir.atlasdb.keyvalue.cassandra.CqlKeyValueServices.StartTsResultsCollector in project atlasdb by palantir.

the class CqlKeyValueService method getRows.

@Override
public Map<Cell, Value> getRows(final TableReference tableRef, final Iterable<byte[]> rows, ColumnSelection selection, final long startTs) {
    if (!selection.allColumnsSelected()) {
        Collection<byte[]> selectedColumns = selection.getSelectedColumns();
        Set<Cell> cells = Sets.newHashSetWithExpectedSize(selectedColumns.size() * Iterables.size(rows));
        for (byte[] row : rows) {
            for (byte[] col : selectedColumns) {
                cells.add(Cell.create(row, col));
            }
        }
        try {
            StartTsResultsCollector collector = new StartTsResultsCollector(startTs);
            loadWithTs(tableRef, cells, startTs, false, collector, readConsistency);
            return collector.getCollectedResults();
        } catch (Throwable t) {
            throw Throwables.throwUncheckedException(t);
        }
    }
    try {
        return getRowsAllColsInternal(tableRef, rows, startTs);
    } catch (Throwable t) {
        throw Throwables.throwUncheckedException(t);
    }
}
Also used : StartTsResultsCollector(com.palantir.atlasdb.keyvalue.cassandra.CqlKeyValueServices.StartTsResultsCollector) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Aggregations

Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 StartTsResultsCollector (com.palantir.atlasdb.keyvalue.cassandra.CqlKeyValueServices.StartTsResultsCollector)2 Value (com.palantir.atlasdb.keyvalue.api.Value)1