Search in sources :

Example 16 with RowColumnRangeIterator

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;
}
Also used : RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection)

Example 17 with RowColumnRangeIterator

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;
}
Also used : Sha256Hash(com.palantir.util.crypto.Sha256Hash) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) Value(com.palantir.atlasdb.keyvalue.api.Value) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap)

Example 18 with RowColumnRangeIterator

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());
}
Also used : BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) Test(org.junit.Test)

Aggregations

RowColumnRangeIterator (com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)18 BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)12 ColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection)8 Cell (com.palantir.atlasdb.keyvalue.api.Cell)6 Test (org.junit.Test)6 LocalRowColumnRangeIterator (com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Entry (java.util.Map.Entry)5 SortedMap (java.util.SortedMap)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 Value (com.palantir.atlasdb.keyvalue.api.Value)4 ArrayList (java.util.ArrayList)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)3 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 Measurement (org.openjdk.jmh.annotations.Measurement)3 Threads (org.openjdk.jmh.annotations.Threads)3