Search in sources :

Example 1 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class DbKvs method getRowsColumnRange.

@Override
public Map<byte[], RowColumnRangeIterator> getRowsColumnRange(TableReference tableRef, Iterable<byte[]> rows, BatchColumnRangeSelection batchColumnRangeSelection, long timestamp) {
    List<byte[]> rowList = ImmutableList.copyOf(rows);
    Map<byte[], List<Map.Entry<Cell, Value>>> firstPage = getFirstRowsColumnRangePage(tableRef, rowList, batchColumnRangeSelection, timestamp);
    Map<byte[], RowColumnRangeIterator> ret = Maps.newHashMapWithExpectedSize(rowList.size());
    for (Entry<byte[], List<Map.Entry<Cell, Value>>> e : firstPage.entrySet()) {
        List<Map.Entry<Cell, Value>> results = e.getValue();
        if (results.isEmpty()) {
            ret.put(e.getKey(), new LocalRowColumnRangeIterator(e.getValue().iterator()));
            continue;
        }
        byte[] lastCol = results.get(results.size() - 1).getKey().getColumnName();
        RowColumnRangeIterator firstPageIter = new LocalRowColumnRangeIterator(e.getValue().iterator());
        if (isEndOfColumnRange(lastCol, batchColumnRangeSelection.getEndCol())) {
            ret.put(e.getKey(), firstPageIter);
        } else {
            byte[] nextCol = RangeRequests.nextLexicographicName(lastCol);
            BatchColumnRangeSelection nextColumnRangeSelection = BatchColumnRangeSelection.create(nextCol, batchColumnRangeSelection.getEndCol(), batchColumnRangeSelection.getBatchHint());
            Iterator<Map.Entry<Cell, Value>> nextPagesIter = getRowColumnRange(tableRef, e.getKey(), nextColumnRangeSelection, timestamp);
            ret.put(e.getKey(), new LocalRowColumnRangeIterator(Iterators.concat(firstPageIter, nextPagesIter)));
        }
    }
    return ret;
}
Also used : BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) Entry(java.util.Map.Entry) LocalRowColumnRangeIterator(com.palantir.atlasdb.keyvalue.impl.LocalRowColumnRangeIterator) Value(com.palantir.atlasdb.keyvalue.api.Value) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 2 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method testGetRowColumnRangeCellBatchHistorical.

@Test
public void testGetRowColumnRangeCellBatchHistorical() {
    putTestDataForMultipleTimestamps();
    RowColumnRangeIterator values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row0), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 2);
    assertNextElementMatches(values, TEST_CELL, value0_t1);
    assertFalse(values.hasNext());
    values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row0), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
    assertNextElementMatches(values, TEST_CELL, value0_t0);
    assertFalse(values.hasNext());
}
Also used : RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Test(org.junit.Test)

Example 3 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method testGetRowColumnRangeCellBatchSingleRow.

@Test
public void testGetRowColumnRangeCellBatchSingleRow() {
    putTestDataForSingleTimestamp();
    RowColumnRangeIterator values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
    assertNextElementMatches(values, Cell.create(row1, column0), value10);
    assertNextElementMatches(values, Cell.create(row1, column2), value12);
    assertFalse(values.hasNext());
    values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(RangeRequests.nextLexicographicName(column0), PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
    assertNextElementMatches(values, Cell.create(row1, column2), value12);
    assertFalse(values.hasNext());
    values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(RangeRequests.nextLexicographicName(column0), column2), 1, TEST_TIMESTAMP + 1);
    assertFalse(values.hasNext());
    values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(RangeRequests.nextLexicographicName(column2), PtBytes.EMPTY_BYTE_ARRAY), 1, TEST_TIMESTAMP + 1);
    assertFalse(values.hasNext());
    values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), Integer.MAX_VALUE, TEST_TIMESTAMP + 1);
    assertNextElementMatches(values, Cell.create(row1, column0), value10);
    assertNextElementMatches(values, Cell.create(row1, column2), value12);
    assertFalse(values.hasNext());
}
Also used : RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Test(org.junit.Test)

Example 4 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method testGetRowColumnRangeCellBatchMultipleHistorical.

@Test
public void testGetRowColumnRangeCellBatchMultipleHistorical() {
    keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column0), value0_t0), TEST_TIMESTAMP);
    keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column0), value0_t1), TEST_TIMESTAMP + 1);
    keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column1), value0_t0), TEST_TIMESTAMP);
    keyValueService.put(TEST_TABLE, ImmutableMap.of(Cell.create(row1, column1), value0_t1), TEST_TIMESTAMP + 1);
    RowColumnRangeIterator values = keyValueService.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row1), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, RangeRequests.nextLexicographicName(column1)), 2, TEST_TIMESTAMP + 1);
    assertNextElementMatches(values, Cell.create(row1, column0), value0_t0);
    assertNextElementMatches(values, Cell.create(row1, column1), value0_t0);
    assertFalse(values.hasNext());
}
Also used : RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Test(org.junit.Test)

Example 5 with RowColumnRangeIterator

use of com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator in project atlasdb by palantir.

the class KeyValueServices method mergeGetRowsColumnRangeIntoSingleIterator.

public static RowColumnRangeIterator mergeGetRowsColumnRangeIntoSingleIterator(KeyValueService kvs, TableReference tableRef, Iterable<byte[]> rows, ColumnRangeSelection columnRangeSelection, int batchHint, long timestamp) {
    if (Iterables.isEmpty(rows)) {
        return new LocalRowColumnRangeIterator(Collections.emptyIterator());
    }
    int columnBatchSize = batchHint / Iterables.size(rows);
    BatchColumnRangeSelection batchColumnRangeSelection = BatchColumnRangeSelection.create(columnRangeSelection, columnBatchSize);
    Map<byte[], RowColumnRangeIterator> rowsColumnRanges = kvs.getRowsColumnRange(tableRef, rows, batchColumnRangeSelection, timestamp);
    // Return results in the same order as the provided rows.
    Iterable<RowColumnRangeIterator> orderedRanges = Iterables.transform(rows, rowsColumnRanges::get);
    return new LocalRowColumnRangeIterator(Iterators.concat(orderedRanges.iterator()));
}
Also used : BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator)

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