use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class InMemoryKeyValueService method getRowsColumnRange.
@Override
public Map<byte[], RowColumnRangeIterator> getRowsColumnRange(TableReference tableRef, Iterable<byte[]> rows, BatchColumnRangeSelection batchColumnRangeSelection, long timestamp) {
Map<byte[], RowColumnRangeIterator> result = Maps.newHashMap();
ConcurrentSkipListMap<Key, byte[]> table = getTableMap(tableRef).entries;
ColumnRangeSelection columnRangeSelection = new ColumnRangeSelection(batchColumnRangeSelection.getStartCol(), batchColumnRangeSelection.getEndCol());
for (byte[] row : rows) {
result.put(row, getColumnRangeForSingleRow(table, row, columnRangeSelection, timestamp));
}
return result;
}
use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class KeyValueServices method filterGetRowsToColumnRange.
// TODO(gsheasby): kill this when we can properly implement this on all KVSes
public static Map<byte[], RowColumnRangeIterator> filterGetRowsToColumnRange(KeyValueService kvs, TableReference tableRef, Iterable<byte[]> rows, BatchColumnRangeSelection columnRangeSelection, long timestamp) {
log.warn("Using inefficient postfiltering for getRowsColumnRange because the KVS doesn't support it natively. " + "Production environments should use a KVS with a proper implementation.");
Map<Cell, Value> allValues = kvs.getRows(tableRef, rows, ColumnSelection.all(), timestamp);
Map<Sha256Hash, byte[]> hashesToBytes = Maps.newHashMap();
Map<Sha256Hash, ImmutableSortedMap.Builder<byte[], Value>> rowsToColumns = Maps.newHashMap();
for (byte[] row : rows) {
Sha256Hash rowHash = Sha256Hash.computeHash(row);
hashesToBytes.put(rowHash, row);
ImmutableSortedMap.Builder<byte[], Value> builder = ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator());
rowsToColumns.put(rowHash, builder);
}
for (Map.Entry<Cell, Value> e : allValues.entrySet()) {
Sha256Hash rowHash = Sha256Hash.computeHash(e.getKey().getRowName());
rowsToColumns.get(rowHash).put(e.getKey().getColumnName(), e.getValue());
}
Map<byte[], RowColumnRangeIterator> results = Maps.newHashMap();
for (Map.Entry<Sha256Hash, ImmutableSortedMap.Builder<byte[], Value>> row : rowsToColumns.entrySet()) {
SortedMap<byte[], Value> map = row.getValue().build();
Set<Map.Entry<byte[], Value>> subMap;
if ((columnRangeSelection.getStartCol().length == 0) && (columnRangeSelection.getEndCol().length == 0)) {
subMap = map.entrySet();
} else if (columnRangeSelection.getStartCol().length == 0) {
subMap = map.headMap(columnRangeSelection.getEndCol()).entrySet();
} else if (columnRangeSelection.getEndCol().length == 0) {
subMap = map.tailMap(columnRangeSelection.getStartCol()).entrySet();
} else {
subMap = map.subMap(columnRangeSelection.getStartCol(), columnRangeSelection.getEndCol()).entrySet();
}
byte[] rowName = hashesToBytes.get(row.getKey());
results.put(hashesToBytes.get(row.getKey()), new LocalRowColumnRangeIterator(Iterators.transform(subMap.iterator(), e -> Pair.<Cell, Value>of(Cell.create(rowName, e.getKey()), e.getValue()))));
}
return results;
}
use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.
the class OneNodeDownGetTest method canGetRowsColumnRange.
@Test
public void canGetRowsColumnRange() {
BatchColumnRangeSelection rangeSelection = BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1);
Map<byte[], RowColumnRangeIterator> rowsColumnRange = OneNodeDownTestSuite.kvs.getRowsColumnRange(OneNodeDownTestSuite.TEST_TABLE, ImmutableList.of(OneNodeDownTestSuite.FIRST_ROW), rangeSelection, Long.MAX_VALUE);
assertEquals(1, rowsColumnRange.size());
byte[] rowName = rowsColumnRange.entrySet().iterator().next().getKey();
assertTrue(Arrays.equals(OneNodeDownTestSuite.FIRST_ROW, rowName));
RowColumnRangeIterator it = rowsColumnRange.get(rowName);
assertThat(it).containsExactlyElementsOf(expectedRow.entrySet());
}
Aggregations